You are here

public function CredentialProvider::getCredentials in OAuth2 Client 8.3

Get the provided credentials.

Parameters

\Drupal\oauth2_client\Plugin\Oauth2Client\Oauth2ClientPluginInterface $plugin: An authorization plugin.

Return value

array|string The value of the configured key.

File

src/Service/CredentialProvider.php, line 70

Class

CredentialProvider
Class KeyProvider.

Namespace

Drupal\oauth2_client\Service

Code

public function getCredentials(Oauth2ClientPluginInterface $plugin) {
  $provider = $plugin
    ->getCredentialProvider();
  $credentials = [];
  if (empty($provider)) {
    return $credentials;
  }
  switch ($provider) {
    case 'key':
      $keyEntity = $this->keyRepository
        ->getKey($plugin
        ->getStorageKey());
      if ($keyEntity instanceof Key) {

        // A key was found in the repository.
        $credentials = $keyEntity
          ->getKeyValues();
      }
      break;
    default:
      $credentials = $this->state
        ->get($plugin
        ->getStorageKey());
  }
  return $credentials;
}