googleapis / googleapis/google-api-nodejs-client

Service account impersonation

Open
#2,959 0 comments 1 reaction 0 assignees View on GitHub
priority: p3 type: question
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

Hi!

I was trying to request the dv360 API with an impersonated service account token.
Hi guys,

running into the same issue.
When I try to request an impersonated token like this :
return new google.auth.GoogleAuth({
keyFile: './google-credentials.json',
clientOptions: {
subject:
'test-service-account-to-impers@some-domain', //serviceAccountEmail,
},
scopes: SCOPES,
});

where const SCOPES = [
'https://www.googleapis.com/auth/display-video',
'https://www.googleapis.com/auth/display-video-mediaplanning',
'https://www.googleapis.com/auth/display-video-user-management',
'https://www.googleapis.com/auth/doubleclickbidmanager',
];

But i receive an error from the API: Error: unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested

if I remove the clientOptions I receive the token and can get to the API.

Note: roles added to the master service account got from here https://cloud.google.com/iam/docs/impersonating-service-accounts#iam-service-accounts-grant-role-sa-console

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.