温馨提示:本文翻译自stackoverflow.com,查看原文请点击:identityserver4 - Identity Server 4 Silent Renew ErrorResponse: login_required
identityserver4 oidc-client-js

identityserver4 - Identity Server 4静默续订错误响应:login_required

发布于 2021-01-05 06:46:36

我已经从redux-oidc-example克隆了仓库,它在大多数情况下都起作用,但是几个小时后,它给出了以下错误:

操作有效负载:ErrorResponse: 在t的
新e(oidc-
client.min.js:1)
在t [作为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
};

和我的身份服务器配置:

{
        "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
      }

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

idsrv.session cookie

我认为这是问题的根本原因,我在相关的Github存储库中对其进行了搜索,然后尝试将Cookie.SameSite添加为无,但没有帮助:

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

任何想法!

查看更多

提问者
Attiqe
被浏览
0
Attiqe 2019-11-22 04:43

搜索Identity Server 4存储库后,对代码进行了以下更改:

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());

之后它开始工作,但是关闭浏览器或重新打开新标签后,您必须再次登录,我猜这是由于sessionStorage所致