You are here

public function OpenIDConnectClientBase::retrieveUserInfo 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::retrieveUserInfo()

Retrieves user info: additional user profile data.

Parameters

string $access_token: Access token.

Return value

array|bool User profile information array, or FALSE if retrieval failed.

Overrides OpenIDConnectClientInterface::retrieveUserInfo

2 calls to OpenIDConnectClientBase::retrieveUserInfo()
OpenIDConnectGoogleClient::retrieveUserInfo in src/Plugin/OpenIDConnectClient/OpenIDConnectGoogleClient.php
Retrieves user info: additional user profile data.
OpenIDConnectLinkedinClient::retrieveUserInfo in src/Plugin/OpenIDConnectClient/OpenIDConnectLinkedinClient.php
Retrieves user info: additional user profile data.
4 methods override OpenIDConnectClientBase::retrieveUserInfo()
OpenIDConnectFacebookClient::retrieveUserInfo in src/Plugin/OpenIDConnectClient/OpenIDConnectFacebookClient.php
Implements OpenIDConnectClientInterface::retrieveUserInfo().
OpenIDConnectGithubClient::retrieveUserInfo in src/Plugin/OpenIDConnectClient/OpenIDConnectGithubClient.php
Retrieves user info: additional user profile data.
OpenIDConnectGoogleClient::retrieveUserInfo in src/Plugin/OpenIDConnectClient/OpenIDConnectGoogleClient.php
Retrieves user info: additional user profile data.
OpenIDConnectLinkedinClient::retrieveUserInfo in src/Plugin/OpenIDConnectClient/OpenIDConnectLinkedinClient.php
Retrieves user info: additional user profile data.

File

src/Plugin/OpenIDConnectClientBase.php, line 380

Class

OpenIDConnectClientBase
Base class for OpenID Connect client plugins.

Namespace

Drupal\openid_connect\Plugin

Code

public function retrieveUserInfo($access_token) {
  $request_options = [
    'headers' => [
      'Authorization' => 'Bearer ' . $access_token,
      'Accept' => 'application/json',
    ],
  ];
  $endpoints = $this
    ->getEndpoints();
  $client = $this->httpClient;
  try {
    $response = $client
      ->get($endpoints['userinfo'], $request_options);
    $response_data = (string) $response
      ->getBody();
    return json_decode($response_data, TRUE);
  } catch (\Exception $e) {
    $variables = [
      '@message' => 'Could not retrieve user profile information',
      '@error_message' => $e
        ->getMessage(),
    ];
    if ($e instanceof RequestException && $e
      ->hasResponse()) {
      $response_body = $e
        ->getResponse()
        ->getBody()
        ->getContents();
      $variables['@error_message'] .= ' Response: ' . $response_body;
    }
    $this->loggerFactory
      ->get('openid_connect_' . $this->pluginId)
      ->error('@message. Details: @error_message', $variables);
    return FALSE;
  }
}