improvement(OAuth2Authentication)!: Make the site option runtime configurable. (#31)

This commit is contained in:
James Harton 2022-11-15 14:32:36 +13:00 committed by James Harton
parent e7b1e84a63
commit 65d53e3597
3 changed files with 18 additions and 6 deletions

View file

@ -31,8 +31,18 @@ defmodule AshAuthentication.OAuth2Authentication do
required: true
],
site: [
type: :string,
doc: "The base URL of the OAuth2 server.",
type:
{:spark_function_behaviour, AshAuthentication.Secret,
{AshAuthentication.SecretFunction, 3}},
doc: """
The base URL of the OAuth2 server.
Takes either a 2..3 arity anonymous function, or a module which
implements the `AshAuthentication.Secret` behaviour.
See the module documentation for `AshAuthentication.Secret` for more
information.
""",
required: true
],
auth_method: [
@ -243,10 +253,12 @@ defmodule AshAuthentication.OAuth2Authentication do
Application.fetch_env(:my_app, :oauth2_client_secret)
end
site "https://auth.example.com"
site fn _, _, _ ->
{:ok, "https://auth.example.com"}
end)
redirect_uri fn _, _, _ ->
"https://localhost:4000/auth"
{:ok, "https://localhost:4000/auth"}
end
end

View file

@ -23,7 +23,7 @@ defmodule AshAuthentication.OAuth2Authentication.Info do
AshAuthentication.Info.tokens_signing_algorithm(resource),
{:ok, authorization_params} <- authorization_params(resource),
{:ok, redirect_uri} <- fetch_secret(resource, :redirect_uri),
{:ok, site} <- site(resource),
{:ok, site} <- fetch_secret(resource, :site),
{:ok, authorize_path} <- authorize_path(resource),
{:ok, token_path} <- token_path(resource),
{:ok, user_path} <- user_path(resource) do

View file

@ -113,7 +113,7 @@ defmodule Example.UserWithUsername do
client_id(fn _, _, _ -> {:ok, "made up"} end)
redirect_uri(fn _, _, _ -> {:ok, "http://localhost:4000/auth"} end)
client_secret(fn _, _, _ -> {:ok, "also made up"} end)
site("https://example.com")
site(fn _, _, _ -> {:ok, "https://example.com"} end)
authorization_params(scope: "openid profile email")
auth_method(:client_secret_post)
identity_resource(Example.UserIdentity)