Lar*_*rsi 2 oauth-2.0 identityserver4 implicit-flow oidc-client-js
如何保留用户导航到的原始URL?说我有一个未经身份验证的用户导航到http:// localhost:9000 / customer / 123
要验证用户身份,我将执行以下操作:
// in my app.js
new Oidc.UserManager().signinRedirect({state:'customer/123'}); // need a way to keep this url
Run Code Online (Sandbox Code Playgroud)
当返回到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>
Run Code Online (Sandbox Code Playgroud)
或者,也许还有其他获取原始网址的方式?
谢谢你的帮助!
您的方法很好。您以自己的方式进行登录,然后在回调中稍微修改代码(使用返回的用户对象):
new Oidc.UserManager().signinRedirectCallback().then(function (user){
var url = user.state;
//more code here
}
Run Code Online (Sandbox Code Playgroud)
状态将是用户对象的一部分,并将具有您提交的值。您可以重定向到任何您想要的地方。
归档时间: |
|
查看次数: |
2065 次 |
最近记录: |