AccessToken 过期后静默刷新仍然有效

问题描述

我有一个 ID4 身份验证服务器,它与一个 Angular 应用运行良好,该应用通过 SilentRefresh 和 PCKE 授权流程实现了 angular-oauth2-oidc

一切正常 - ID4 配置为以 5 分钟的生命周期提供 AccessToken,Angular 应用程序将每分钟静默刷新令牌(可能会随着 0.75 时间的流逝而更改为刷新)。然而,我发现的问题是,我可以关闭已登录的浏览器 - 然后 10 分钟后在网站上再次打开它(在原始 AccessToken 过期后没有刷新) - 但是静默刷新会刷新令牌并且用户保持登录状态。这是一个重大的安全漏洞。

我的客户端配置如下:

{
    issuer: config.authServerUrl,clientId: '<redacted>',// The "Auth Code + PKCE" client
    responseType: 'code',redirectUri: window.location.origin,silentRefreshRedirectUri: window.location.origin + '/silent-refresh.html',postLogoutRedirectUri: window.location.origin,scope: 'openid profile email api',useSilentRefresh: true,// Needed for Code Flow to suggest using iframe-based refreshes
    silentRefreshTimeout: 60000,// For faster testing
    sessionChecksEnabled: true,showDebugInformation: !config.production,// Also requires enabling "Verbose" level in devtools
    clearHashAfterLogin: false,nonceStateSeparator : 'semicolon',// Real semicolon gets mangled by IdentityServer's URI encoding
  }

我的 ID4 配置如下所示:

      {
        "Enabled": true,"ClientId": "<redacted>","ClientName": "<redacted>","ClientSecrets": [ { "Value": "<redacted>" } ],"AccessTokenLifetime": "300","AllowedGrantTypes": [ "authorization_code" ],"AllowedScopes": [ "openid","profile","email","api" ],"AllowedCorsOrigins": [
          "http://localhost:4200"
        ],"PostLogoutRedirectUris": [
          "http://localhost:4200"
        ],"RedirectUris": [
          "http://localhost:4200","http://localhost:4200/silent-refresh.html"
        ]
      }

我希望这种行为是,只有在 AccessToken 的到期时间内再次在站点上打开浏览器时,静默刷新才会起作用 - 即,如果我在 AccessToken 过期后打开 - 那么我无法刷新并且需要登录。

似乎 Silent Refresh 不使用 RefreshTokens,因为登录时显示的范围不包括 offline_access 并且我没有在 ID4 端将 AllowOfflineAccess 设置为 true。此处是否使用了刷新令牌 - 是否以某种方式暗示了配置 - 如果是这样,为什么您可以允许 RefreshTokens 生命周期长于 AccessTokens?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)