Fix JWT signing for Google Calendar authentication
- Change from jwt.sign() to SignJWT class - Use proper jose library SignJWT API for Deno - Fix 'Cannot read properties of undefined' error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,33 +30,21 @@ interface CreateMeetRequest {
|
|||||||
// Function to create JWT and get access token
|
// Function to create JWT and get access token
|
||||||
async function getGoogleAccessToken(serviceAccount: GoogleServiceAccount): Promise<string> {
|
async function getGoogleAccessToken(serviceAccount: GoogleServiceAccount): Promise<string> {
|
||||||
try {
|
try {
|
||||||
// Import JWT library
|
// Import JWT sign function from jose
|
||||||
const { jwt } = await import("https://deno.land/x/jose@v4.15.1/index.ts");
|
const { SignJWT } = await import("https://deno.land/x/jose@v4.15.1/index.ts");
|
||||||
|
|
||||||
// Create JWT header and payload
|
|
||||||
const header = {
|
|
||||||
alg: "RS256",
|
|
||||||
typ: "JWT",
|
|
||||||
kid: serviceAccount.private_key_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
const payload = {
|
|
||||||
|
// Create and sign JWT
|
||||||
|
const token = await new SignJWT({
|
||||||
iss: serviceAccount.client_email,
|
iss: serviceAccount.client_email,
|
||||||
scope: "https://www.googleapis.com/auth/calendar",
|
scope: "https://www.googleapis.com/auth/calendar",
|
||||||
aud: serviceAccount.token_uri,
|
aud: serviceAccount.token_uri,
|
||||||
exp: now + 3600,
|
exp: now + 3600,
|
||||||
iat: now,
|
iat: now,
|
||||||
};
|
})
|
||||||
|
.setProtectedHeader({ alg: 'RS256', kid: serviceAccount.private_key_id })
|
||||||
// Import key
|
.sign(serviceAccount.private_key);
|
||||||
const privateKey = serviceAccount.private_key;
|
|
||||||
|
|
||||||
// Sign JWT
|
|
||||||
const token = await jwt.sign(payload, privateKey, {
|
|
||||||
algorithm: 'RS256',
|
|
||||||
header: header,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Exchange JWT for access token
|
// Exchange JWT for access token
|
||||||
const response = await fetch(serviceAccount.token_uri, {
|
const response = await fetch(serviceAccount.token_uri, {
|
||||||
|
|||||||
Reference in New Issue
Block a user