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

Angular AccessToken过期后,静默刷新仍然有效,angular,identityserver4,angular-oauth2-oidc,Angular,Identityserver4,Angular Oauth2 Oidc,我有一个ID4身份验证服务器,它与一个Angular应用程序配合得很好,该应用程序使用SilentRefresh和PCKE授权流实现 一切都很好-ID4被配置为服务AccessTokens,使用寿命为5分钟,Angular应用程序将每分钟静默刷新一次token(可能会更改为使用0.75时间刷新)。然而,我发现的问题是,我可以在登录后关闭浏览器-然后在10分钟后在站点上再次打开它(在原始AccessToken已过期而未刷新后)-但是静默刷新会启动刷新,刷新令牌,用户保持登录状态。这是一个重大的安全

我有一个ID4身份验证服务器,它与一个Angular应用程序配合得很好,该应用程序使用SilentRefresh和PCKE授权流实现

一切都很好-ID4被配置为服务AccessTokens,使用寿命为5分钟,Angular应用程序将每分钟静默刷新一次token(可能会更改为使用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
  }
      {
        "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"
        ]
      }
{
颁发者:config.authServerUrl,
clientId:“”,//验证代码+PKCE客户端
responseType:'代码',
重定向URI:window.location.origin,
silentRefreshRedirectUri:window.location.origin+'/silent refresh.html',
postLogoutRedirectUri:window.location.origin,
作用域:“openid配置文件电子邮件api”,
useSilentRefresh:true,//代码流需要它来建议使用基于iframe的刷新
silentRefreshTimeout:60000,//用于更快的测试
SessionCheckEnabled:true,
showDebugInformation:!config.production,//还需要在devtools中启用“详细”级别
clearHashAfterLogin:false,
nonEstateSepator:'分号',//实际分号被IdentityServer的URI编码弄乱
}
我的ID4配置如下所示:

{
    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
  }
      {
        "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"
        ]
      }
{
“启用”:正确,
“ClientId”:“,
“客户名称”:“,
“ClientSecrets”:[{“值”:“}],
“AccessTokenLifetime”:“300”,
“AllowedGrantTypes”:[“授权码”],
“AllowedScopes”:[“openid”、“配置文件”、“电子邮件”、“api”],
“允许的科索里根人”:[
"http://localhost:4200"
],
“PostLogoutRedecturis”:[
"http://localhost:4200"
],
“重定向URI”:[
"http://localhost:4200",
"http://localhost:4200/silent-刷新.html“
]
}
我希望这样的行为是,如果我在AccessToken的到期时间内再次在站点上打开浏览器(即,如果我在AccessToken过期后打开浏览器),则静默刷新将起作用,然后我无法刷新,需要登录


静默刷新似乎不使用RefreshTokens,因为登录时显示的作用域不包括脱机访问,并且我没有在ID4端将
AllowOfflineAccess
设置为true。此处是否使用了刷新令牌?配置是否以某种方式暗示?如果是,为什么允许刷新令牌的生存期长于AccessTokens?

一个想法是您的IdentityServer设置了自己的“会话”首次登录期间使用的cookie允许应用程序以静默方式重新验证并获取新的访问令牌。您可以从IdentityServer调整此cookie的生存期


我会使用类似代理的方式来验证这种行为。

如果目的是让他们的会话结束,如果他们关闭浏览器,那么在
IdentityServer 4
IDP中使用非持久性身份验证cookie就可以了。您还应确保您的客户端应用程序注销机制也会通过结束会话端点触发IDP注销。我希望“记住我”功能能够记住登录屏幕中的用户,但不能用于静默刷新,我想,您所说的ID4“记住我”会话cookie用于两个。。。。然后我想,我需要让客户端应用程序使用刷新令牌,而不仅仅是允许通过会话令牌进行重新身份验证——将静默刷新与刷新的“会话cookie方法”分离。我想这是通过在客户端应用程序中请求
offline\u访问
scope,并在ID4上启用
allowOffline访问
。我说的对吗?离线访问直到给你刷新令牌,那么问题是你应该在后端还是前端进行openid连接?看见