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
|
||||
async function getGoogleAccessToken(serviceAccount: GoogleServiceAccount): Promise<string> {
|
||||
try {
|
||||
// Import JWT library
|
||||
const { jwt } = 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,
|
||||
};
|
||||
// Import JWT sign function from jose
|
||||
const { SignJWT } = await import("https://deno.land/x/jose@v4.15.1/index.ts");
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const payload = {
|
||||
|
||||
// Create and sign JWT
|
||||
const token = await new SignJWT({
|
||||
iss: serviceAccount.client_email,
|
||||
scope: "https://www.googleapis.com/auth/calendar",
|
||||
aud: serviceAccount.token_uri,
|
||||
exp: now + 3600,
|
||||
iat: now,
|
||||
};
|
||||
|
||||
// Import key
|
||||
const privateKey = serviceAccount.private_key;
|
||||
|
||||
// Sign JWT
|
||||
const token = await jwt.sign(payload, privateKey, {
|
||||
algorithm: 'RS256',
|
||||
header: header,
|
||||
});
|
||||
})
|
||||
.setProtectedHeader({ alg: 'RS256', kid: serviceAccount.private_key_id })
|
||||
.sign(serviceAccount.private_key);
|
||||
|
||||
// Exchange JWT for access token
|
||||
const response = await fetch(serviceAccount.token_uri, {
|
||||
|
||||
Reference in New Issue
Block a user