Guest User

Untitled

a guest
Feb 5th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
  2. {
  3. AccountLogin LogCredentials = new AccountLogin();
  4. LogCredentials.UserName = context.UserName;
  5. LogCredentials.Password = context.Password;
  6. LogCredentials.IPAddress = "::1";
  7.  
  8. string webHost = Convert.ToString(WebConfigurationManager.AppSettings["webHost"]);
  9. context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { webHost });
  10.  
  11. ProviderLoginResponse providerLoginResponse = MembershipService.UserLogin(LogCredentials);
  12. if (providerLoginResponse.LoginStatus != "Y")
  13. {
  14. context.SetError("invalid_grant", "The user name or password is incorrect.");
  15. return Task.FromResult<object>(null);
  16. }
  17.  
  18. var claims = new List<Claim>()
  19. {
  20. new Claim(ClaimTypes.Sid, Convert.ToString(providerLoginResponse.UserID)),
  21. new Claim(ClaimTypes.Name, providerLoginResponse.UserName),
  22. new Claim(ClaimTypes.Email, providerLoginResponse.UserEmail)
  23. };
  24.  
  25. ClaimsIdentity oAuthIdentity = new ClaimsIdentity(claims,
  26. Startup.OAuthOptions.AuthenticationType);
  27.  
  28. AuthenticationProperties properties = CreateProperties(providerLoginResponse);
  29.  
  30. AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
  31. context.Validated(ticket);
  32. return Task.FromResult<object>(null);
  33. }
  34.  
  35. [HttpGet]`
  36. [Route("GetColumn")]
  37. public HttpResponseMessage GetColumn(HttpRequestMessage request)
  38. {
  39. string tableName = "";
  40. HttpResponseMessage response = null;
  41. try
  42. {
  43. var clientList = _settingsService.GetColumns(tableName);
  44. response = request.CreateResponse(HttpStatusCode.OK, new APIResponse { Status = true, Data = clientList, Message = Messages.Saved_Success });
  45. }
  46. catch (Exception ex)
  47. {
  48. response = request.CreateResponse(HttpStatusCode.OK, new APIResponse { Status = false, Data = null, Message = ex.Message });
  49. }
  50. return response;
  51. }`
  52.  
  53. function GetColumn(data, cb) {
  54. var token = sessionStorage.getItem('accessToken');
  55.  
  56. var headers = {};
  57. if (token) {
  58. headers.Authorization = 'Bearer ' + token;
  59. }
  60.  
  61. $.ajax({
  62. type: 'GET',
  63. url: "api/Settings/GetColumn",
  64. headers: headers
  65. }).done(function (data) {
  66. cb(data);
  67. }).fail(function (Res) {
  68. cb(Res);
  69. });
  70. };
Add Comment
Please, Sign In to add comment