You are here

protected function OAuth2ControllerBase::checkAuthError in Social Auth 8.2

Same name and namespace in other branches
  1. 3.x src/Controller/OAuth2ControllerBase.php \Drupal\social_auth\Controller\OAuth2ControllerBase::checkAuthError()

Checks if there was an error during authentication with provider.

When there is an authentication problem in a provider (e.g. user did not authorize the app), a query to the client containing an error key is often returned. This method checks for such key, dispatches an event, and returns a redirect object where there is an authentication error.

Parameters

string $key: The query parameter key to check for authentication error.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse|null Redirect response object that may be returned by the controller or null.

File

src/Controller/OAuth2ControllerBase.php, line 285

Class

OAuth2ControllerBase
Handle responses for Social Auth implementer controllers.

Namespace

Drupal\social_auth\Controller

Code

protected function checkAuthError($key = 'error') {
  $request_query = $this->request
    ->getCurrentRequest()->query;

  // Checks if authentication failed.
  if ($request_query
    ->has($key)) {
    $this->messenger
      ->addError($this
      ->t('You could not be authenticated.'));
    $response = $this->userAuthenticator
      ->dispatchAuthenticationError($request_query
      ->get($key));
    if ($response) {
      return $response;
    }
    return $this
      ->redirect('user.login');
  }
  return NULL;
}