You are here

public static function Oauth2AuthorizeController::redirectToCallback in Simple OAuth (OAuth2) & OpenID Connect 8.3

Generates a redirection response to the consumer callback.

Parameters

\League\OAuth2\Server\RequestTypes\AuthorizationRequest $auth_request: The auth request.

\League\OAuth2\Server\AuthorizationServer $server: The authorization server.

\Drupal\Core\Session\AccountInterface $current_user: The user to be logged in.

bool $can_grant_codes: Weather or not the user can grant codes.

bool $remembers_clients: Weather or not the sites remembers consumers that were previously granted access.

\Drupal\simple_oauth\KnownClientsRepositoryInterface|null $known_clients_repository: The known clients repository.

Return value

\Drupal\Core\Routing\TrustedRedirectResponse The response.

2 calls to Oauth2AuthorizeController::redirectToCallback()
Oauth2AuthorizeController::authorize in simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php
Authorizes the code generation or prints the confirmation form.
Oauth2AuthorizeForm::submitForm in simple_oauth_extras/src/Controller/Oauth2AuthorizeForm.php
Form submission handler.

File

simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php, line 214

Class

Oauth2AuthorizeController
Oauth2AuthorizeController.

Namespace

Drupal\simple_oauth_extras\Controller

Code

public static function redirectToCallback(AuthorizationRequest $auth_request, AuthorizationServer $server, AccountInterface $current_user, $can_grant_codes, $remembers_clients = FALSE, KnownClientsRepositoryInterface $known_clients_repository = NULL) {

  // Once the user has logged in set the user on the AuthorizationRequest.
  $user_entity = new UserEntity();
  $user_entity
    ->setIdentifier($current_user
    ->id());
  $auth_request
    ->setUser($user_entity);

  // Once the user has approved or denied the client update the status
  // (true = approved, false = denied).
  $auth_request
    ->setAuthorizationApproved($can_grant_codes);

  // Return the HTTP redirect response.
  $response = $server
    ->completeAuthorizationRequest($auth_request, new Response());

  // Remembers the choice for the current user.
  if ($remembers_clients) {
    $scopes = array_map(function (ScopeEntityInterface $scope) {
      return $scope
        ->getIdentifier();
    }, $auth_request
      ->getScopes());
    $known_clients_repository = $known_clients_repository instanceof KnownClientsRepositoryInterface ? $known_clients_repository : \Drupal::service('simple_oauth.known_clients');
    $known_clients_repository
      ->rememberClient($current_user
      ->id(), $auth_request
      ->getClient()
      ->getIdentifier(), $scopes);
  }

  // Get the location and return a secure redirect response.
  return TrustedRedirectResponse::create($response
    ->getHeaderLine('location'), $response
    ->getStatusCode(), $response
    ->getHeaders());
}