peburrows / goth

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

Configure when goth starts. #69

Closed Adzz closed 3 years ago

Adzz commented 4 years ago

Hello, thanks for goth it's great. I have a question.

I made a lib that has goth as a dependancy. Let's call it gcp_secret_provider. I want to use gcp_secret_provider in another app, App A.

I have configured goth in gcp_secret_provider, and App A shouldn't know about Goth at all. But currently if I include gcp_secret_provider in App A, app A will crash on start up in :dev env or :test env because goth is incorrectly configured.

In gcp_secret_provider I have this in config/config.exs

config(:goth, json: ~S({
    "project_id": "PROJECT_ID",
    "private_key": "MOCK_KEY",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/my_lovely_app.iam.gserviceaccount.com"
  }))

So I would expect when I start App A that the above config would be given to goth and it would all be fine. Do you know why it's not?

Is it something to do with when Goth's genserver(s) get started?

Thanks for any help.

bbhoss commented 4 years ago

This seems to be the reason config shouldn't be used for things like this, or at least not the only option. Being able to call functions with the key info as a string would make this much easier.

wojtekmach commented 3 years ago

This is fixed in #83, we're introducing a new API where you'd be explicitly adding Goth to your supervision tree.