google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Service account impersonation

Open P1K3N opened this issue 2 years ago • 0 comments

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

P1K3N avatar Apr 21 '22 15:04 P1K3N