-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle client side flow for google auth. #35
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}} -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does a 401 here return with an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hassox Yep, it returned an :error when I tested it. I will retest it and confirm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hassox I have verified the response again. It returns with and
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latest |
||
{: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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hassox could we add the parameter as
binary
as well? We technically don't need theConn
so if I add the logic of the oauth callbacks outside of an phoenix project I dont need to carry on theConn
everywhere.The same for other strategies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yordis I'm not sure I follow when you say
binary
. Are you asking that this match be changed from%Plug.Conn{params: %{"token" => token}}
to%{params: %{"token" => token}}
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blakedietz could you make this change based on @yordis's comment below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohanpujaris the param that holds the JWT is called
credential
I think: https://developers.google.com/identity/gsi/web/reference/js-reference#credential