Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

How can I use cache in IdentityServer4? #5007

Closed
Demon520-coder opened this issue Oct 30, 2020 · 2 comments
Closed

How can I use cache in IdentityServer4? #5007

Demon520-coder opened this issue Oct 30, 2020 · 2 comments

Comments

@Demon520-coder
Copy link

In my project,I want to add the clientStoreCache,resourceStoreCache,corsCache. I have read the doc of setting cache from here http://docs.identityserver.io/en/release/topics/startup.html?highlight=AddClientStoreCache#in-memory-configuration-stores.
But it dosen't work. Is anyone can help me? Thank you!

public static IServiceCollection RegisterIdentityServer(this IServiceCollection services, IWebHostEnvironment environment, IdentityServerConfig serverConfig)
        {
            var jwtCertficate = serverConfig.Certificate["Jwt"];
            var currentAssemblyName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            services.AddIdentityServer(op =>
            {
                if (environment.IsDevelopment())
                {
                    op.Events.RaiseErrorEvents = true;
                    op.Events.RaiseFailureEvents = true;
                    op.Events.RaiseInformationEvents = true;
                    op.Events.RaiseSuccessEvents = true;
                }
                else
                {
                    op.Discovery.ShowGrantTypes = false;
                    op.Discovery.ShowIdentityScopes = false;
                    op.Discovery.ShowApiScopes = false;
                }

                op.Authentication.CookieLifetime = TimeSpan.FromSeconds(Constants.CookieExpireIn);
                op.Authentication.CookieAuthenticationScheme = Constants.AuthenCookieName;

                op.AccessTokenJwtType = "jwt";
                op.Caching.ClientStoreExpiration = TimeSpan.FromMinutes(30);
                op.Caching.ResourceStoreExpiration = TimeSpan.FromMinutes(30);
                op.Caching.CorsExpiration = TimeSpan.FromMinutes(30);

            }).AddConfigurationStoreCache()
              .AddSigningCredential(new X509Certificate2(jwtCertficate.Path, jwtCertficate.Pwd))
              .AddProfileService<CustomeProfileService>()
              .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()
              .AddCustomTokenRequestValidator<CustomTokenValidator>()

              .AddConfigurationStore(op =>
                {
                    op.ConfigureDbContext = (db) =>
                    {
                        db.UseSqlServer(serverConfig.ConnectionString, sqlDb => sqlDb.MigrationsAssembly(currentAssemblyName));
                    };
                }).AddOperationalStore(op =>
                {
                    op.EnableTokenCleanup = serverConfig.TokenCleanup.EnableTokenCleanup;
                    op.TokenCleanupInterval = serverConfig.TokenCleanup.TokenCleanupInterval;
                    op.TokenCleanupBatchSize = serverConfig.TokenCleanup.TokenCleanupBatchSize;
                    op.ConfigureDbContext = (db) =>
                    {
                        db.UseSqlServer(serverConfig.ConnectionString, sqlDb => sqlDb.MigrationsAssembly(currentAssemblyName));
                    };
                });


            services.AddAuthentication(Constants.AuthenCookieName)
                    .AddCookie(Constants.AuthenCookieName, op =>
                    {
                        op.ExpireTimeSpan.Add(TimeSpan.FromSeconds(Constants.CookieExpireIn));
                    });

            return services;
        }

Relevant parts of the log file

   <log goes here>
@stale
Copy link

stale bot commented Nov 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.

@stale stale bot added the wontfix label Nov 9, 2020
@stale stale bot closed this as completed Nov 14, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant