peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
289 stars 111 forks source link

Getting 401 unauthorized client when trying to impersonate with service account #159

Open tonyzeng91 opened 1 year ago

tonyzeng91 commented 1 year ago

Hi - I am getting the follow error when trying to impersonate a service account.

{:error, %RuntimeError{message: "unexpected status 401 from Google\n\n{\n  \"error\": \"unauthorized_client\",\n  \"error_description\": \"Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.\"\n}\n"}}
# steps to impersonate
credentials = "credentials.json" |> File.read!() |> Jason.decode!()
claims = %{"sub" => "<IMPERSONATED_ACCOUNT_EMAIL>", "scope" => "https://www.googleapis.com/auth/cloud-platform"}
Goth.Token.fetch(source: {:service_account, credentials, [claims: claims]})

I am able to impersonate with a similar library in Python. Any idea why I am getting this error using the Goth lib?