ueberauth / ueberauth_google

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

%OAuth2.Response{status_code: 503} with no error_description in body is not handled in get_access_token #98

Closed angelikatyborska closed 1 year ago

angelikatyborska commented 1 year ago

Steps to Reproduce

In our error tracker, we get sometimes see a CaseClauseError in Ueberauth.Strategy.Google.OAuth.get_access_token/2 when Google responds with a 503 error. The response's body only has an "error" key, but doesn't have the "error_description" key. Since this is an internal error from Google, we cannot reproduce it ourselves. The response looks like this:

{:error,
 %OAuth2.Response{
   status_code: 503,
   headers: [
     {"cache-control", "no-cache, no-store, max-age=0, must-revalidate"},
     {"expires", "Mon, 01 Jan 1990 00:00:00 GMT"},
     {"date", "Fri, 28 Jul 2023 16:55:20 GMT"}
     # more headers omitted for readability
   ],
   body: %{"error" => "internal_failure"}
 }}

It fails to be matched against one of the patters from https://github.com/ueberauth/ueberauth_google/blob/fdd44cdaa219903367c2fc6bc03d933f5ad737db/lib/ueberauth/strategy/google/oauth.ex#L55-L66

Expected Result

The get_access_token function returns a well formatted error like in case of other handled error responses. Since the error description is missing in the response, the short error code could be repeated in place of the description.

Actual Result

A CaseClauseError is raised.

yordis commented 1 year ago

Hey there, are you able to contribute and fix the situation?

 {:error, %OAuth2.Response{body: %{"error" => error} = response} -> 
   description = response.body["error_description"] || "....."
   # or please check what could be a better description or if we should use an empty string instead
   {:error, {error, description}} 
angelikatyborska commented 1 year ago

Yes, I or somebody else from my team can open a PR for this and probably also for a very similar issue https://github.com/ueberauth/ueberauth_google/issues/94. Give us a day or two 🙂

yordis commented 1 year ago

You got this! Let me know if you need help from me!