I am working with idsrv4 using your EF persistence 👍 .
I see this potential problem :
Idsrv4, inside AddIdentityServer always registers the InMemory transient stores
public static IServiceCollection AddInMemoryTransientStores(this IServiceCollection services) { services.TryAddSingleton<IAuthorizationCodeStore, InMemoryAuthorizationCodeStore>(); services.TryAddSingleton<IRefreshTokenStore, InMemoryRefreshTokenStore>(); services.TryAddSingleton<ITokenHandleStore, InMemoryTokenHandleStore>(); services.TryAddSingleton<IConsentStore, InMemoryConsentStore>(); return services; }
Then your code registers the EF based stores :
public EntityFrameworkOptions RegisterOperationalStores<TOperationalContext>() { _builder.Services.AddScoped<OperationalContext, TOperationalContext>(); _builder.Services.AddScoped<IAuthorizationCodeStore, AuthorizationCodeStore>(); _builder.Services.AddScoped<ITokenHandleStore, TokenHandleStore>(); _builder.Services.AddScoped<IConsentStore, ConsentStore>(); _builder.Services.AddScoped<IRefreshTokenStore, RefreshTokenStore>(); return this; }
So this stores are registered twice, once a singleton once in scoped mode. I am not sure what happens if the same Interface is registered twice.