Oidc-client-js: How to determine from where the signinrequest took place.

Created on 11 Sep 2016  路  6Comments  路  Source: IdentityModel/oidc-client-js

I'm creating an AngularJS application with the ui-router. Whenever a user navigates to a route that requires authentication a signinRequest is performed, but when the user is returned to the redirectUri from where the signinRedirectCallback() function is called I see no way to figure out where the user was when the signinRequest was started.

Is there some way I can find this out, or better yet, provide some custom state that is returned to the redirectUri?

Thanks in advance.

question

Most helpful comment

Apologies, it works exactly as you said and I didn't want to bother you with yet another 'new reply'-notification

So in short: when I call:

this.manager.signinRedirect({data: '/the/current/location'});

Then on the redirect page I can do this:

this.manager.signinRedirectCallback().then(function(user) {
    if (user.state)
        window.location = user.state
});

Initially I thought it didn't work because I had set breakpoints and it seems that when redirecting to the OP, the state value is encrypted or obscured somehow, but as it turns out, whatever you put in gets returned in the callback.

Thanks again for the help.

All 6 comments

You'd have to build that yourself in your UI framework, meaning when you detect "access denied" you'd need to track the current URL/path into your app and store it somewhere (possibly in the state param in oidc-client, but could be anywhere else like localStorage). Then on the callback page from your OP you load that state to then know where to redirect the user.

Thanks for taking the time to answer my question. What I meant to ask is: how do I get something in the state param using the oidc-client, and how do I read the value in the response? I've tried calling the manager's function like this:

this.manager.signinRedirect({state: '/the/current/location'});

But this value does not seem to propagate to the OP. In addition, even if it would. How would I find the value again on the callback page? Would I need parse the hash value manually?

I suppose I could use the localStorage or sessionStorage, but if at all possible, I'd like to avoid having to use such a broad global storage for a value that could be kept locally if passed around properly.

The property name is data on the object passed to signinRedirect. And on the signinRedirectCallback, it's called state on the returned user. And yes, this should be more clear/obvious. I think the sample does it.

Thanks, I'll take a look at it tomorrow.

Any update?

Apologies, it works exactly as you said and I didn't want to bother you with yet another 'new reply'-notification

So in short: when I call:

this.manager.signinRedirect({data: '/the/current/location'});

Then on the redirect page I can do this:

this.manager.signinRedirectCallback().then(function(user) {
    if (user.state)
        window.location = user.state
});

Initially I thought it didn't work because I had set breakpoints and it seems that when redirecting to the OP, the state value is encrypted or obscured somehow, but as it turns out, whatever you put in gets returned in the callback.

Thanks again for the help.

Was this page helpful?
0 / 5 - 0 ratings