MCPcopy Index your code
hub / github.com/simstudioai/sim / buildAuthRequest

Function buildAuthRequest

apps/sim/lib/oauth/oauth.ts:1430–1465  ·  view source on GitHub ↗

* Build the authentication request headers and body for OAuth token refresh

(
  config: ProviderAuthConfig,
  refreshToken: string
)

Source from the content-addressed store, hash-verified

1428 * Build the authentication request headers and body for OAuth token refresh
1429 */
1430function buildAuthRequest(
1431 config: ProviderAuthConfig,
1432 refreshToken: string
1433): { headers: Record<string, string>; bodyParams: Record<string, string>; useJsonBody?: boolean } {
1434 const headers: Record<string, string> = {
1435 'Content-Type': config.useJsonBody ? 'application/json' : 'application/x-www-form-urlencoded',
1436 ...config.additionalHeaders,
1437 }
1438
1439 const bodyParams: Record<string, string> = {
1440 grant_type: 'refresh_token',
1441 }
1442
1443 // Handle refresh token placement
1444 if (config.refreshTokenInAuthHeader) {
1445 // Cal.com style: refresh token in Authorization header as Bearer token
1446 headers.Authorization = `Bearer ${refreshToken}`
1447 } else {
1448 // Standard OAuth: refresh token in request body
1449 bodyParams.refresh_token = refreshToken
1450 }
1451
1452 if (config.useBasicAuth) {
1453 // Use Basic Authentication - credentials in Authorization header only
1454 const basicAuth = Buffer.from(`${config.clientId}:${config.clientSecret}`).toString('base64')
1455 headers.Authorization = `Basic ${basicAuth}`
1456 } else {
1457 // Use body credentials - include client credentials in request body
1458 bodyParams.client_id = config.clientId
1459 if (config.clientSecret) {
1460 bodyParams.client_secret = config.clientSecret
1461 }
1462 }
1463
1464 return { headers, bodyParams, useJsonBody: config.useJsonBody }
1465}
1466
1467function getBaseProviderForService(providerId: string): string {
1468 if (providerId in OAUTH_PROVIDERS) {

Callers 1

refreshOAuthTokenFunction · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected