Guest User

Untitled

a guest
Mar 10th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. context.SetError("invalid_credentials", Newtonsoft.Json.JsonConvert.SerializeObject(new { result = false, message = "Please enter password !!!" }));
  2. }
  3. });
  4. }
  5. else
  6. {
  7. return Task.Factory.StartNew(() =>
  8. {
  9. var username = _userName;
  10. var password = _passWord;
  11. var userService = new UserServices();
  12. User user = userService.GetUserByCredentials(username, password);
  13. if (user != null && user.IsValid)
  14. {
  15. var claims = new List<Claim>()
  16. {
  17. new Claim(ClaimTypes.Name, user.Name),
  18. new Claim("UserID", user.Id)
  19. };
  20.  
  21. ClaimsIdentity oAutIdentity = new ClaimsIdentity(claims,
  22. Axmix.App_Start.Startup.OAuthOptions.AuthenticationType);
  23. context.Validated(new AuthenticationTicket(oAutIdentity, new AuthenticationProperties() { }));
  24. }
  25. else
  26. {
  27. context.SetError("invalid_grant", Newtonsoft.Json.JsonConvert.SerializeObject(new { result = false, message = "Invalid User Credentials !!!" }));
  28. }
  29. });
  30. }
  31. }
  32.  
  33.  
  34. public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
  35. {
  36. string clientId = string.Empty;
  37. string clientSecret = string.Empty;
  38.  
  39. if (!context.TryGetFormCredentials(out clientId, out clientSecret))
  40. {
  41. context.SetError("invalid_client", "Client credentials could not be retrieved through the Authorization header.");
  42. context.Rejected();
  43.  
  44. }
  45.  
  46.  
  47. if (!string.IsNullOrEmpty(clientId) && !string.IsNullOrEmpty(clientSecret))
  48. {
  49. context.Validated();
  50. _userName = clientId;
  51. _passWord = clientSecret;
  52. }
  53. else
  54. {
  55. context.Rejected();
  56. }
  57. //return Task.FromResult<object>(null);
  58. return base.ValidateClientAuthentication(context);
  59. }
Add Comment
Please, Sign In to add comment