peburrows / goth

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

:nxdomain when calling Goth.Token.for_scope/1 #60

Closed yuchunc closed 5 years ago

yuchunc commented 5 years ago

I have been trying to auth with Google with Goth.Token.for_scope/1, and would get this error:

** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :nxdomain}}
    (goth) lib/goth/client.ex:64: Goth.Client.get_access_token/3
    (goth) lib/goth/token.ex:151: Goth.Token.retrieve_and_store!/2

Looking in to the code base, I found it is trying to call http://metadata.google.internal, hence the :nxdomain error. I feel I missed something during the setup, but can't figure it out. How should I understand this error?

Thanks

yuchunc commented 5 years ago

Hi, sorry to be a nuisance, but any direction on this would be super helpful!

Thank you!!

peburrows commented 5 years ago

Sorry, I somehow completely missed this initial issue report!

Goth should only be falling back to hitting that internal Google metadata host when it can't find any other configuration. Have you configured Goth to use your service account json credentials, most likely via something like this in a config file:

# via a variable that contains the json
config :goth, json: credentials_json

# or, via an ENV var
config :goth, json: {:system, "MY_GCP_CREDENTIALS"}

(There are other ways to pass in your credentials, but those are the two most common.)

yuchunc commented 5 years ago

@peburrows ahhh..... I think I had provided the wrong credential json. I deleted everything and started again last week, and "accidentally" provided the right cred json, and it works now. Do you think it might be useful to have warning messages in dev environment when some part of the cred is missing?

Thanks for being patient with my issues.

vans163 commented 5 years ago

I think this is an error with how :inet_res works on newer erlang versions. 10.4.4 ERTS for example cannot parse a domain with a trailing /, but 10.2.2 ERTS can.