Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting an account for requests impersonification when using service accounts #5842

Closed
velPL opened this issue Feb 2, 2023 · 3 comments

Comments

@velPL
Copy link

velPL commented Feb 2, 2023

The https://github.com/googleapis/google-api-php-client library allows to authenticate using Service Accounts keys in JSON format and also impersonificate another user within a domain (which requires domain-wide delegation to be enabled). This is simply done as:

$client = new Google_Client();
$client->setSubject('address_to_act_as@example.com');

Could we please have this functionality as well in this library? From what I've seen there is a class \Google\Auth\Credentials\ServiceAccountCredentials with a constructor's 3rd argument for setting impersonation subject but this is never used/referenced. What's more - hardcoding a valid address to impersonate also fails with the permission denied for provided property id - error code 7.

@bshaffer
Copy link
Contributor

If you look at the code in Google\Client.php, it uses the same class you're referring to, ServiceAccountCredentials, to set the subject. So using that class and supplying the subject to its constructor would hav the same efect:

$credentials = new Google\Auth\Credentials\ServiceAccountCredentials($scope, $credFile, $subject);
// the configuration option may be different depending on the client
$bigquery = new Google\Cloud\BigQuery\BigQueryClient(['credentialsFetcher' => $credentials]);
$analytics = new Google\Cloud\AnalyticsData\V1\BetaAnalyticsDataClient(['credentials' => $credentials]);

Be sure to check the constructor options for your clients to see which parameter (credentials or credentialsFetcher) it accepts

@velPL
Copy link
Author

velPL commented Apr 12, 2023

Thanks @bshaffer for clearing this out. It works perfectly with code snippet you provided

@erensertkaya
Copy link

this helped me to thank you
#7257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants