Commit 76f90de3 authored by Christopher C. Wells's avatar Christopher C. Wells
Browse files

Issue #3296270: Legacy People API has not been used in project before or it is disabled

parent ae94d6c8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
        }
    ],
    "require": {
        "league/oauth2-google": "^2.0",
        "league/oauth2-google": "^4.0",
        "drupal/social_auth": "^4.0",
        "drupal/core": "^9 || ^10"
    },
+12 −7
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\social_auth_google;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\social_auth\AuthManager\OAuth2Manager;
use Drupal\social_auth\User\SocialAuthUser;
use Drupal\social_auth\User\SocialAuthUserInterface;
use Drupal\Core\Config\ConfigFactory;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
@@ -51,13 +52,17 @@ class GoogleAuthManager extends OAuth2Manager {
   * {@inheritdoc}
   */
  public function getUserInfo(): SocialAuthUserInterface {
    $access_token = $this->getAccessToken();
    if (!$this->user && $access_token != NULL) {
      $this->user = $this->client->getResourceOwner($this->getAccessToken());
    }
    else {
      $this->loggerFactory->get('social_auth_google')
        ->error('There was an error fetching the access token for user.');
    if (!$this->user) {
      /** @var \League\OAuth2\Client\Provider\GoogleUser $owner */
      $owner = $this->client->getResourceOwner($this->getAccessToken());
      $this->user = new SocialAuthUser(
        $owner->getName(),
        $owner->getId(),
        $this->getAccessToken(),
        $owner->getEmail(),
        $owner->getAvatar(),
        $this->getExtraDetails()
      );
    }
    return $this->user;
  }