Skip to content

Commit

Permalink
Make sure access token is included in the client
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed Mar 19, 2018
1 parent 222e0ee commit e121fa1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/coherence_assent/strategies/oauth2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ defmodule CoherenceAssent.Strategy.OAuth2 do
state
|> check_state(client, params)
|> get_access_token(config, params)
|> get_user(config[:user_url])
|> case do
{:ok, user} -> {:ok, %{conn: conn, client: client, user: user}}
{:error, error} -> {:error, %{conn: conn, error: error}}
end
|> get_user_with_client(config[:user_url], conn)
end

@doc false
Expand Down Expand Up @@ -82,6 +78,17 @@ defmodule CoherenceAssent.Strategy.OAuth2 do
end
def get_user({:error, error}, _user_url), do: {:error, error}

defp get_user_with_client({:ok, client}, user_url, conn) do
{:ok, client}
|> get_user(user_url)
|> case do
{:ok, user} -> {:ok, %{conn: conn, client: client, user: user}}
{:error, error} -> {:error, %{conn: conn, error: error}}
end
end
defp get_user_with_client({:error, error}, _user_url, conn),
do: {:error, %{conn: conn, error: error}}

defp process_user_response({:ok, %OAuth2.Response{body: user}}), do: {:ok, user}
defp process_user_response({:error, %OAuth2.Response{status_code: 401}}),
do: {:error, %CoherenceAssent.RequestError{message: "Unauthorized token"}}
Expand Down

0 comments on commit e121fa1

Please sign in to comment.