public function BynderMediaApi::initiateOAuthTokenRetrieval in Bynder 7
File
- includes/
BynderMediaApi.inc, line 122 - Manages the Bynder media browser functionality
Class
Code
public function initiateOAuthTokenRetrieval() {
$settings = array(
'consumerKey' => variable_get('bynder_oauth_consumer', ''),
'consumerSecret' => variable_get('bynder_oauth_consumer_secret', ''),
'baseUrl' => variable_get('bynder_url', ''),
);
$this->bynderApi = BynderApiFactory::create($settings);
try {
$requestToken = $this->bynderApi
->getRequestToken()
->wait();
parse_str($requestToken, $tokenArray);
$token = $tokenArray['oauth_token'];
$tokenSecret = $tokenArray['oauth_token_secret'];
$_SESSION['bynder_data'] = array(
'oauth_token' => $token,
'oauth_token_secret' => $tokenSecret,
'isRequestToken' => true,
);
$query = array(
'oauth_token' => $token,
// Would be the url pointing to this script for example.
'callback' => url('bynder-oauth', array(
'absolute' => true,
)),
);
return url(variable_get('bynder_url') . '/api/v4/oauth/authorise', [
'query' => $query,
]);
} catch (Exception $e) {
watchdog('bynder', $e
->getMessage());
drupal_set_message(t('An error occurred while trying to login'), 'error');
return false;
}
}