improvement(docs): Improve endpoint docs for PasswordAuthentication and PasswordReset.

This commit is contained in:
James Harton 2022-11-04 11:46:03 +13:00
parent 9afce721fe
commit e5ba987ee1
4 changed files with 53 additions and 11 deletions

View file

@ -100,6 +100,36 @@ defmodule AshAuthentication.PasswordAuthentication do
end
```
## Endpoints
This provider routes requests to both the `request` and `callback` endpoints
to the same handler, so either can be used. Requests are differentiated by
the presence of an `action` parameter in the request body.
### Examples
When attempting to register a new user
```
%{"user" => %{
"action" => "register",
"email" => "marty@mcfly.me",
"password" => "back to 1985",
"password_confirmation" => "back to 1985"
# any additional user fields you wish to accept on creation.
}}
```
When attempting to sign-in a user
```
%{"user" => %{
"action" => "sign_in",
"email" => "marty@mcfly.me",
"password" => "back to 1985"
}}
```
## DSL Documentation
### Index

View file

@ -86,10 +86,19 @@ defmodule AshAuthentication.PasswordReset do
end
```
Because you often want to submit the password reset token via the web, you can
also use the password authentication callback endpoint with an action of
"reset_password" and the reset password action will be called with the
included params.
## Endpoints
* `request` - send the identity field nested below the subject name (eg
`%{"user" => %{"email" => "marty@mcfly.me"}}`). If the resource supports
password resets then the success callback will be called with a `nil` user
and token regardless of whether the user could be found. If the user is
found then the `sender` will be called.
* `callback` - attempt to perform a password reset. Should be called with the
reset token, password and password confirmation if confirmation is enabled,
nested below the subject name (eg `%{"user" => %{"reset_token" => "abc123",
"password" => "back to 1985", "password_confirmation" => "back to 1975"}}`).
If the password was successfully changed then the relevant user will be
returned to the `success` callback.
## DSL Documentation

View file

@ -219,6 +219,9 @@ defmodule AshAuthentication.PasswordReset.Transformer do
|> Enum.concat([
Transformer.build_entity!(Resource.Dsl, [:actions, :update], :change,
change: PA.HashPasswordChange
),
Transformer.build_entity!(Resource.Dsl, [:actions, :update], :change,
change: PA.GenerateTokenChange
)
])
@ -254,12 +257,14 @@ defmodule AshAuthentication.PasswordReset.Transformer do
action,
password_confirmation_field,
confirmation_required?
),
:ok <-
PA.UserValidations.validate_action_has_validation(
action,
PA.PasswordConfirmationValidation,
confirmation_required?
) do
PA.UserValidations.validate_action_has_validation(
action,
PA.PasswordConfirmationValidation,
confirmation_required?
)
validate_action_has_change(action, PA.GenerateTokenChange)
end
end
end

View file

@ -25,8 +25,6 @@ defmodule AshAuthentication.Plug.Dispatcher do
|> return(return_to)
end
def call(conn, {_phase, _routes, return_to}), do: return_to.handle_failure(conn)
defp dispatch(
%{params: %{"subject_name" => subject_name, "provider" => provider}} = conn,
phase,