@@ -347,6 +347,7 @@ export async function refreshOAuthToken(
347347 let tokenEndpoint : string
348348 let clientId : string | undefined
349349 let clientSecret : string | undefined
350+ let useBasicAuth = false
350351
351352 switch ( provider ) {
352353 case 'google' :
@@ -373,6 +374,7 @@ export async function refreshOAuthToken(
373374 tokenEndpoint = 'https://airtable.com/oauth2/v1/token'
374375 clientId = process . env . AIRTABLE_CLIENT_ID
375376 clientSecret = process . env . AIRTABLE_CLIENT_SECRET
377+ useBasicAuth = true
376378 break
377379 case 'supabase' :
378380 tokenEndpoint = 'https://api.supabase.com/v1/oauth/token'
@@ -387,21 +389,37 @@ export async function refreshOAuthToken(
387389 throw new Error ( `Missing client credentials for provider: ${ provider } ` )
388390 }
389391
392+ // Prepare request headers and body
393+ const headers : Record < string , string > = {
394+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
395+ ...( provider === 'github' && {
396+ Accept : 'application/json' ,
397+ } ) ,
398+ }
399+
400+ // For providers using Basic auth, add Authorization header
401+ if ( useBasicAuth ) {
402+ const basicAuth = Buffer . from ( `${ clientId } :${ clientSecret } ` ) . toString ( 'base64' )
403+ headers [ 'Authorization' ] = `Basic ${ basicAuth } `
404+ }
405+
406+ // Prepare request body
407+ const bodyParams : Record < string , string > = {
408+ grant_type : 'refresh_token' ,
409+ refresh_token : refreshToken ,
410+ }
411+
412+ // Only add client_id and client_secret to body for non-Basic auth providers
413+ if ( ! useBasicAuth ) {
414+ bodyParams . client_id = clientId
415+ bodyParams . client_secret = clientSecret
416+ }
417+
390418 // Refresh the token
391419 const response = await fetch ( tokenEndpoint , {
392420 method : 'POST' ,
393- headers : {
394- 'Content-Type' : 'application/x-www-form-urlencoded' ,
395- ...( provider === 'github' && {
396- Accept : 'application/json' ,
397- } ) ,
398- } ,
399- body : new URLSearchParams ( {
400- client_id : clientId ,
401- client_secret : clientSecret ,
402- grant_type : 'refresh_token' ,
403- refresh_token : refreshToken ,
404- } ) . toString ( ) ,
421+ headers,
422+ body : new URLSearchParams ( bodyParams ) . toString ( ) ,
405423 } )
406424
407425 if ( ! response . ok ) {
0 commit comments