IdentityServer4 Post Migration from 2.2.0 to 2.3.2
I migrated from netcore 2.1 to netcore 2.2 and migrated IdentityServer4 from 2.2.0 to 2.3.2.
After make command for migration I receive this exception and I can't login. This excepion is from Identity Server Log…. but look after this exception
2019-01-30 14:24:30.728 +01:00 [WRN] Using an in-memory repository. Keys will not be persisted to storage. 2019-01-30 14:24:30.751 +01:00 [WRN] Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits. 2019-01-30 14:24:30.766 +01:00 [WRN] No XML encryptor configured. Key "7309429e-0256-471d-9ec5-04c605f2703a" may be persisted to storage in unencrypted form. 2019-01-30 14:24:31.337 +01:00 [INF] Starting IdentityServer4 version 2.3.2.0 2019-01-30 14:24:31.358 +01:00 [INF] Using the default authentication scheme KSMWeb for IdentityServer 2019-01-30 14:24:31.358 +01:00 [DBG] Using KSMWeb as default ASP.NET Core scheme for authentication 2019-01-30 14:24:31.359 +01:00 [DBG] Using KSMWeb as default ASP.NET Core scheme for sign-in 2019-01-30 14:24:31.359 +01:00 [DBG] Using KSMWeb as default ASP.NET Core scheme for sign-out 2019-01-30 14:24:31.359 +01:00 [DBG] Using KSMWeb as default ASP.NET Core scheme for challenge 2019-01-30 14:24:31.359 +01:00 [DBG] Using KSMWeb as default ASP.NET Core scheme for forbid 2019-01-30 14:24:31.372 +01:00 [DBG] Starting grant removal 2019-01-30 14:24:31.414 +01:00 [DBG] Login Url: /Account/Login 2019-01-30 14:24:31.416 +01:00 [DBG] Login Return Url Parameter: ReturnUrl 2019-01-30 14:24:31.416 +01:00 [DBG] Logout Url: /Account/Logout 2019-01-30 14:24:31.416 +01:00 [DBG] ConsentUrl Url: /consent 2019-01-30 14:24:31.416 +01:00 [DBG] Consent Return Url Parameter: returnUrl 2019-01-30 14:24:31.416 +01:00 [DBG] Error Url: /home/error 2019-01-30 14:24:31.416 +01:00 [DBG] Error Id Parameter: errorId 2019-01-30 14:24:31.441 +01:00 [DBG] Request path /connect/token matched to endpoint type Token 2019-01-30 14:24:31.451 +01:00 [DBG] Endpoint enabled: Token, successfully created handler: IdentityServer4.Endpoints.TokenEndpoint 2019-01-30 14:24:31.451 +01:00 [INF] Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token 2019-01-30 14:24:31.459 +01:00 [DBG] Start token request. 2019-01-30 14:24:31.465 +01:00 [DBG] Start client validation 2019-01-30 14:24:31.470 +01:00 [DBG] Start parsing Basic Authentication secret 2019-01-30 14:24:31.471 +01:00 [DBG] Parser found secret: BasicAuthenticationSecretParser 2019-01-30 14:24:31.471 +01:00 [DBG] Secret id found: KSMWeb 2019-01-30 14:24:32.082 +01:00 [DBG] KSMWeb found in database: true 2019-01-30 14:24:32.087 +01:00 [DBG] client configuration validation for client KSMWeb succeeded. 2019-01-30 14:24:32.099 +01:00 [DBG] Secret validator success: HashedSharedSecretValidator 2019-01-30 14:24:32.099 +01:00 [DBG] Client validation success 2019-01-30 14:24:32.126 +01:00 [DBG] Start token request validation 2019-01-30 14:24:32.133 +01:00 [DBG] Start client credentials token request validation 2019-01-30 14:24:32.187 +01:00 [DBG] Found [] identity scopes in database 2019-01-30 14:24:32.442 +01:00 [DBG] Found ["KSMApi.Read","KSMApi.Write"] API scopes in database 2019-01-30 14:24:32.458 +01:00 [DBG] Found [] identity scopes in database 2019-01-30 14:24:32.461 +01:00 [DBG] Found ["KSMApi.Read","KSMApi.Write"] API scopes in database 2019-01-30 14:24:32.464 +01:00 [DBG] KSMWeb credentials token request validation success 2019-01-30 14:24:32.474 +01:00 [INF] Token request validation success {"ClientId":"KSMWeb","ClientName":"KSMApi","GrantType":"client_credentials","Scopes":"KSMApi.Read KSMApi.Write","AuthorizationCode":null,"RefreshToken":null,"UserName":null,"AuthenticationContextReferenceClasses":null,"Tenant":null,"IdP":null,"Raw":{"grant_type":"client_credentials"},"$type":"TokenRequestValidationLog"} 2019-01-30 14:24:32.499 +01:00 [DBG] Getting claims for access token for client: KSMWeb 2019-01-30 14:24:32.533 +01:00 [FTL] Unhandled exception: No signing credential is configured. Can't create JWT token System.InvalidOperationException: No signing credential is configured. Can't create JWT token at IdentityServer4.Services.DefaultTokenCreationService.CreateHeaderAsync(Token token) at IdentityServer4.Services.DefaultTokenCreationService.CreateTokenAsync(Token token) at IdentityServer4.Services.DefaultTokenService.CreateSecurityTokenAsync(Token token) at IdentityServer4.ResponseHandling.TokenResponseGenerator.CreateAccessTokenAsync(ValidatedTokenRequest request) at IdentityServer4.ResponseHandling.TokenResponseGenerator.ProcessTokenRequestAsync(TokenRequestValidationResult validationResult) at IdentityServer4.ResponseHandling.TokenResponseGenerator.ProcessAsync(TokenRequestValidationResult request) at IdentityServer4.Endpoints.TokenEndpoint.ProcessTokenRequestAsync(HttpContext context) at IdentityServer4.Endpoints.TokenEndpoint.ProcessAsync(HttpContext context) at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) 2019-01-30 14:24:32.534 +01:00 [ERR] An unhandled exception has occurred while executing the request. System.InvalidOperationException: No signing credential is configured. Can't create JWT token at IdentityServer4.Services.DefaultTokenCreationService.CreateHeaderAsync(Token token) at IdentityServer4.Services.DefaultTokenCreationService.CreateTokenAsync(Token token) at IdentityServer4.Services.DefaultTokenService.CreateSecurityTokenAsync(Token token) at IdentityServer4.ResponseHandling.TokenResponseGenerator.CreateAccessTokenAsync(ValidatedTokenRequest request) at IdentityServer4.ResponseHandling.TokenResponseGenerator.ProcessTokenRequestAsync(TokenRequestValidationResult validationResult) at IdentityServer4.ResponseHandling.TokenResponseGenerator.ProcessAsync(TokenRequestValidationResult request) at IdentityServer4.Endpoints.TokenEndpoint.ProcessTokenRequestAsync(HttpContext context) at IdentityServer4.Endpoints.TokenEndpoint.ProcessAsync(HttpContext context) at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
After this exception I look around and I find that I have to put in startup.cs
.AddSigningCredential("CN=*.krono.com", StoreLocation.LocalMachine, nameType: NameType.SubjectDistinguishedName)
and I put and reload the project and now the error is
2019-01-30 15:13:55.342 +01:00 [WRN] Using an in-memory repository. Keys will not be persisted to storage. 2019-01-30 15:13:55.367 +01:00 [WRN] Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits. 2019-01-30 15:13:55.379 +01:00 [WRN] No XML encryptor configured. Key "ea613780-e6a0-430c-8719-de2f21ffd049" may be persisted to storage in unencrypted form. 2019-01-30 15:13:55.438 +01:00 [INF] Starting IdentityServer4 version 2.3.2.0 2019-01-30 15:13:55.439 +01:00 [FTL] No storage mechanism for clients specified. Use the 'AddInMemoryClients' extension method to register a development version. 2019-01-30 15:18:18.774 +01:00 [WRN] Using an in-memory repository. Keys will not be persisted to storage. 2019-01-30 15:18:18.799 +01:00 [WRN] Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits. 2019-01-30 15:18:18.813 +01:00 [WRN] No XML encryptor configured. Key "d87ff639-9262-41de-ba92-cb5f47c29a08" may be persisted to storage in unencrypted form. 2019-01-30 15:18:18.874 +01:00 [INF] Starting IdentityServer4 version 2.3.2.0 2019-01-30 15:18:18.875 +01:00 [FTL] No storage mechanism for clients specified. Use the 'AddInMemoryClients' extension method to register a development version.
in Identity Server I insert a try catch and in my log file tell me
'*.krono.com' not found in certificate store but it is in store in right place! and then tell me
No service for type 'IdentityServer4.EntityFramework.DbContexts.PersistedGrantDbContext' has been registered.
No storage mechanism for clients specified. Use the 'AddInMemoryClients' extension method to register a development version.
What I have to do? what I 'm missing?
Is your feature request related to a problem? Please describe. Describe the solution you'd like Describe alternatives you've considered
there are many problem to pass from 2.2.0 Identity and 2.3.2 for example Access to the path 'C:\WINDOWS\SysWOW64\inetsrv\tempkey.rsa' is denied.
Looks like you switched to in-process hosting in ASP.NET Core 2.2
No, the problem is not-in process, because I have a webapi application without IdentityServer4 and I did the migration from 2.1 to 2.2 without problem.
Now after 7 days of concussions I managed to solve!
there were several things that had to be changed:
put
it was difficult to find everything else, starting from how to create a log file for Identity: Install these package in Identity Project using Serilog; using Serilog.Events; using Serilog.Sinks.SystemConsole.Themes;
Put in Program of Identity Project these rows:
Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("System", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.File(@"C:\URBACOLOG\myPath.txt") .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate) .CreateLogger(); CreateWebHostBuilder(args).Build().Run();
After I found that IdentityDB need to be modify… and then in Data->Migration-> ..->ConfigurationDB folder (Project Identity), delete all files contained in folder, then open CMD go to path of IdentityProject and launch: dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
then go in Data-> MIgration-> ..->PersistentGrantDB delete all file and go to CMD and lanch
dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
Then Delete the old Database.
Put Try Catch in Database.cs and in Startup. and Config of IdentityServer…
And Then I found that I have to change startup.cs of Identity in this way:
services.Configure
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
string connectionString = Configuration.GetConnectionString("DefaultConnection");
Cls_Log.Log(connectionString);
//services.AddIdentityServer()
services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<PersistedGrantDbContext>().AddDefaultTokenProviders();
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryPersistedGrants()
.AddInMemoryIdentityResources(KSMConfig.GetResources())
.AddInMemoryApiResources(KSMConfig.GetApiResources())
.AddInMemoryClients(KSMConfig.GetClients())
.AddAspNetIdentity<IdentityUser>()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 30;
});
services.AddAuthentication("KSMWeb")
.AddCookie("KSMWeb", options =>
{
options.Cookie.Name = "KSMWeb";
});
After I discovered that in C:\Windows\System32\inetsrv the tempkey.rsa doen't exist go put a copy in this path, and now go! But …. O.O
All of that code you're describing is not in IdentityServer itself, and rather code you used from a sample of how you might host IdentityServer.
I solve
https://stackoverflow.com/questions/54480504/migration-from-dotnetcore2-1-to-dotnetcore-2-2-and-identityserver4-2-2-0-to-2-3
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.