IdentityModel / oidc-client-js

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

Add returnUrl as first class property in state #1169

Open brockallen opened 4 years ago

brockallen commented 4 years ago

and redirect automatically in signinCallback

ed-sparkes commented 3 years ago

Hi, in the absence of this do you have an example of how to do this manually. I am passing custom state object to siginRedirect with a targeturl in but struggling to work out how to get access to it after redirect ?

mgr.signinRedirect({state:{targetUrl: “https://Mysite.com/somepath “}})

danielmcormond commented 3 years ago

@ed-sparkes try something like this where you handle the callback:

new UserManager({response_mode: 'query'})
    .signinRedirectCallback()
    .then(user => location.href = user.state.targetUrl)
ed-sparkes commented 3 years ago

Thanks @danielmcormond, ill give that a go, i am currently using https://github.com/bjerkio/oidc-react which wraps this library in a React context, it provides and onSignIn event which provides the User but the state is coming through undefined, looks like maybe the state is only available on the signinRedirectCallback and this has been called and therefore state lost by the time the onSignIn event is called. I will confirm and raise a pr on oidc-react if this is the case