Skip to content

Commit

Permalink
Add support to lc param in handle_request
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrodevs committed Sep 25, 2023
1 parent 335e877 commit 5ed220c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ueberauth/strategy/microsoft.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Ueberauth.Strategy.Microsoft do
[scope: scopes, prompt: prompt]
|> with_scopes(:extra_scopes, conn)
|> with_state_param(conn)
|> with_param(:lc, conn)

opts = oauth_client_options_from_conn(conn)
redirect!(conn, Ueberauth.Strategy.Microsoft.OAuth.authorize_url!(params, opts))
Expand Down Expand Up @@ -154,4 +155,8 @@ defmodule Ueberauth.Strategy.Microsoft do
|> options
|> Keyword.get(key, default)
end

defp with_param(opts, key, conn) do
if value = conn.params[to_string(key)], do: Keyword.put(opts, key, value), else: opts
end
end
13 changes: 13 additions & 0 deletions test/strategy/microsoft_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Ueberauth.Strategy.MicrosoftTest do
use ExUnit.Case, async: true
use Plug.Test

test "lc param is present in the redirect uri" do
conn = conn(:get, "/auth/microsoft", %{lc: 10})
routes = Ueberauth.init()
resp = Ueberauth.call(conn, routes)
assert [location] = get_resp_header(resp, "location")
redirect_uri = URI.parse(location)
assert Plug.Conn.Query.decode(redirect_uri.query)["lc"] == "10"
end
end

0 comments on commit 5ed220c

Please sign in to comment.