You are here

public function OpenIDConnectClientBase::authorize in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x src/Plugin/OpenIDConnectClientBase.php \Drupal\openid_connect\Plugin\OpenIDConnectClientBase::authorize()

Redirects the user to the authorization endpoint.

The authorization endpoint authenticates the user and returns them to the redirect_uri specified previously with an authorization code that can be exchanged for an access token.

Parameters

string $scope: Name of scope(s) that with user consent will provide access to otherwise restricted user data. Defaults to "openid email".

Return value

\Symfony\Component\HttpFoundation\Response A response object.

Overrides OpenIDConnectClientInterface::authorize

3 calls to OpenIDConnectClientBase::authorize()
OpenIDConnectFacebookClient::authorize in src/Plugin/OpenIDConnectClient/OpenIDConnectFacebookClient.php
Redirects the user to the authorization endpoint.
OpenIDConnectGithubClient::authorize in src/Plugin/OpenIDConnectClient/OpenIDConnectGithubClient.php
Redirects the user to the authorization endpoint.
OpenIDConnectLinkedinClient::authorize in src/Plugin/OpenIDConnectClient/OpenIDConnectLinkedinClient.php
Redirects the user to the authorization endpoint.
3 methods override OpenIDConnectClientBase::authorize()
OpenIDConnectFacebookClient::authorize in src/Plugin/OpenIDConnectClient/OpenIDConnectFacebookClient.php
Redirects the user to the authorization endpoint.
OpenIDConnectGithubClient::authorize in src/Plugin/OpenIDConnectClient/OpenIDConnectGithubClient.php
Redirects the user to the authorization endpoint.
OpenIDConnectLinkedinClient::authorize in src/Plugin/OpenIDConnectClient/OpenIDConnectLinkedinClient.php
Redirects the user to the authorization endpoint.

File

src/Plugin/OpenIDConnectClientBase.php, line 256

Class

OpenIDConnectClientBase
Base class for OpenID Connect client plugins.

Namespace

Drupal\openid_connect\Plugin

Code

public function authorize($scope = 'openid email') {
  $redirect_uri = $this
    ->getRedirectUrl()
    ->toString(TRUE);
  $url_options = $this
    ->getUrlOptions($scope, $redirect_uri);
  $endpoints = $this
    ->getEndpoints();

  // Clear _GET['destination'] because we need to override it.
  $this->requestStack
    ->getCurrentRequest()->query
    ->remove('destination');
  $authorization_endpoint = Url::fromUri($endpoints['authorization'], $url_options)
    ->toString(TRUE);
  $response = new TrustedRedirectResponse($authorization_endpoint
    ->getGeneratedUrl());

  // We can't cache the response, since this will prevent the state to be
  // added to the session. The kill switch will prevent the page getting
  // cached for anonymous users when page cache is active.
  $this->pageCacheKillSwitch
    ->trigger();
  return $response;
}