diff --git a/lib/ueberauth/strategy/google.ex b/lib/ueberauth/strategy/google.ex index c0dc3c7..bdcaad2 100644 --- a/lib/ueberauth/strategy/google.ex +++ b/lib/ueberauth/strategy/google.ex @@ -42,9 +42,16 @@ defmodule Ueberauth.Strategy.Google do end end + @doc """ + Handles the callback for Google client side flow. + """ + def handle_callback!(%Plug.Conn{params: %{"token" => token}} = conn) do + fetch_user(conn, OAuth2.AccessToken.new(token)) + end + @doc false def handle_callback!(conn) do - set_errors!(conn, [error("missing_code", "No code received")]) + set_errors!(conn, [error("missing_code_or_token", "No code or token received")]) end @doc false @@ -124,7 +131,7 @@ defmodule Ueberauth.Strategy.Google do resp = Ueberauth.Strategy.Google.OAuth.get(token, path) case resp do - {:ok, %OAuth2.Response{status_code: 401, body: _body}} -> + {:error, %OAuth2.Response{status_code: 401, body: _body}} -> set_errors!(conn, [error("token", "unauthorized")]) {:ok, %OAuth2.Response{status_code: status_code, body: user}} when status_code in 200..399 -> put_private(conn, :google_user, user)