class CredentialProvider in OAuth2 Client 8.3
Class KeyProvider.
@package Drupal\oauth2_client\Service
Hierarchy
- class \Drupal\oauth2_client\Service\CredentialProvider
Expanded class hierarchy of CredentialProvider
1 file declares its use of CredentialProvider
- Oauth2ClientPluginBase.php in src/
Plugin/ Oauth2Client/ Oauth2ClientPluginBase.php
1 string reference to 'CredentialProvider'
File
- src/
Service/ CredentialProvider.php, line 15
Namespace
Drupal\oauth2_client\ServiceView source
class CredentialProvider {
/**
* Key module service conditionally injected.
*
* @var \Drupal\key\KeyRepositoryInterface
*/
protected $keyRepository;
/**
* The Drupal state api.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* KeyService constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The key value store to use.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* Provides a means to our services.yml file to conditionally inject service.
*
* @param \Drupal\key\KeyRepositoryInterface $repository
* The injected service, if it exists.
*/
public function setKeyRepository(KeyRepositoryInterface $repository) {
$this->keyRepository = $repository;
}
/**
* Detects if key module service was injected.
*
* @return bool
* True if the KeyRepository is present.
*/
public function additionalProviders() {
return $this->keyRepository instanceof KeyRepositoryInterface;
}
/**
* Get the provided credentials.
*
* @param \Drupal\oauth2_client\Plugin\Oauth2Client\Oauth2ClientPluginInterface $plugin
* An authorization plugin.
*
* @return array|string
* The value of the configured key.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CredentialProvider:: |
protected | property | Key module service conditionally injected. | |
CredentialProvider:: |
protected | property | The Drupal state api. | |
CredentialProvider:: |
public | function | Detects if key module service was injected. | |
CredentialProvider:: |
public | function | Get the provided credentials. | |
CredentialProvider:: |
public | function | Provides a means to our services.yml file to conditionally inject service. | |
CredentialProvider:: |
public | function | KeyService constructor. |