panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

Issuer initiates with proxy but issuer client can't complete calls #404

Closed alexlindsay closed 3 years ago

alexlindsay commented 3 years ago

Describe the bug I'm able to set up my issuer with our proxy agent and get the client after the "discover" call, but when the issuer client calls the callback method with my oidc redirect url I get an error as follows:

RequestError: Timeout awaiting 'request' for 3500ms

I've tried changing the timeout of our issuer's options but it always stays at 3500ms. It seems our issuer client isn't calling through our proxy as intended.

To Reproduce NOTE: variable values have been purposefully omitted ` Issuer[custom.http_options] = function(options) { options.agent = { https: new HttpsProxyAgent({ proxy: proxyUrl }) }
return options; };

return Issuer.discover(discoverUrl) .then(issuer => { const issuerClient = new issuer.Client({ client_id: clientId, client_secret: clientSecret, token_endpoint_auth_method: 'client_secret_post', response_types: ['code'], redirect_uris: [ redirectUrl ], });

    return Promise.resolve(issuerClient);
}).then(client => {
    return client
            .callback(redirectUrl, params, checks)
            .then(response => {
              console.log("Callback response ", response);
            })
}).catch(err => {
    console.log("ERROR ", err);
})

`

Steps to reproduce the behaviour:

  1. Run the above node script with proper url values for proxyUrl, discoverUrl, clientSecret, clientId, redirectUrl, params, and checks (fails at client.callback())

Expected behaviour Callback to return oidc values

Environment:

Additional context Add any other context about the problem here.

marcbachmann commented 3 years ago

Thanks for the heads up. I also just needed to configure that. I've directly used the global option after running into the issue where I've only configured the client.

require('openid-client').custom.setHttpOptionsDefaults({
  agent: {
    http: new HttpProxyAgent(agentOpts),
    https: new HttpsProxyAgent(agentOpts)
  }
})
panva commented 3 years ago

Changing Issuer class options does not affect client instance options. You're using a granular control setting rather than a global one.

https://github.com/panva/node-openid-client/blob/main/docs/README.md#customizing

Behaves as expected.