public async void SignIn(User user) { Claim[] claims = new [] { new Claim(ClaimTypes.Name, string.Format("user{0}", user.Id)) }; ClaimsIdentity identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal principal = new ClaimsPrincipal(identity); await this.handler.Context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); }
public override Task GrantResourceOwnerCredentials(GrantResourceOwnerCredentialsContext context) { var user = new { Id = "users-123", UserName = "******", Password = "******" }; if (context.UserName != user.UserName || context.Password != user.Password) { context.Rejected("Invalid username or password."); return Task.FromResult(0); } var identity = new ClaimsIdentity(OpenIdConnectDefaults.AuthenticationScheme); identity.AddClaim(ClaimTypes.NameIdentifier, user.Id, "id_token token"); identity.AddClaim(ClaimTypes.Name, user.UserName, "id_token token"); context.Validated(new ClaimsPrincipal(identity)); return Task.FromResult(0); }