【问题标题】:identityserver using aspnetidentity id_token on server reboot在服务器重新启动时使用 aspnetidentity id_token 的身份服务器
【发布时间】:2017-09-07 08:09:13
【问题描述】:

我有带有 aspnetidentity 的 identityserver4,它正在工作,但在服务器重新启动时,应用程序会将用户重定向到再次签名。

 services.AddIdentityServer(options =>
       {
           options.Events.RaiseSuccessEvents = true;
           options.Events.RaiseFailureEvents = true;
           options.Events.RaiseErrorEvents = true;
           //options.Authentication.CookieLifetime = TimeSpan.FromSeconds(30);
           options.Authentication.CookieLifetime = TimeSpan.FromMinutes(20);
       }).AddSigningCredential(cert)
            //.AddInMemoryIdentityResources(Config.GetIdentityResources())
            //.AddInMemoryApiResources(Config.GetApiResources())
            //.AddInMemoryClients(Config.GetClients())
            //.AddTestUsers(Config.GetUsers());
            .AddConfigurationStore(builder =>
                builder.UseSqlServer(connectionString, options =>
                    options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder =>
                builder.UseSqlServer(connectionString, options =>
                     options.MigrationsAssembly(migrationsAssembly)))
            .AddAspNetIdentity<ApplicationUser>()                
            .AddProfileService<ProfileService>();

使用访问令牌我没有任何问题,因为它是 cookie 格式的客户端浏览器。无论服务器是否重新启动,资源仍然允许。

但 id_token 是相同的情况,但是当请求转到 Idmsrv 端点连接/授权时,它会让用户再次登录。

【问题讨论】:

    标签: asp.net-identity identityserver4


    【解决方案1】:

    将密钥保存到磁盘而不是内存中,因此当 cookie 返回服务器使用密钥解密时,它将拥有一个密钥。

    //参考https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-storage-providers

    //REFERENCE 持久化键 http://www.tugberkugurlu.com/archive/asp-net-core-authentication-in-a-load-balanced-environment-with-haproxy-and-redis

    services.AddDataProtection() //Microsoft.AspNetCore.DataProtection.Redis package
                            .PersistKeysToFileSystem(new DirectoryInfo("F:\\Jana\\Certs\\Keys\\"));
    

    【讨论】:

      猜你喜欢
      • 2019-08-23
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多