class BasicAuth in Entity Share 8.3
Provides Basic Auth based client authorization.
Plugin annotation
@ClientAuthorization(
id = "basic_auth",
label = @Translation("Basic Auth"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\entity_share_client\ClientAuthorization\ClientAuthorizationPluginBase implements ContainerFactoryPluginInterface, ClientAuthorizationInterface
- class \Drupal\entity_share_client\Plugin\ClientAuthorization\BasicAuth
- class \Drupal\entity_share_client\ClientAuthorization\ClientAuthorizationPluginBase implements ContainerFactoryPluginInterface, ClientAuthorizationInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of BasicAuth
File
- modules/
entity_share_client/ src/ Plugin/ ClientAuthorization/ BasicAuth.php, line 18
Namespace
Drupal\entity_share_client\Plugin\ClientAuthorizationView source
class BasicAuth extends ClientAuthorizationPluginBase {
/**
* {@inheritdoc}
*/
public function checkIfAvailable() {
// Basic Auth is a core module which any server can enable.
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getClient($url) {
$credentials = $this->keyService
->getCredentials($this);
$http_client = $this->httpClientFactory
->fromOptions([
'base_uri' => $url . '/',
'cookies' => TRUE,
'allow_redirects' => TRUE,
]);
$http_client
->post('/user/login', [
'form_params' => [
'name' => $credentials['username'],
'pass' => $credentials['password'],
'form_id' => 'user_login_form',
],
]);
return $http_client;
}
/**
* {@inheritdoc}
*/
public function getJsonApiClient($url) {
$credentials = $this->keyService
->getCredentials($this);
return $this->httpClientFactory
->fromOptions([
'base_uri' => $url . '/',
'auth' => [
$credentials['username'],
$credentials['password'],
],
'headers' => [
'Content-type' => 'application/vnd.api+json',
],
]);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$credentials = $this->keyService
->getCredentials($this);
$form['entity_share']['username'] = [
'#type' => 'textfield',
'#required' => FALSE,
'#title' => $this
->t('Username'),
'#default_value' => $credentials['username'] ?? '',
];
$form['entity_share']['password'] = [
'#type' => 'password',
'#required' => FALSE,
'#title' => $this
->t('Password'),
'#default_value' => $credentials['password'] ?? '',
];
if ($this->keyService
->additionalProviders()) {
$this
->expandedProviderOptions($form);
$form['key']['id']['#key_filters'] = [
'type' => 'entity_share_basic_auth',
];
$form['key']['id']['#description'] = $this
->t('Select the key you have configured to hold the Basic Auth credentials.');
}
$form['warning_message'] = [
'#theme' => 'status_messages',
'#message_list' => [
'warning' => [
$this
->t('With the Basic Auth authorization method you need to ensure that the %module_name module is enabled on the server website.', [
'%module_name' => $this
->t('HTTP Basic Authentication'),
]),
],
],
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BasicAuth:: |
public | function |
Form constructor. Overrides ClientAuthorizationPluginBase:: |
|
BasicAuth:: |
public | function |
Returns true if the plugin method is supported. Overrides ClientAuthorizationInterface:: |
|
BasicAuth:: |
public | function |
Prepares a guzzle client for http operations with the supported auth. Overrides ClientAuthorizationInterface:: |
|
BasicAuth:: |
public | function |
Prepares a guzzle client for JSON operations with the supported auth. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationInterface:: |
constant | The collection ID of for authorization config local storage. | ||
ClientAuthorizationPluginBase:: |
protected | property | Injected HTTP client factory. | |
ClientAuthorizationPluginBase:: |
protected | property | Injected key service. | |
ClientAuthorizationPluginBase:: |
protected | property | The key value store to use. | |
ClientAuthorizationPluginBase:: |
protected | property | Injected UUID service. | |
ClientAuthorizationPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
ClientAuthorizationPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
ClientAuthorizationPluginBase:: |
protected | function | Helper method to build the credential provider elements of the form. | |
ClientAuthorizationPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Returns the plugin data if it is set, otherwise returns NULL. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Gets the plugin label. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Returns the plugin data if it is set, otherwise returns NULL. Overrides ClientAuthorizationInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ClientAuthorizationPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
ClientAuthorizationPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
ClientAuthorizationPluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. |