You are here

public function SimpleOauthAuthenticationProvider::authenticate in Simple OAuth (OAuth2) & OpenID Connect 8.2

Same name and namespace in other branches
  1. 8.4 src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider::authenticate()
  2. 8 src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider::authenticate()
  3. 8.3 src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider::authenticate()
  4. 5.x src/Authentication/Provider/SimpleOauthAuthenticationProvider.php \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider::authenticate()

Authenticates the user.

Parameters

\Symfony\Component\HttpFoundation\Request|null $request: The request object.

Return value

\Drupal\Core\Session\AccountInterface|null AccountInterface - in case of a successful authentication. NULL - in case where authentication failed.

Overrides AuthenticationProviderInterface::authenticate

File

src/Authentication/Provider/SimpleOauthAuthenticationProvider.php, line 60

Class

SimpleOauthAuthenticationProvider
@internal

Namespace

Drupal\simple_oauth\Authentication\Provider

Code

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);
}