Skip to content

Commit

Permalink
Deprecate domain config in Auth0 strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed Jan 1, 2025
1 parent b6c3ac8 commit f7554e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.13 (TBA)

* `Assent.Strategy.Auth0` deprecated `:domain` config option in favor of `:base_url`

## v0.2.12 (2024-12-29)

* `Assent` now has a module doc
Expand Down
10 changes: 7 additions & 3 deletions lib/assent/strategies/auth0.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Assent.Strategy.Auth0 do
config = [
client_id: "REPLACE_WITH_CLIENT_ID",
client_secret: "REPLACE_WITH_CLIENT_SECRET",
domain: "REPLACE_WITH_DOMAIN",
base_url: "https://my-domain.auth0.com",
redirect_uri: "http://localhost:4000/auth/callback"
]
Expand All @@ -28,8 +28,12 @@ defmodule Assent.Strategy.Auth0 do

defp append_domain_config(config, default) do
case Assent.fetch_config(config, :domain) do
{:ok, domain} -> Keyword.put(default, :base_url, prepend_scheme(domain))
_error -> default
{:ok, domain} ->
IO.warn("`:domain` config is deprecated. Use `:base_url` instead.")
Keyword.put(default, :base_url, prepend_scheme(domain))

_error ->
default
end
end

Expand Down
35 changes: 22 additions & 13 deletions test/assent/strategies/auth0_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ defmodule Assent.Strategy.Auth0Test do
}
@user @user_response

describe "authorize_url/2" do
test "requires domain or base_url configuration", %{config: config} do
config = Keyword.take(config, [:client_id, :redirect_uri])
test "authorize_url/2", %{config: config} do
config = Keyword.delete(config, :base_url)

assert {:error, %MissingConfigError{} = error} = Auth0.authorize_url(config)
assert error.key == :base_url
assert {:error, %MissingConfigError{} = error} = Auth0.authorize_url(config)
assert error.key == :base_url

assert {:ok, %{url: url}} = Auth0.authorize_url(config ++ [base_url: "https://localhost"])
assert url =~ "https://localhost/authorize"
assert {:ok, %{url: url}} =
Auth0.authorize_url(config ++ [base_url: "https://demo.auth0.com/authorize"])

assert {:ok, %{url: url}} = Auth0.authorize_url(config ++ [domain: "demo.auth0.com"])
assert url =~ "https://demo.auth0.com/authorize"

assert {:ok, %{url: url}} = Auth0.authorize_url(config ++ [domain: "http://demo.auth0.com"])
assert url =~ "http://demo.auth0.com/authorize"
end
assert url =~ "https://demo.auth0.com/authorize"
end

test "callback/2", %{config: config, callback_params: params} do
Expand All @@ -58,4 +52,19 @@ defmodule Assent.Strategy.Auth0Test do
assert {:ok, %{user: user}} = Auth0.callback(config, params)
assert user == @user
end

### Deprecated

test "authorize_url/2 with `:domain` config", %{config: config} do
config = Keyword.take(config, [:client_id, :redirect_uri])

assert {:error, %MissingConfigError{} = error} = Auth0.authorize_url(config)
assert error.key == :base_url

assert {:ok, %{url: url}} = Auth0.authorize_url(config ++ [domain: "demo.auth0.com"])
assert url =~ "https://demo.auth0.com/authorize"

assert {:ok, %{url: url}} = Auth0.authorize_url(config ++ [domain: "http://demo.auth0.com"])
assert url =~ "http://demo.auth0.com/authorize"
end
end

0 comments on commit f7554e1

Please sign in to comment.