public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>(); _customIdentityService = new CustomIdentityService(); ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } else { await _customIdentityService.UpdateLoginDate(Guid.Parse(user.Id)); } ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType); ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager, CookieAuthenticationDefaults.AuthenticationType); Guid userID = await _customIdentityService.UserID(Guid.Parse(user.Id)); oAuthIdentity.AddClaim(new Claim("userID", userID.ToString())); AuthenticationProperties properties = CreateProperties(user.UserName); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public void CustomIdentityService_GetNextIdentity_ValueIncrements() { int value1 = CustomIdentityService.GenerateNextIdentity(); int value2 = CustomIdentityService.GenerateNextIdentity(); int value3 = CustomIdentityService.GenerateNextIdentity(); Assert.AreNotEqual(value1, value2); Assert.AreNotEqual(value1, value3); Assert.AreNotEqual(value2, value3); }
/// <inheritdoc/> public int GenerateNextIdentity() => CustomIdentityService.GenerateNextIdentity();