I have a asp.net core app with a angular 2 running on it. I'm using the oidc-client.js library to handle logging in. Currently, if the user is already logged in and follows a link to the site, the auth happens properly and the user is taken to the correct page. However, if they're not logged in, the get bounced to the login page just fine, get taken back to the site with the proper url, but eventually get taken to the /auth-callback page. At that point, the redirect url gets lost and they wind up at the default route of the site after auth-callback.
What I'm looking for is if there's any options in the oidc-client library that I can use to persist the correct url after the auth-callback call? Digging through the documentation and examples, nothing jumped out at me. Or am I going to have to put something together myself?
In your client code when you call signinRedirect
you could abuse the state property with something to use later (this is not what it's intended for) e.g new Oidc.UserManager().signinRedirect({state:window.location.href});
.
Then in your callback page you can use it:
mgr
.signinRedirectCallback()
.then(function (user) {
window.history.replaceState({}, window.document.title, window.location.origin + window.location.pathname);
window.location = user.state || "/";
});
well you have to create a separate html page in your assets to handle getting the tokens and store them after login redirect
you can create redirect_page.html in /assets folder
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.4.1/oidc-client.min.js"></script>
<script>
var config = {
userStore: new Oidc.WebStorageStateStore({ store: window.localStorage })
};
var mgr = new Oidc.UserManager(config);
mgr.signinRedirectCallback().then(() => {
window.history.replaceState({},
window.document.title,
window.location.origin);
window.location = "/";
}, error => {
console.error(error);
});
</script>
and set your userManager config
var config = {
...
redirect_uri: `${clientRoot}/assets/redirect_page.html`,
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With