Skip to content

Instantly share code, notes, and snippets.

@gregmercer
Last active December 22, 2015 11:28
Show Gist options
  • Save gregmercer/6465411 to your computer and use it in GitHub Desktop.
Save gregmercer/6465411 to your computer and use it in GitHub Desktop.
Example of a call to rest_helper to do OAuth2 Username-Password Flow, to obtain a token in an Autonomous Client.
/***********************************************************
function for fetching the rest login token
example of use:
$response = rest_login();
$instance_url = $response->instance_url;
$access_token = $response->access_token;
$response = rest_helper(
"< request url goes here >",
array(),
'GET',
'json',
"OAuth $access_token"
);
$data = json_decode($response,true);
code rest_helper can be found here:
https://gist.github.com/gregmercer/6465114
***********************************************************/
function rest_login() {
$grant_type = 'password';
$client_id = '<your client id goes here>';
$client_secret = '<your client secret goes here>';
$username = '<your username goes here>';
$password = '<your password goes here>';
$login_url = '<your oauth2 token url goes here>';
$response = rest_helper(
$login_url, array(
'grant_type' => $grant_type,
'client_id' => $client_id,
'client_secret' => $client_secret,
'username' => $username,
'password' => $password
),
'POST'
);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment