class SimpleOauthAuthenticationProvider in Simple OAuth (OAuth2) & OpenID Connect 8.2
Same name and namespace in other branches
- 8.4 src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider
- 8 src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider
- 8.3 src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider
- 5.x src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider
@internal
Hierarchy
- class \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider implements SimpleOauthAuthenticationProviderInterface
Expanded class hierarchy of SimpleOauthAuthenticationProvider
2 files declare their use of SimpleOauthAuthenticationProvider
- DisallowSimpleOauthRequests.php in src/
PageCache/ DisallowSimpleOauthRequests.php - SimpleOauthAuthenticationTest.php in tests/
src/ Unit/ Authentication/ Provider/ SimpleOauthAuthenticationTest.php
1 string reference to 'SimpleOauthAuthenticationProvider'
1 service uses SimpleOauthAuthenticationProvider
File
- src/
Authentication/ Provider/ SimpleOauthAuthenticationProvider.php, line 14
Namespace
Drupal\simple_oauth\Authentication\ProviderView source
class SimpleOauthAuthenticationProvider implements SimpleOauthAuthenticationProviderInterface {
/**
* @var \Drupal\simple_oauth\Server\ResourceServerInterface
*/
protected $resourceServer;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a HTTP basic authentication provider object.
*
* @param \Drupal\simple_oauth\Server\ResourceServerInterface $resource_server
* The resource server object.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(ResourceServerInterface $resource_server, EntityTypeManagerInterface $entity_type_manager) {
$this->resourceServer = $resource_server;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function applies(Request $request) {
// Check for the presence of the token.
return $this
->hasTokenValue($request);
}
/**
* {@inheritdoc}
*/
public static function hasTokenValue(Request $request) {
// Check the header. See: http://tools.ietf.org/html/rfc6750#section-2.1
$auth_header = trim($request->headers
->get('Authorization', '', TRUE));
return strpos($auth_header, 'Bearer ') !== FALSE;
}
/**
* {@inheritdoc}
*/
public function authenticate(Request $request) {
// Update the request with the OAuth information.
try {
$request = $this->resourceServer
->validateAuthenticatedRequest($request);
} catch (OAuthServerException $exception) {
// Procedural code here is hard to avoid.
watchdog_exception('simple_oauth', $exception);
return NULL;
}
$tokens = $this->entityTypeManager
->getStorage('oauth2_token')
->loadByProperties([
'value' => $request
->get('oauth_access_token_id'),
]);
$token = reset($tokens);
return new TokenAuthUser($token);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SimpleOauthAuthenticationProvider:: |
protected | property | ||
SimpleOauthAuthenticationProvider:: |
protected | property | ||
SimpleOauthAuthenticationProvider:: |
public | function |
Checks whether suitable authentication credentials are on the request. Overrides AuthenticationProviderInterface:: |
|
SimpleOauthAuthenticationProvider:: |
public | function |
Authenticates the user. Overrides AuthenticationProviderInterface:: |
|
SimpleOauthAuthenticationProvider:: |
public static | function |
Gets the access token from the request. Overrides SimpleOauthAuthenticationProviderInterface:: |
|
SimpleOauthAuthenticationProvider:: |
public | function | Constructs a HTTP basic authentication provider object. |