Skip to content

Commit

Permalink
Keep agents from cloning in simple-oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
nalanj committed Feb 4, 2025
1 parent 00df61f commit d005de3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/shared/lib/clients/oauth2.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getSimpleOAuth2ClientConfig(

const authConfig = provider as ProviderOAuth2;

return {
const clientConfig: Merge<ModuleOptions, { http: WreckHttpOptions }> = {
client: {
id: providerConfig.oauth_client_id,
secret: providerConfig.oauth_client_secret
Expand All @@ -36,25 +36,27 @@ export function getSimpleOAuth2ClientConfig(
authorizeHost: authorizeUrl.origin,
authorizePath: authorizeUrl.pathname
},
http: {
headers,
// @ts-expect-error badly documented feature https://github.com/hapijs/wreck/blob/ba28b0420d6b0998cd8e61be7f3f8822129c88fe/lib/index.js#L34-L40
agents:
httpAgent && httpsAgent
? {
http: httpAgent,
https: httpsAgent,
httpsAllowUnauthorized: httpsAgent
}
: undefined
},
options: {
authorizationMethod: authConfig.authorization_method || 'body',
bodyFormat: authConfig.body_format || 'form',
// @ts-expect-error seems unused ?
scopeSeparator: provider.scope_separator || ' '
}
};

// make sure agents aren't enumerable so they don't get cloned in simple-oauth2
const httpConfig = { headers };
Object.defineProperty(httpConfig, 'agents', {
value: {
http: httpAgent,
https: httpsAgent,
httpsAllowUnauthorized: httpsAgent
},
enumerable: false
});

clientConfig.http = httpConfig;
return clientConfig;
}

export async function getFreshOAuth2Credentials(
Expand Down

0 comments on commit d005de3

Please sign in to comment.