$this->googleUserFromToken($identityToken, $nonce ?? ''), SocialProvider::Apple => $this->appleIdentityTokenVerifier->userFromToken( $identityToken, $nonce ?? '', ), }; } catch (HttpExceptionInterface $exception) { throw $exception; } catch (GuzzleException) { abort(503, 'SOCIAL_PROVIDER_UNAVAILABLE'); } catch (Throwable) { abort(401, 'SOCIAL_TOKEN_INVALID'); } } private function googleUserFromToken(string $identityToken, string $nonce): SocialiteUser { if (! config('services.google.client_id')) { abort(503, 'SOCIAL_PROVIDER_NOT_CONFIGURED'); } /** @var AbstractProvider $provider */ $provider = $this->socialite->driver(SocialProvider::Google->value); $identity = $provider->userFromToken($identityToken); $rawIdentity = method_exists($identity, 'getRaw') ? $identity->getRaw() : []; if (! is_array($rawIdentity) || ! $this->socialAuthenticationNonce->consume( SocialProvider::Google, $nonce, Arr::get($rawIdentity, 'nonce'), )) { abort(401, 'SOCIAL_TOKEN_INVALID'); } return $identity; } }