Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
- {
- var user = Users()
- .FirstOrDefault(x => x.Name == context.UserName
- && x.Password == context.Password);
- if (user == null)
- {
- context.SetError("invalid_grant",
- "Usuário não encontrado ou a senha está incorreta.");
- return;
- }
- var identyUser = new ClaimsIdentity(context.Options.AuthenticationType);
- identyUser.AddClaim(new Claim("sub", context.UserName));
- identyUser.AddClaim(new Claim(ClaimTypes.Role, "user"));
- context.Validated(identyUser);
- }
- public static IEnumerable<User> Users()
- {
- return new List<User>
- {
- new User { Name = "Marcelo", Password = "admin" },
- new User { Name = "Joao", Password = "12345" },
- };
- }
Add Comment
Please, Sign In to add comment