1

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

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

4

1 回答 1

0

对于您的 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>
于 2018-09-06T23:31:55.680 回答