mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix(oauth): added extra logging to token refresh and added client_id in token refresh for airtable
This commit is contained in:
@@ -47,7 +47,11 @@ export async function getOAuthToken(userId: string, providerId: string): Promise
|
||||
const refreshResult = await refreshOAuthToken(providerId, credential.refreshToken!)
|
||||
|
||||
if (!refreshResult) {
|
||||
logger.error(`Failed to refresh token for user ${userId}, provider ${providerId}`)
|
||||
logger.error(`Failed to refresh token for user ${userId}, provider ${providerId}`, {
|
||||
providerId,
|
||||
userId,
|
||||
hasRefreshToken: !!credential.refreshToken,
|
||||
})
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -66,7 +70,12 @@ export async function getOAuthToken(userId: string, providerId: string): Promise
|
||||
logger.info(`Successfully refreshed token for user ${userId}, provider ${providerId}`)
|
||||
return accessToken
|
||||
} catch (error) {
|
||||
logger.error(`Error refreshing token for user ${userId}, provider ${providerId}`, error)
|
||||
logger.error(`Error refreshing token for user ${userId}, provider ${providerId}`, {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
providerId,
|
||||
userId,
|
||||
})
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -116,7 +125,15 @@ export async function refreshAccessTokenIfNeeded(
|
||||
const refreshedToken = await refreshOAuthToken(credential.providerId, credential.refreshToken)
|
||||
|
||||
if (!refreshedToken) {
|
||||
logger.error(`[${requestId || ''}] Failed to refresh token for credential: ${credentialId}`)
|
||||
logger.error(
|
||||
`[${requestId || ''}] Failed to refresh token for credential: ${credentialId}`,
|
||||
{
|
||||
credentialId,
|
||||
providerId: credential.providerId,
|
||||
userId: credential.userId,
|
||||
hasRefreshToken: !!credential.refreshToken,
|
||||
}
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -135,10 +152,13 @@ export async function refreshAccessTokenIfNeeded(
|
||||
)
|
||||
return refreshedToken.accessToken
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`[${requestId || ''}] Error refreshing token for credential: ${credentialId}`,
|
||||
error
|
||||
)
|
||||
logger.error(`[${requestId || ''}] Error refreshing token for credential: ${credentialId}`, {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
providerId: credential.providerId,
|
||||
credentialId,
|
||||
userId: credential.userId,
|
||||
})
|
||||
return null
|
||||
}
|
||||
} else if (!accessToken) {
|
||||
|
||||
@@ -469,10 +469,16 @@ async function fetchAndProcessAirtablePayloads(
|
||||
)
|
||||
throw new Error('Airtable access token not found.')
|
||||
}
|
||||
|
||||
logger.info(`[${requestId}] Successfully obtained Airtable access token`)
|
||||
} catch (tokenError: any) {
|
||||
logger.error(
|
||||
`[${requestId}] Failed to get Airtable OAuth token for user ${workflowData.userId}`,
|
||||
tokenError
|
||||
{
|
||||
error: tokenError.message,
|
||||
stack: tokenError.stack,
|
||||
userId: workflowData.userId,
|
||||
}
|
||||
)
|
||||
await persistExecutionError(
|
||||
workflowData.id,
|
||||
|
||||
+5
-2
@@ -409,8 +409,11 @@ export async function refreshOAuthToken(
|
||||
refresh_token: refreshToken,
|
||||
}
|
||||
|
||||
// Only add client_id and client_secret to body for non-Basic auth providers
|
||||
if (!useBasicAuth) {
|
||||
// For Airtable specifically, include client_id in body even with Basic auth
|
||||
if (provider === 'airtable') {
|
||||
bodyParams.client_id = clientId
|
||||
} else if (!useBasicAuth) {
|
||||
// For other non-Basic auth providers, include both credentials
|
||||
bodyParams.client_id = clientId
|
||||
bodyParams.client_secret = clientSecret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user