class AuthCodeAccessExample in OAuth2 Client 8.3
Auth code with access example.
Plugin annotation
@Oauth2Client(
id = "authcode_access_example",
name = @Translation("Example for code capture access override"),
grant_type = "authorization_code",
authorization_uri = "https://oauth.mocklab.io/oauth/authorize",
token_uri = "https://oauth.mocklab.io/oauth/token",
resource_owner_uri = "https://oauth.mocklab.io/userinfo",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\oauth2_client\Plugin\Oauth2Client\Oauth2ClientPluginBase implements Oauth2ClientPluginInterface uses ConfigFormBaseTrait
- class \Drupal\oauth2_client_example_plugins\Plugin\Oauth2Client\AuthCodeAccessExample implements Oauth2ClientPluginAccessInterface
- class \Drupal\oauth2_client\Plugin\Oauth2Client\Oauth2ClientPluginBase implements Oauth2ClientPluginInterface uses ConfigFormBaseTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of AuthCodeAccessExample
File
- examples/
oauth2_client_example_plugins/ src/ Plugin/ Oauth2Client/ AuthCodeAccessExample.php, line 24
Namespace
Drupal\oauth2_client_example_plugins\Plugin\Oauth2ClientView source
class AuthCodeAccessExample extends Oauth2ClientPluginBase implements Oauth2ClientPluginAccessInterface {
/**
* Access Token storage implementation.
*
* @var \Drupal\Core\TempStore\PrivateTempStore
*/
private $tempStore;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->tempStore = $container
->get('tempstore.private')
->get('authcode_private_temp_store_example');
return $instance;
}
/**
* {@inheritdoc}
*/
public function codeRouteAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermissions($account, [
'access content',
]);
}
/*
* This example assumes that a user is authenticating against a third-party
* service to retrieve a token that Drupal can use to access resources on
* that user's behalf.
*
*/
/**
* {@inheritdoc}
*/
public function storeAccessToken(AccessToken $accessToken) {
$key = 'oauth2_client_access_token-' . $this
->getId();
$this->tempStore
->set($key, $accessToken);
}
/**
* {@inheritdoc}
*/
public function retrieveAccessToken() {
$key = 'oauth2_client_access_token-' . $this
->getId();
return $this->tempStore
->get($key);
}
/**
* {@inheritdoc}
*/
public function clearAccessToken() {
$key = 'oauth2_client_access_token-' . $this
->getId();
return $this->tempStore
->delete($key);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthCodeAccessExample:: |
private | property | Access Token storage implementation. | |
AuthCodeAccessExample:: |
public | function |
Clears the access token from storage. Overrides Oauth2ClientPluginInterface:: |
|
AuthCodeAccessExample:: |
public | function |
Override the default access with this method. Overrides Oauth2ClientPluginAccessInterface:: |
|
AuthCodeAccessExample:: |
public static | function |
Creates an instance of the plugin. Overrides Oauth2ClientPluginBase:: |
|
AuthCodeAccessExample:: |
public | function |
Retrieve the access token storage. Overrides Oauth2ClientPluginInterface:: |
|
AuthCodeAccessExample:: |
public | function |
Stores access tokens obtained by this client. Overrides Oauth2ClientPluginInterface:: |
|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
Oauth2ClientPluginBase:: |
protected | property | The configuration factory. | |
Oauth2ClientPluginBase:: |
private | property | Storage for credentials retrieved from credential service. | |
Oauth2ClientPluginBase:: |
protected | property | Injected credential service. | |
Oauth2ClientPluginBase:: |
protected | property |
The messenger service. Overrides MessengerTrait:: |
|
Oauth2ClientPluginBase:: |
protected | property | The Drupal state api. | |
Oauth2ClientPluginBase:: |
protected | property | Injected UUID service. | |
Oauth2ClientPluginBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
Oauth2ClientPluginBase:: |
private | function | Check that a key is defined when requested. Throw an exception if not. | |
Oauth2ClientPluginBase:: |
private | function | Helper function to clear cached credentials. | |
Oauth2ClientPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Check the plugin definition for success_message or return a static value. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
protected | function | Helper method to build the credential provider elements of the form. | |
Oauth2ClientPluginBase:: |
public | function |
Retrieves the authorization_uri of the OAuth2 server. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the client_id of the OAuth2 server. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the client_secret of the OAuth2 server. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Returns the plugin credentials if they are set, otherwise returns NULL. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the grant type of the plugin. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the id of the OAuth2 Client plugin. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the human-readable name of the Oauth2 Client plugin. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the redirect_uri of the OAuth2 server. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the resource_uri of the OAuth2 server. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Get the set of scopes for the provider to use by default. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Get the separator used to join the scopes in the OAuth2 query string. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Returns the credential storage key if it is set, otherwise returns NULL. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Retrieves the token_uri of the OAuth2 server. Overrides Oauth2ClientPluginInterface:: |
|
Oauth2ClientPluginBase:: |
protected | function | Helper function to initialize the internal configuration array. | |
Oauth2ClientPluginBase:: |
private | function | Helper function to retrieve and cache credentials. | |
Oauth2ClientPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
Oauth2ClientPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
Oauth2ClientPluginBase:: |
final public | function |
Constructs a Oauth2ClientPluginBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |