我上有一个角2运行一个asp.net核心应用。我使用的是OIDC-client.js库来处理登录。目前,如果用户已经登录并打开一个链接到该网站中,auth发生是否正常,用户被引导到正确的页面。但是,如果他们没有登录,则get反弹到登录页面就好了,要去采回用正确的URL的网站,但最终会带到/ AUTH-回调页面。在这一点上,重定向的URL已被丢失,他们最后在AUTH-回调后,该网站的默认路由。
是什么我要找的,如果有在,我可以用它来坚持在auth回拨电话后,正确的网址,OIDC客户端库的选择吗?通过文档和示例挖,没有跳出我。还是我将不得不把某些东西一起自己?
在您的客户端代码,当你调用signinRedirect
你需要的东西设置状态属性后e.g new Oidc.UserManager().signinRedirect({state:window.location.href});
使用。
然后在回调页面,您可以使用它:
mgr
.signinRedirectCallback()
.then(function (user) {
window.history.replaceState({}, window.document.title, window.location.origin + window.location.pathname);
window.location = user.state || "/";
});
好,你必须创建自己的资产处理得到令牌并登录重定向后存储在不同的html页面
您可以在创建redirect_page.html /资产的文件夹
<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>
并设置你的UserManager配置
var config = {
...
redirect_uri: `${clientRoot}/assets/redirect_page.html`,
}