Identityserver4: 2.0.0rc1 - InvalidOperationException: sub claim is missing

Created on 20 Sep 2017  路  4Comments  路  Source: IdentityServer/IdentityServer4

After upgrading to 2.0.0rc1 I get this while trying to log in:

InvalidOperationException: sub claim is missing

Code is not changed just settings.

All I did was to remove app.UseIdentity() and replaced with app.AddAuthentication();
Same thing in Configure method in Startup.cs.

Application version: 1.0.0.0
AspNetCoreEnvironment: Development
Client IP address: 127.0.0.1
DeveloperMode: true
Event time: 20/09/2017 18:59:30
Exception type: System.InvalidOperationException
handledAt: Platform
Message: sub claim is missing
Node name: DESKTOP-NOBHIJ3
Operation ID: e48aaa36-41282e80d87e671d
Operation name: POST Account/Login
Operation parent ID: |e48aaa36-41282e80d87e671d.
Problem ID: System.InvalidOperationException at IdentityServer4.IdentityServerPrincipal.AssertRequiredClaims
Role instance: DESKTOP-NOBHIJ3
SDK version: aspnet5c:2.1.1
Session ID: vG4WH
User ID: UJE4K

Stack Trace
System.InvalidOperationException: sub claim is missing
at IdentityServer4.IdentityServerPrincipal.AssertRequiredClaims
at IdentityServer4.Hosting.IdentityServerAuthenticationService.AugmentPrincipal
at IdentityServer4.Hosting.IdentityServerAuthenticationService+d__7.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Identity.SignInManager1+<SignInAsync>d__30.MoveNext at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification at Microsoft.AspNetCore.Identity.SignInManager1+d__52.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult at Microsoft.AspNetCore.Identity.SignInManager1+d__33.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult at Microsoft.AspNetCore.Identity.SignInManager1+d__34.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult at IdentityServerWithAspNetIdentity.Controllers.AccountController+<Login>d__10.MoveNext at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification at System.Runtime.CompilerServices.TaskAwaiter1.GetResult
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__12.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__10.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__14.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__22.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__17.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__15.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__6.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at IdentityServer4.Hosting.IdentityServerMiddleware+d__4.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__6.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware+d__7.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at IdentityServer4.Hosting.BaseUrlMiddleware+d__3.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware+d__7.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext

question

Most helpful comment

Find this line in Startup.cs confgiureservices

services.AddIdentity()
.AddEntityFrameworkStores()
.AddIdentityServer()
.AddDefaultTokenProviders();

make sure .AddIdentityServer() is there. That's what solved it for me

All 4 comments

If it is an existing account in your AspNetIdentities tables, then add "sub" and "name" claims into the AspNetClaims table and you should be good.

Find this line in Startup.cs confgiureservices

services.AddIdentity()
.AddEntityFrameworkStores()
.AddIdentityServer()
.AddDefaultTokenProviders();

make sure .AddIdentityServer() is there. That's what solved it for me

@mrf460 that was the thing. I forgot to add AddIdentityServer().

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisrestall picture chrisrestall  路  3Comments

leastprivilege picture leastprivilege  路  3Comments

eshorgan picture eshorgan  路  3Comments

not-good-with-usernames picture not-good-with-usernames  路  3Comments

krgm03 picture krgm03  路  3Comments