You are here

protected function OAuth2ControllerBase::checkAuthError in Social Post 3.x

Same name and namespace in other branches
  1. 8.2 src/Controller/OAuth2ControllerBase.php \Drupal\social_post\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 246

Class

OAuth2ControllerBase
Handle responses for Social Post implementer controllers.

Namespace

Drupal\social_post\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.'));
    return $this
      ->redirect('entity.user.edit_form', [
      'user' => $this->userAuthenticator
        ->currentUser()
        ->id(),
    ]);
  }
  return NULL;
}