diff --git a/src/Credentials/UserRefreshCredentials.php b/src/Credentials/UserRefreshCredentials.php index e2f32d87f..2c94a3bef 100644 --- a/src/Credentials/UserRefreshCredentials.php +++ b/src/Credentials/UserRefreshCredentials.php @@ -58,7 +58,8 @@ class UserRefreshCredentials extends CredentialsLoader implements GetQuotaProjec */ public function __construct( $scope, - $jsonKey + $jsonKey, + $targetAudience = null ) { if (is_string($jsonKey)) { if (!file_exists($jsonKey)) { @@ -84,12 +85,17 @@ public function __construct( 'json key is missing the refresh_token field' ); } + $additionalClaims = []; + if ($targetAudience) { + $additionalClaims = ['target_audience' => $targetAudience]; + } $this->auth = new OAuth2([ 'clientId' => $jsonKey['client_id'], 'clientSecret' => $jsonKey['client_secret'], 'refresh_token' => $jsonKey['refresh_token'], 'scope' => $scope, 'tokenCredentialUri' => self::TOKEN_CREDENTIAL_URI, + 'additionalClaims' => $additionalClaims, ]); if (array_key_exists('quota_project_id', $jsonKey)) { $this->quotaProject = (string) $jsonKey['quota_project_id'];