panva / openid-client

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

Function Callback/ Query Params #310

Closed MohammedKevin closed 3 years ago

MohammedKevin commented 3 years ago

Is it possible to provide a function callback to the client which gets called right before the user gets redirected / the authentication flow starts?

Because one of the entry points of my application includes query parameters and I want to store this query parameters in the session with / under the state key. When the user gets redirected to the application again I can read the session value with the state key from the redirect url. ThenI can "rebuild" the url, append the query params and redirect the user to this url. The callback I am looking for also have to pass the state key as parameter, so I can store the value in the session under the state key. As described in this article the described use case should be possible with the state key: https://auth0.com/docs/protocols/state-parameters How do I can do that?

panva commented 3 years ago

You can only be asking about the Passport strategy I presume (very much light on the details here). No, there's no callback, but you can trigger the authenticate call with state you've prepared. Then it's just a matter of orchestrating your passport call.

npeham commented 3 years ago

@panva I have exactly the same problem as @MohammedKevin described.

@panva Can you maybe post the function with which I can trigger the authenticate call? Do you have an example? That would be very nice, thank you! :pray:

panva commented 3 years ago
passport.authenticate('oidc', { state: crypto.randomBytes(16).toString('base64url') })(req, res, next);