You are here

public function BynderApi::initiateOAuthTokenRetrieval in Bynder 4.0.x

Same name and namespace in other branches
  1. 8.3 src/BynderApi.php \Drupal\bynder\BynderApi::initiateOAuthTokenRetrieval()
  2. 8 src/BynderApi.php \Drupal\bynder\BynderApi::initiateOAuthTokenRetrieval()
  3. 8.2 src/BynderApi.php \Drupal\bynder\BynderApi::initiateOAuthTokenRetrieval()

Initiates the access token retrieval.

Gets request token from Bynder and prepares everything to redirect user to Bynder for login.

Return value

\Drupal\Core\Url Url to redirect the user to.

Overrides BynderApiInterface::initiateOAuthTokenRetrieval

See also

::finishOAuthTokenRetrieval()

File

src/BynderApi.php, line 171

Class

BynderApi
Bynder API service.

Namespace

Drupal\bynder

Code

public function initiateOAuthTokenRetrieval() {
  $bynder_settings = $this->configFactory
    ->get('bynder.settings');
  if (!$bynder_settings
    ->get('client_id') || !$bynder_settings
    ->get('client_secret')) {
    throw new \Exception('Client ID or secret configuration missing');
  }
  $query = [
    'client_id' => $bynder_settings
      ->get('client_id'),
    'redirect_uri' => $this
      ->getCallback(),
    'scope' => 'offline asset:read asset:write asset.usage:read asset.usage:write current.user:read current.profile:read',
    'response_type' => 'code',
    'state' => 'state',
  ];
  return Url::fromUri('https://' . $bynder_settings
    ->get('account_domain') . '/v6/authentication/oauth2/auth', array(
    'query' => $query,
    'auth' => null,
    'allow_redirects' => false,
  ));
}