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

InvalidOperationException when trying to do SignInAsync #1126

Closed
Lutando opened this issue Feb 15, 2017 · 2 comments
Closed

InvalidOperationException when trying to do SignInAsync #1126

Lutando opened this issue Feb 15, 2017 · 2 comments

Comments

@Lutando
Copy link

Lutando commented Feb 15, 2017

I am trying to sign a user in, in a normal controller. I have something along the lines of:

var claims = new List<Claim>
{
    new Claim(JwtClaimTypes.Subject, "xxx-xxx-xx-xxx),
    new Claim(JwtClaimTypes.PreferredUserName, "someusername"),
    new Claim(JwtClaimTypes.Email, "foo@bar"),
    new Claim(JwtClaimTypes.EmailVerified, "foo@bar:),
    new Claim(JwtClaimTypes.IdentityProvider, "idsvr"),
};

var ci = new ClaimsIdentity(claims, "password", JwtClaimTypes.PreferredUserName, JwtClaimTypes.Role);
var cp = new ClaimsPrincipal(ci);
await HttpContext.Authentication.SignInAsync("myscheme", cp);

And I get an exception saying InvalidOperationException: name claim is missing

In the constructor of the ClaimsIdentity I specified my name claim to be JwtClaimTypes.PreferredUsername (which is "preferred_username")

If I do add a name claim to my claims list, then sign in works fine with the above snippet. However we actually don't have name claims in our system. We want to use the "preferred_username" as the name claim in your abstractions.

@kevinchalet
Copy link
Contributor

InvalidOperationException: name claim is missing is not an exception thrown by the security stack.

It sounds like an IdSrv exception: https://github.com/IdentityServer/IdentityServer4/blob/dev/src/IdentityServer4/IdentityServerPrincipal.cs#L81

@Lutando
Copy link
Author

Lutando commented Feb 15, 2017

Thanks seems like it is, I could not find where this would be thrown. Thanks for the pointer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants