You are here

public function Oauth::initializeToken in Entity Share 8.3

Helper function to initialize a token.

Parameters

\Drupal\entity_share_client\Entity\Remote $remote: The remote website for which authorization is needed.

array $credentials: Trial credentials.

Return value

\League\OAuth2\Client\Token\AccessTokenInterface A valid access token.

Throws

\League\OAuth2\Client\Provider\Exception\IdentityProviderException Exception thrown if the provider response contains errors.

2 calls to Oauth::initializeToken()
Oauth::initalizeToken in modules/entity_share_client/src/Plugin/ClientAuthorization/Oauth.php
Helper function to initialize a token.
Oauth::submitConfigurationForm in modules/entity_share_client/src/Plugin/ClientAuthorization/Oauth.php
Form submission handler.

File

modules/entity_share_client/src/Plugin/ClientAuthorization/Oauth.php, line 359

Class

Oauth
Provides Oauth2 based client authorization.

Namespace

Drupal\entity_share_client\Plugin\ClientAuthorization

Code

public function initializeToken(Remote $remote, array $credentials) {
  $oauth_client = $this
    ->getOauthClient($remote
    ->get('url'), $credentials);

  // Try to get an access token using the
  // resource owner password credentials grant.
  return $oauth_client
    ->getAccessToken('password', [
    'username' => $credentials['username'],
    'password' => $credentials['password'],
  ]);
}