Skip to content

Commit 0617af3

Browse files
authored
Merge pull request #63 from robuye/rob-upgrade-ueberauth
update state param handling & ueberauth to 0.7
2 parents d141ecf + 8d52fde commit 0617af3

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

lib/ueberauth/strategy/github.ex

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ defmodule Ueberauth.Strategy.Github do
7474
use Ueberauth.Strategy,
7575
uid_field: :id,
7676
default_scope: "",
77+
send_redirect_uri: true,
7778
oauth2_module: Ueberauth.Strategy.Github.OAuth
7879

7980
alias Ueberauth.Auth.Info
@@ -87,22 +88,14 @@ defmodule Ueberauth.Strategy.Github do
8788
them as part of your url:
8889
8990
"/auth/github?scope=user,public_repo,gist"
90-
91-
You can also include a `:state` param that github will return to you.
9291
"""
93-
def handle_request!(conn) do
94-
scopes = conn.params["scope"] || option(conn, :default_scope)
95-
send_redirect_uri = Keyword.get(options(conn), :send_redirect_uri, true)
96-
97-
opts =
98-
if send_redirect_uri do
99-
[redirect_uri: callback_url(conn), scope: scopes]
100-
else
101-
[scope: scopes]
102-
end
10392

93+
def handle_request!(conn) do
10494
opts =
105-
if conn.params["state"], do: Keyword.put(opts, :state, conn.params["state"]), else: opts
95+
[]
96+
|> with_scopes(conn)
97+
|> with_state_param(conn)
98+
|> with_redirect_uri(conn)
10699

107100
module = option(conn, :oauth2_module)
108101
redirect!(conn, apply(module, :authorize_url!, [opts]))
@@ -279,4 +272,18 @@ defmodule Ueberauth.Strategy.Github do
279272
defp option(conn, key) do
280273
Keyword.get(options(conn), key, Keyword.get(default_options(), key))
281274
end
275+
276+
defp with_scopes(opts, conn) do
277+
scopes = conn.params["scope"] || option(conn, :default_scope)
278+
279+
opts |> Keyword.put(:scope, scopes)
280+
end
281+
282+
defp with_redirect_uri(opts, conn) do
283+
if option(conn, :send_redirect_uri) do
284+
opts |> Keyword.put(:redirect_uri, callback_url(conn))
285+
else
286+
opts
287+
end
288+
end
282289
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule Ueberauth.Github.Mixfile do
2727
defp deps do
2828
[
2929
{:oauth2, "~> 1.0 or ~> 2.0"},
30-
{:ueberauth, "~> 0.6.0"},
30+
{:ueberauth, "~> 0.7.0"},
3131
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
3232
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
3333
]

0 commit comments

Comments
 (0)