【问题标题】:Session timeout using SPA and oidc-js使用 SPA 和 oidc-js 的会话超时
【发布时间】:2019-01-23 19:15:00
【问题描述】:

我将 Angular 5 与 oidc-client 和身份服务器 4 一起使用。oidc-client 是否支持会话超时,或者我需要手动实现它?

我的意思是会话超时,用户将在一段时间不活动后注销

【问题讨论】:

    标签: identityserver4 oidc-client-js


    【解决方案1】:

    对于您的 SPA 应用程序,您可以使用隐式流程,无法自动刷新令牌,但 oidc-client.js 可以让您轻松。您可以使用静默刷新,oidc-client 将在新的 access_token 到期之前发送活动的 cookie 会话以获取新的 access_token。你只需要配置它

    const config = {
      authority: xxxxx,
      client_id: xxxxx,
      popup_redirect_uri: `${OidcConfig.clientRoot}/assets/html/popup-login-redirect.html`,
      scope: 'openid profile',
      response_type: 'id_token token',
      post_logout_redirect_uri: `${OidcConfig.clientRoot}?postLogout=true`, // delet all stored tokens after logout
      userStore: new WebStorageStateStore({ store: window.localStorage }),
      automaticSilentRenew: true, // enable silent refresh
      silent_redirect_uri: `${OidcConfig.clientRoot}/assets/html/silent-refresh-redirect.html` // here when you can get the new tokens
    };
    

    这里是silent-refresh-redirect.html的内容

      <script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.5.1/oidc-client.min.js"></script>
      <script>
      var config = {
         userStore: new Oidc.WebStorageStateStore({ store: window.localStorage })
      };
      new Oidc.UserManager(config).signinSilentCallback()
        .catch((err) => {
            console.log(err);
        });
    
      </script>
    

    【讨论】:

    • 感谢@Fateh,我需要会话在一段时间不活动后过期。这是开箱即用的,还是我需要手动监控他的活动并将他注销?
    • @Jek 你找到答案了吗?我目前正在实施这个。
    • @Narshe 我们通过监控用户 KeyDown 和 MouseMove 事件来实施自己的解决方案。 MouseMove 在每次移动之间延迟 1 秒以避免性能问题
    猜你喜欢
    • 2018-11-25
    • 2021-03-07
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 2011-04-24
    • 2018-01-28
    相关资源
    最近更新 更多