Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Authorization: Basic [client_id]:[client_secret]
- Content-Type: application/x-www-form-urlencoded
- Authorization: Basic bXlfY2xpZW50X2lkOnBFUnkyTGhLYko0U2FkY3ZLcklpQW5xWnprakg5bm9STUc3aUxZcWl2MA==
- grant_type=password&scope=read write&username=[username]&password=[password]
- {
- "access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9(...)",
- "token_type":"Bearer",
- "expires_in":3600,
- "refresh_token":null
- }
- $api = "KEY GOES HERE";
- $authurl = "https://url.com/oauth/token";
- $client_id = "ID GOES HERE";
- $client_secret = "SECRET GOES HERE";
- // Creating base 64 encoded authkey
- $Auth_Key = $client_id.":".$client_secret;
- $encoded_Auth_Key=base64_encode($Auth_Key);
- $headers = array();
- $headers['Authorization'] = "Basic ".$encoded_Auth_Key;
- $headers['Content-Type'] = "application/x-www-form-urlencoded";
- $data = "grant_type=password&scope=read write&username=".$api."&password=".$api."";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $authurl);
- curl_setopt($ch, CURLOPT_POST, 1 );
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- $auth = curl_exec( $ch );
- if ( curl_errno( $ch ) ){
- echo 'Error: ' . curl_error( $ch );
- }
- curl_close($ch);
- $secret = json_decode($auth);
- $access_key = $secret->access_token;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement