You are here

public function BynderMediaApi::finishOAuthTokenRetrieval in Bynder 7

File

includes/BynderMediaApi.inc, line 201
Manages the Bynder media browser functionality

Class

BynderMediaApi

Code

public function finishOAuthTokenRetrieval() {
  $tokens = $this
    ->hasAccessToken();
  if ($tokens && isset($tokens['isRequestToken'])) {
    unset($tokens['isRequestToken']);
    $settings = array(
      'consumerKey' => variable_get('bynder_oauth_consumer', ''),
      'consumerSecret' => variable_get('bynder_oauth_consumer_secret', ''),
      'token' => $tokens['oauth_token'],
      'tokenSecret' => $tokens['oauth_token_secret'],
      'baseUrl' => variable_get('bynder_url', ''),
    );
    $bynder_api = BynderApiFactory::create($settings);
    foreach ($bynder_api
      ->getAccessToken()
      ->wait() as $key => $token) {
      $tokens[$key] = $token;
    }
    $_SESSION['bynder_data'] = $tokens;
  }
  else {
    drupal_set_message(t('Could not finish login, please try again'), 'error');
  }
}