Identity Server 4 Silent Renew ErrorResponse: login_required

Att*_*iqe 7 identityserver4 oidc-client-js

我已经从redux-oidc-example克隆了 repo并且它在大多数情况下都有效,但是几个小时后它给出了以下错误:

操作负载:ErrorResponse: login_required
at new e (oidc-client.min.js:1)
at t [as _processSigninParams] (oidc-client.min.js:1)
at t [as validateSigninResponse] (oidc-client.min. js:1)
在 oidc-client.min.js:1

UserManager.js 看起来像这样:

const userManagerConfig = {
  client_id: 'js.dev',
  client_secret: 'secret',
  redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}/callback`,
  response_type: 'id_token token',
  scope: 'openid email profile role offline_access',
  authority: 'http://localhost:8080',
  silent_redirect_uri: `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}/silent_renew.html`,
  automaticSilentRenew: true,
  filterProtocolClaims: true,
  loadUserInfo: true
};
Run Code Online (Sandbox Code Playgroud)

和我的身份服务器配置:

{
        "Enabled": true,
        "ClientId": "js.dev",
        "ClientName": "Javascript Client",
        "ClientSecrets": [ { "Value": "K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=" } ],
        "AllowedGrantTypes": [ "implicit", "authorization_code" ],
        "AllowedScopes": [ "openid", "email", "profile", "role", "offline_access" ],
        "AllowOfflineAccess": true,
        "AllowAccessTokensViaBrowser":true,
        "RedirectUris": [
          "http://localhost:8081/callback",
          "http://localhost:8081/silent_renew.html"
        ],
        "PostLogoutRedirectUris": [
          "http://localhost:8081"
        ],
        "AccessTokenLifetime": 900,
        "RequireConsent": false
      }
Run Code Online (Sandbox Code Playgroud)

我注意到在错误之前,最后一个有效响应有一个 cookie 响应(idsrv.session),其值为空,到期日期设置为上一年:

idsrv.session cookie

我相信这是问题的根本原因,我在相关的 Github 存储库中搜索了它并尝试将 Cookie.SameSite 添加到 none 但它没有帮助:

services.AddAuthentication()
                .AddSaml(Configuration,externalProviders.UseSaml)
                .AddCookie(options => {
                    options.SlidingExpiration = true;
                    options.ExpireTimeSpan = TimeSpan.FromDays(30);
                    options.Cookie.SameSite = SameSiteMode.None;
                });
Run Code Online (Sandbox Code Playgroud)

任何的想法!

mac*_*kie 7

这可能是由于您的 IDP 会话到期 - 如果您调用authorize端点,prompt=none但由于不存在有效会话(即身份验证 cookie 不存在或已过期)而无法满足该请求,则它将返回error=login_required.

如果发生这种情况,那么正确的做法是prompt=login在顶级浏览器窗口中执行交互式(即)登录请求。


Att*_*iqe 4

搜索Identity Server 4 repo后,我对代码进行了以下更改:

services.AddIdentityServer(options=>
                {
                    options.Authentication.CookieLifetime = TimeSpan.FromDays(30);
                    options.Authentication.CookieSlidingExpiration = true;
                })
                .AddProfileService<ProfileService>()
                .AddSigningCertificate(Configuration)
                .AddInMemoryClients(Configuration.GetSection("IdentityServer:Clients"))
                .AddInMemoryIdentityResources(Resources.GetIdentityResources());
Run Code Online (Sandbox Code Playgroud)

它随后开始工作,但在关闭浏览器或重新打开新选项卡后,您必须再次登录,我想这是因为sessionStorage