IdentityServer 4: No storage mechanism for grants specified - use AddInMemoryStores

Hussein Salman picture Hussein Salman · Nov 25, 2016 · Viewed 11.8k times · Source

I am using Identity Server 4 , ASP.NET Core and trying to replace the IdentityServer developer in Production environment. But getting the following error:

No storage mechanism for grants specified. Use the 'AddInMemoryStores' extension method to register a development version.

So, I tried to implement the services as mentioned in this answer:

  • IProfileService
  • IResourceOwnerPasswordValidator

This is my ConfigureServices Method in Startup class:

            services.AddMvc();
            var identityBuilder = services.AddIdentityServer();
            identityBuilder.AddInMemoryScopes(identitySrvConfig.GetScopes());
            identityBuilder.AddInMemoryClients(identitySrvConfig.GetClients());
            identityBuilder.AddProfileService<ProfileService>();
            identityBuilder.Services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();

Taking into consideration that in my case the interface signature is different:

 public class ResourceOwnerPasswordValidator : IdentityServer4.Validation.IResourceOwnerPasswordValidator
{
    public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
    {
        throw new NotImplementedException();
    }
}

But I am still getting the same error, what is the problem?

Answer

Amit Kumar Shrivastava picture Amit Kumar Shrivastava · May 30, 2020

If you are applying custom Identity i.e

services.AddIdentity<AppUser, UserRole>(options => { options.User.RequireUniqueEmail = true; }).AddEntityFrameworkStores<AbcDbContext>();

then in

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

Comment

app.UseIdentityServer();

because we are using custom identity, not default