diff --git a/supabase/functions/create-google-meet-event/index.ts b/supabase/functions/create-google-meet-event/index.ts index 37dcfd0..82fd072 100644 --- a/supabase/functions/create-google-meet-event/index.ts +++ b/supabase/functions/create-google-meet-event/index.ts @@ -30,33 +30,21 @@ interface CreateMeetRequest { // Function to create JWT and get access token async function getGoogleAccessToken(serviceAccount: GoogleServiceAccount): Promise { 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, {