Am I using customFetch wrong? #813
-
|
Hi! I think this is the right place for my question :) Our Identity Provider is the Oracle Access Manager and it requires a custom header "x-oauth-identity-domain-name" set in any requests to that server. To do this of course I want to use the customFetch option that openid-client offers. So what I do is:
const autodiscoveredConfig = await openIdClient.discovery(
new URL(issuerUrl),
clientConfig.clientId,
{
client_secret: clientConfig.clientSecret,
},
openIdClient.ClientSecretPost(clientConfig.clientSecret),
{
// Custom fetch is required for OAM. OAM Requires a non-standard defined header in its request to differentiate the domains.
[openIdClient.customFetch]: buildCustomFetch(logger, clientConfig)
}
)
function buildCustomFetch(logger, clientConfig) {
return (url, options) => {
options.headers['x-oauth-identity-domain-name'] = clientConfig.domain
console.log('###################################################################################')
logger.debug(`Running custom fetch for OpenID Configuration (${clientConfig.issuer}) -> Url: ${url} | Options: ${JSON.stringify(options)} | Body: ${(options.body ?? 'No Body').toString()}`)
console.log('###################################################################################')
return undici.fetch(url, options)
}
}When the autodiscovery runs, it prints the expected log Next, I do the call and redirect and now want to make the Call to the token endpoint to get the tokens: const tokens = await openIdClient.authorizationCodeGrant(
openidClientConfig,
currentURL,
{
pkceCodeVerifier: codeVerifier,
expectedState: state,
},
)But now, there are no logs from the customFetch that I set before, which makes the request fail 👎 Am I setting the customFetch wrong? Am I misunderstanding how it is applied? I am grateful for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
Oh yah, I am using node 22.14.0, and openid-client is installed at 6.6.2 |
Beta Was this translation helpful? Give feedback.
-
|
FYI: When doing a client credentials request, the custom Fetch runs as usual: const tokens = await openIdClient.clientCredentialsGrant(config.openidClientConfig, {
scope: config.scopes.join(' '),
})logs: |
Beta Was this translation helpful? Give feedback.
-
|
I can't see a flaw |
Beta Was this translation helpful? Give feedback.
-
|
I agree your code snippet works with our issuer. But at least that means that conceptually I understood it correctly. Thanks for this snippet! |
Beta Was this translation helpful? Give feedback.
I can't see a flaw