@@ -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
282289end
0 commit comments