Guest User

Untitled

a guest
Oct 4th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
  2. {
  3. var user = Users()
  4. .FirstOrDefault(x => x.Name == context.UserName
  5. && x.Password == context.Password);
  6.  
  7. if (user == null)
  8. {
  9. context.SetError("invalid_grant",
  10. "Usuário não encontrado ou a senha está incorreta.");
  11. return;
  12. }
  13.  
  14. var identyUser = new ClaimsIdentity(context.Options.AuthenticationType);
  15. identyUser.AddClaim(new Claim("sub", context.UserName));
  16. identyUser.AddClaim(new Claim(ClaimTypes.Role, "user"));
  17. context.Validated(identyUser);
  18. }
  19.  
  20. public static IEnumerable<User> Users()
  21. {
  22. return new List<User>
  23. {
  24. new User { Name = "Marcelo", Password = "admin" },
  25. new User { Name = "Joao", Password = "12345" },
  26.  
  27. };
  28. }
Add Comment
Please, Sign In to add comment