OIDC客户端登录后重定向

问题描述 投票:3回答:2

我上有一个角2运行一个asp.net核心应用。我使用的是OIDC-client.js库来处理登录。目前,如果用户已经登录并打开一个链接到该网站中,auth发生是否正常,用户被引导到正确的页面。但是,如果他们没有登录,则get反弹到登录页面就好了,要去采回用正确的URL的网站,但最终会带到/ AUTH-回调页面。在这一点上,重定向的URL已被丢失,他们最后在AUTH-回调后,该网站的默认路由。

是什么我要找的,如果有在,我可以用它来坚持在auth回拨电话后,正确的网址,OIDC客户端库的选择吗?通过文档和示例挖,没有跳出我。还是我将不得不把某些东西一起自己?

javascript angular oidc
2个回答
3
投票

在您的客户端代码,当你调用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 || "/";
  });

2
投票

好,你必须创建自己的资产处理得到令牌并登录重定向后存储在不同的html页面

  1. 登录成功在您的OpenID提供商
  2. 重定向到你的HTML静态页面
  3. 您的页面将获得令牌和他们的localStorage存储例如
  4. 当令牌是准备好了,你的静态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`,
}
© www.soinside.com 2019 - 2024. All rights reserved.