User.Identity.Name is null

At this time I am set claims like following line.

identity.AddClaim(new Claim("UserName", context.UserName));

I changed this to

using (AuthRepository _repo = new AuthRepository())
  IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

  if (user == null)
     context.SetError("invalid_grant", "The user name or password is incorrect.");
  ClaimsIdentity identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType);
  identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
  identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s