IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 842 forks source link

Is there a way to modify the post_logout_redirect_uri at run-time? #1347

Closed mellis481 closed 3 years ago

mellis481 commented 3 years ago

I have a /loggedout page which is set in client settings as the post_logout_redirect_uri. This is the page users will see when they manually log out. We're in the process of adding an idle timeout and want the messaging on the /loggedout page to be different if the user was timed out vs. logged out. I, therefore, am hoping to be able to add a query string (eg. ?timedout=true) to the /loggedout post-logout redirect or, alternatively, provide a different URL (eg. /timedout).

I did some digging and came across extraQueryParams which can be passed in to userManager.signoutRedirect(), but realized that this will not do what I need it to do. This adds a query string to the entire endsession redirect URL, not to the post_logout_redirect_uri query string parameter which is part of that URL.

I also tried to set window.location in UserManager callback (userManager.signoutRedirect().then()), but that ends up firing before the redirect to the IdP's end session page occurs so the session is never ended.

Is there any way to modify the post_logout_redirect_uri at run-time to accomplish what I'm trying to accomplish? I assume I can create a second UserManager instance, but that isn't ideal to have to do that and I'm actually not sure if having multiple UserManager instances will cause undesirable behavior.

ghostd commented 3 years ago

Hi,

Did you try to call userManager.signoutRedirect({post_logout_redirect_uri: 'http://whatever.example.com/some/path'}). I guess it could work according to the code: https://github.com/IdentityModel/oidc-client-js/blob/a8a70ce68bd07373abd7d33e016a97adc5d204bc/src/UserManager.js#L433-L447

mellis481 commented 3 years ago

@ghostd That works. Thanks!