You are here

public function OpenIDConnectGoogleClient::retrieveUserInfo in OpenID Connect / OAuth client 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/OpenIDConnectClient/OpenIDConnectGoogleClient.php \Drupal\openid_connect\Plugin\OpenIDConnectClient\OpenIDConnectGoogleClient::retrieveUserInfo()

Retrieves user info: additional user profile data.

Parameters

string $access_token: Access token.

Return value

array|null Additional user profile information or NULL on failure.

Overrides OpenIDConnectClientBase::retrieveUserInfo

File

src/Plugin/OpenIDConnectClient/OpenIDConnectGoogleClient.php, line 49

Class

OpenIDConnectGoogleClient
Google OpenID Connect client.

Namespace

Drupal\openid_connect\Plugin\OpenIDConnectClient

Code

public function retrieveUserInfo(string $access_token = NULL) : ?array {
  $userinfo = parent::retrieveUserInfo($access_token);
  if ($userinfo) {

    // For some reason Google returns the URI of the profile picture in a
    // weird format: "https:" appears twice in the beginning of the URI.
    // Using a regular expression matching for fixing it guarantees that
    // things won't break if Google changes the way the URI is returned.
    preg_match('/https:\\/\\/*.*/', $userinfo['picture'], $matches);
    $userinfo['picture'] = $matches[0];
  }
  return $userinfo;
}