auth = new OAuth2([ 'clientId' => $jsonKey['client_id'], 'clientSecret' => $jsonKey['client_secret'], 'refresh_token' => $jsonKey['refresh_token'], 'scope' => $scope, 'tokenCredentialUri' => self::TOKEN_CREDENTIAL_URI, ]); if (array_key_exists('quota_project', $jsonKey)) { $this->quotaProject = (string) $jsonKey['quota_project']; } if ($jsonKey['client_id'] === self::CLOUD_SDK_CLIENT_ID && is_null($this->quotaProject) && getenv(self::SUPPRESS_CLOUD_SDK_CREDS_WARNING_ENV) !== 'true') { trigger_error( 'Your application has authenticated using end user credentials ' . 'from Google Cloud SDK. We recommend that most server ' . 'applications use service accounts instead. If your ' . 'application continues to use end user credentials ' . 'from Cloud SDK, you might receive a "quota exceeded" ' . 'or "API not enabled" error. For more information about ' . 'service accounts, see ' . 'https://cloud.google.com/docs/authentication/. ' . 'To disable this warning, set ' . self::SUPPRESS_CLOUD_SDK_CREDS_WARNING_ENV . ' environment variable to "true".', E_USER_WARNING ); } } /** * @param callable $httpHandler * * @return array A set of auth related metadata, containing the following * keys: * - access_token (string) * - expires_in (int) * - scope (string) * - token_type (string) * - id_token (string) */ public function fetchAuthToken(callable $httpHandler = null) { return $this->auth->fetchAuthToken($httpHandler); } /** * @return string */ public function getCacheKey() { return $this->auth->getClientId() . ':' . $this->auth->getCacheKey(); } /** * @return array */ public function getLastReceivedToken() { return $this->auth->getLastReceivedToken(); } /** * Get the quota project used for this API request * * @return string|null */ public function getQuotaProject() { return $this->quotaProject; } }