From 9ae213dfec5ea66ce12e3c6e135c8bb347cf0001 Mon Sep 17 00:00:00 2001 From: Rohan Pujari Date: Tue, 11 Apr 2017 20:12:21 +0530 Subject: [PATCH] Handle client side flow for google auth. --- lib/ueberauth/strategy/google.ex | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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)