ueberauth / ueberauth_google

Google OAuth2 Strategy for Überauth.
MIT License
164 stars 85 forks source link

OAuth2.Error{reason: :closed} is not handled in get_access_token for Google OAuth #94

Closed timgent closed 1 year ago

timgent commented 2 years ago

Steps to Reproduce

Sorry unknown steps to reproduce.

Expected Result

Error should be caught and handled.

Actual Result

We got this stack trace, which suggests that a certain class of OAuth2 error isn't being handled properly.

** (exit) an exception was raised:
    ** (CaseClauseError) no case clause matching: {:error, %OAuth2.Error{reason: :closed}}
        (ueberauth_google 0.10.1) lib/ueberauth/strategy/google/oauth.ex:54: Ueberauth.Strategy.Google.OAuth.get_access_token/2
        (ueberauth_google 0.10.1) lib/ueberauth/strategy/google.ex:45: Ueberauth.Strategy.Google.handle_callback!/1
        (ueberauth 0.7.0) lib/ueberauth/strategy.ex:364: Ueberauth.Strategy.run_handle_callback/2

The code blowing up is:

  def get_access_token(params \\ [], opts \\ []) do
    case opts |> client |> OAuth2.Client.get_token(params) do
      {:error, %{body: %{"error" => error, "error_description" => description}}} ->
        {:error, {error, description}}
      {:ok, %{token: %{access_token: nil} = token}} ->
        %{"error" => error, "error_description" => description} = token.other_params
        {:error, {error, description}}
      {:ok, %{token: token}} ->
        {:ok, token}
    end
  end
Hanspagh commented 2 years ago

Thanks for the bug report, if you feel like it feel free to submit a PR with the fix

angelikatyborska commented 1 year ago

I wanted to try fixing this issue, but as far as I can see, it has already been fixed in https://github.com/ueberauth/ueberauth_google/pull/88 and released in https://github.com/ueberauth/ueberauth_google/releases/tag/v0.10.2

yordis commented 1 year ago

@angelikatyborska thank you so much for the comment! 🪨 on