Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Authorization: Basic [client_id]:[client_secret]
  2. Content-Type: application/x-www-form-urlencoded
  3.  
  4. Authorization: Basic bXlfY2xpZW50X2lkOnBFUnkyTGhLYko0U2FkY3ZLcklpQW5xWnprakg5bm9STUc3aUxZcWl2MA==
  5.  
  6. grant_type=password&scope=read write&username=[username]&password=[password]
  7.  
  8. {
  9. "access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9(...)",
  10. "token_type":"Bearer",
  11. "expires_in":3600,
  12. "refresh_token":null
  13. }
  14.  
  15. $api = "KEY GOES HERE";
  16. $authurl = "https://url.com/oauth/token";
  17.  
  18. $client_id = "ID GOES HERE";
  19. $client_secret = "SECRET GOES HERE";
  20.  
  21. // Creating base 64 encoded authkey
  22. $Auth_Key = $client_id.":".$client_secret;
  23. $encoded_Auth_Key=base64_encode($Auth_Key);
  24.  
  25. $headers = array();
  26. $headers['Authorization'] = "Basic ".$encoded_Auth_Key;
  27. $headers['Content-Type'] = "application/x-www-form-urlencoded";
  28.  
  29. $data = "grant_type=password&scope=read write&username=".$api."&password=".$api."";
  30.  
  31. $ch = curl_init();
  32. curl_setopt($ch, CURLOPT_URL, $authurl);
  33. curl_setopt($ch, CURLOPT_POST, 1 );
  34. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  36. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  37. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  38.  
  39. $auth = curl_exec( $ch );
  40.  
  41. if ( curl_errno( $ch ) ){
  42. echo 'Error: ' . curl_error( $ch );
  43. }
  44. curl_close($ch);
  45.  
  46. $secret = json_decode($auth);
  47. $access_key = $secret->access_token;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement