gpt4 book ai didi

oauth-2.0 - 使用oidc-client检索状态数据

转载 作者:行者123 更新时间:2023-12-04 17:30:41 26 4
gpt4 key购买 nike

如何保留用户导航到的原始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>

或者,也许还有其他获取原始网址的方式?

谢谢你的帮助!

最佳答案

您的方法很好。您以自己的方式进行登录,然后在回调中稍微修改您的代码(使用返回的用户对象):

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

状态将是用户对象的一部分,并将具有您提交的值。而且您可以重定向到任何您想要的地方。

关于oauth-2.0 - 使用oidc-client检索状态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48446485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com