Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving state data with oidc-client

How to keep the original url that the user was navigating to? Say I have an unauthenticated user navigates to http://localhost:9000/customer/123

To authenticate the user I would do a:

// in my app.js  
new Oidc.UserManager().signinRedirect({state:'customer/123'}); // need a way to keep this url

When that returns to the callback.html where I need a way of going to the origianal url:

// callback.html
<script src="oidc-client.js"></script>
<script>
    Oidc.Log.logger = console;
    new Oidc.UserManager().signinRedirectCallback().then(function () {

        var state = 'customer/123' // how to do a redirect to the page originally requested page?
        window.location.href="http://localhost:9000/ + state 
    }).catch(function (e) {
        console.error(e);
    });
</script>

Or maybe there are other build in ways of getting the origianl url?

Thanks for any help!

like image 734
Larsi Avatar asked Jan 25 '18 15:01

Larsi


1 Answers

Your approach is good. You sign in the way you are doing it, and then in the callback, slightly modify your code (use the user object that is returned):

new Oidc.UserManager().signinRedirectCallback().then(function (user){
    var url = user.state;
    //more code here
}

The state will be part of the user object, and will have the value that you have submited. And you can redirect to wherever you want.

like image 121
m3n7alsnak3 Avatar answered Dec 13 '22 09:12

m3n7alsnak3