google-api-nodejs-client
google-api-nodejs-client copied to clipboard
Service account impersonation
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