如何保留用户导航到的原始url?假设我有一个未经身份验证的用户导航到http://localhost:9000/customer/123
要对用户进行身份验证,我将执行以下操作:
// in my app.js
new Oidc.UserManager().signinRedirect({state:'customer/123'}); // need a way to keep this url当它返回到callback.html时,我需要一种转到原始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>或者可能有其他的构建方式来获得原始的url?
谢谢你的帮助!
发布于 2018-01-26 00:26:30
你的方法很好。您可以按照自己的方式登录,然后在回调中稍微修改一下代码(使用返回的user对象):
new Oidc.UserManager().signinRedirectCallback().then(function (user){
var url = user.state;
//more code here
}状态将是user对象的一部分,并且将具有您已提交的值。你可以重定向到你想要的任何地方。
https://stackoverflow.com/questions/48446485
复制相似问题