Guest User

Untitled

a guest
May 18th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. POST /connect/token HTTP/1.1
  2. Authorization: Basic c2lsaWNvbjpGNjIxRjQ3MC05NzMxLTRBMjUtODBFRi02N0E2RjdDNUY0Qjg=
  3. Content-Type: application/x-www-form-urlencoded
  4. Host: localhost:44333
  5. Content-Length: 40
  6. Expect: 100-continue
  7. Connection: Keep-Alive
  8.  
  9. HTTP/1.1 100 Continue
  10.  
  11. grant_type=client_credentials&scope=api1HTTP/1.1 200 OK
  12. Cache-Control: no-store, no-cache, max-age=0, private
  13. Pragma: no-cache
  14. Content-Length: 91
  15. Content-Type: application/json; charset=utf-8
  16. Server: Microsoft-HTTPAPI/2.0
  17. Date: Fri, 17 Jul 2015 08:52:23 GMT
  18.  
  19. {"access_token":"c1cad8180e11deceb43bc1545c863695","expires_in":3600,"token_type":"Bearer"}
  20.  
  21. var clientId = "MyApp";
  22. var clientSecret = "MySecret";
  23.  
  24. // var authorizationBasic = $.base64.btoa(clientId + ':' + clientSecret);
  25. var authorizationBasic = window.btoa(clientId + ':' + clientSecret);
  26.  
  27. var request = new XMLHttpRequest();
  28. request.open('POST', oAuth.AuthorizationServer, true);
  29. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  30. request.setRequestHeader('Authorization', 'Basic ' + authorizationBasic);
  31. request.setRequestHeader('Accept', 'application/json');
  32. request.send("username=John&password=Smith&grant_type=password");
  33.  
  34. request.onreadystatechange = function () {
  35. if (request.readyState === 4) {
  36. alert(request.responseText);
  37. }
  38. };
  39.  
  40. var clientId = "MyApp";
  41. var clientSecret = "MySecret";
  42.  
  43. // var authorizationBasic = $.base64.btoa(clientId + ':' + clientSecret);
  44. var authorizationBasic = window.btoa(clientId + ':' + clientSecret);
  45.  
  46. $.ajax({
  47. type: 'POST',
  48. url: oAuth.AuthorizationServer,
  49. data: { username: 'John', password: 'Smith', grant_type: 'password' },
  50. dataType: "json",
  51. contentType: 'application/x-www-form-urlencoded; charset=utf-8',
  52. xhrFields: {
  53. withCredentials: true
  54. },
  55. // crossDomain: true,
  56. headers: {
  57. 'Authorization': 'Basic ' + authorizationBasic
  58. },
  59. //beforeSend: function (xhr) {
  60. //},
  61. success: function (result) {
  62. var token = result;
  63. },
  64. //complete: function (jqXHR, textStatus) {
  65. //},
  66. error: function (req, status, error) {
  67. alert(error);
  68. }
  69. });
Add Comment
Please, Sign In to add comment