Guest User

Untitled

a guest
Mar 21st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
  2. {
  3. //here you get the context.UserName and context.Password
  4. // and validates the user
  5. }
  6.  
  7. $.ajax({
  8. type: 'POST',
  9. url: Helper.ApiUrl() + '/token',
  10. data: { grant_type: 'password', username: UserName, password: Password },
  11. success: function (result) {
  12. Helper.TokenKey(result.access_token);
  13. Helper.UserName(result.userName);
  14. },
  15. error: function (result) {
  16. Helper.HandleError(result);
  17. }
  18. });
  19.  
  20. data: { grant_type: 'password', username: UserName, password: Password, customer: Customer }
  21.  
  22. //here you get the context.UserName, context.Password and context.Customer
  23.  
  24. var customer = context.Parameters.FirstOrDefault(x => x.Key == "customer").ToString()).Value;
  25.  
  26. public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
  27. {
  28. //here you read all the params
  29. var data = await context.Request.ReadFormAsync();
  30. //here you get the param you want
  31. var param = data.Where(x => x.Key == "CustomParam").Select(x => x.Value).FirstOrDefault();
  32. string customer = "";
  33. if (param != null && param.Length > 0)
  34. {
  35. customer = param[0];
  36. }
  37.  
  38. }
  39.  
  40. data: { grant_type: 'password', username: user, password: pwd, CustomParam: 'MyParam' },
Add Comment
Please, Sign In to add comment