Skip to content

feat: json key scopes in ImpersonatedServiceAccountCredentials#638

Merged
bshaffer merged 5 commits into
mainfrom
json-scopes-in-impersonated-creds
Nov 5, 2025
Merged

feat: json key scopes in ImpersonatedServiceAccountCredentials#638
bshaffer merged 5 commits into
mainfrom
json-scopes-in-impersonated-creds

Conversation

@bshaffer
Copy link
Copy Markdown
Contributor

@bshaffer bshaffer commented Oct 22, 2025

b/450324042

ImpersonatedAccountCredentials now respect the scopes field in the ADC JSON file. The following example credentials file would configure the targetScopes to be in the JSON field (if and only if explicit user scopes were not supplied):

$ cat $APPLICATION_DEFAULT_CREDENTIALS
{
    "type":"impersonated_service_account",
    "service_account_impersonation_url": "https://iamcredentials.googleapis.com/...",
    "scopes": ["scopeA", "scopeB"],
    "source_credentials": {
        "client_email":"clientemail@clientemail.com",
        "private_key":"-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----\n",
        "type":"service_account",
    }
}

When not configured, the defaultScopes will be used. This can be done manually as well when instantiating the credentials:

use Google\Auth\Credentials\ImpersonatedServiceAccountCredentials;
$userScopes = ['my-scope'];
$defaultScopes = ['https://www.googleapis.com/auth/cloud-platform'];
$jsonKey = json_decode(file_get_contents('/path/to/mycredentials.json'));

// If $userScopes are supplied, they will be used
// otherwise the "scopes" field in the JSON key will be used.
// If that's empty, then the $defaultScopes are used.
$impersonatedCreds = new ImpersonatedServiceAccountCredentials($userScopes, $jsonKey, null, $defaultScopes);

@bshaffer bshaffer requested a review from a team October 22, 2025 23:12
@bshaffer bshaffer changed the title feat: support json key scopes in ImpersonatedServiceAccountCredentials feat: json key scopes in ImpersonatedServiceAccountCredentials Oct 22, 2025
@bshaffer bshaffer merged commit b6b6966 into main Nov 5, 2025
12 checks passed
@bshaffer bshaffer deleted the json-scopes-in-impersonated-creds branch November 5, 2025 19:43
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

Successfully merging this pull request may close these issues.

2 participants