peburrows / goth

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

1.3-rc cannot work as expected #115

Closed dannypsnl closed 2 years ago

dannypsnl commented 2 years ago

I switch to 1.3-rc and it didn't work as 1.2

setup

-      {:goth, "~> 1.2.0"},
+      {:goth, "~> 1.3-rc"},
+      {:hackney, "~> 1.17"},
  def start(_type, _args) do
    credentials =
      "GOOGLE_APPLICATION_CREDENTIALS" |> System.fetch_env!() |> File.read!() |> Jason.decode!()
    scopes = ["https://www.googleapis.com/auth/datastore"]
    source =
      {:service_account, credentials, scopes: scopes}

    children = [
      {Goth, name: OurApp.Goth, source: source},
    ]
  end

usage

-    {:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/datastore")
+    {:ok, token} = Goth.fetch(QonverApi.Goth)
wojtekmach commented 2 years ago

Could you give some more context? What did you expect to happen and what actually happened? 1.3 has different API than the deprecated 1.2 API but the latter is still there.

dannypsnl commented 2 years ago

I found I cannot upload files to cloud storage with above changes, sorry that I find more useful context here.

wojtekmach commented 2 years ago

It seems it worked correctly on Goth v1.2 but not on v1.3? Please provide two snippets so I could run this locally:

Mix.install(
  [
    {:goth, "~> 1.2.0"}
  ],
  config: [
    goth: [
      # ... of course please keep credentials confidential.
    ]
  ]
)

Goth.Token.fetch(...)
Mix.install([
  {:goth, "~> 1.3.0-rc.3"}
])

{:ok, _} = Goth.start_link(name: MyApp.Goth, ...)

Goth.fetch(MyApp.Goth)

I'm gonna close this in the meantime but please feel free to continue the discussion here.

dannypsnl commented 2 years ago

It seems it worked correctly on Goth v1.2 but not on v1.3?

Yes, I already found these two versions give two different tokens back to me, where version 1.3 didn't work.

1.2

Mix.install(
  [
    {:goth, "~> 1.2.0"}
  ]
)

{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/datastore")
IO.inspect(token)

1.3

Mix.install([
  {:goth, "~> 1.3.0-rc.3"},
  {:hackney, "~> 1.17"}
])

credentials = "GOOGLE_APPLICATION_CREDENTIALS" |> System.fetch_env!() |> File.read!() |> Jason.decode!()

source = {:service_account, credentials, scopes: ["https://www.googleapis.com/auth/datastore"]}

{:ok, _} = Goth.start_link(name: MyApp.Goth, source: source)

{:ok, token} = Goth.fetch(MyApp.Goth)
IO.inspect(token)
dannypsnl commented 2 years ago

Update! I finally figure out the problem, I didn't notice old code's scope has more than one. My fault, thanks for your help.