mirror of
https://github.com/team-alembic/ash_authentication.git
synced 2024-09-20 05:13:10 +12:00
improvement(docs): Improve endpoint docs for PasswordAuthentication and PasswordReset.
This commit is contained in:
parent
9afce721fe
commit
e5ba987ee1
4 changed files with 53 additions and 11 deletions
|
@ -100,6 +100,36 @@ defmodule AshAuthentication.PasswordAuthentication do
|
||||||
end
|
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
|
## DSL Documentation
|
||||||
|
|
||||||
### Index
|
### Index
|
||||||
|
|
|
@ -86,10 +86,19 @@ defmodule AshAuthentication.PasswordReset do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Because you often want to submit the password reset token via the web, you can
|
## Endpoints
|
||||||
also use the password authentication callback endpoint with an action of
|
|
||||||
"reset_password" and the reset password action will be called with the
|
* `request` - send the identity field nested below the subject name (eg
|
||||||
included params.
|
`%{"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
|
## DSL Documentation
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,9 @@ defmodule AshAuthentication.PasswordReset.Transformer do
|
||||||
|> Enum.concat([
|
|> Enum.concat([
|
||||||
Transformer.build_entity!(Resource.Dsl, [:actions, :update], :change,
|
Transformer.build_entity!(Resource.Dsl, [:actions, :update], :change,
|
||||||
change: PA.HashPasswordChange
|
change: PA.HashPasswordChange
|
||||||
|
),
|
||||||
|
Transformer.build_entity!(Resource.Dsl, [:actions, :update], :change,
|
||||||
|
change: PA.GenerateTokenChange
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -254,12 +257,14 @@ defmodule AshAuthentication.PasswordReset.Transformer do
|
||||||
action,
|
action,
|
||||||
password_confirmation_field,
|
password_confirmation_field,
|
||||||
confirmation_required?
|
confirmation_required?
|
||||||
|
),
|
||||||
|
:ok <-
|
||||||
|
PA.UserValidations.validate_action_has_validation(
|
||||||
|
action,
|
||||||
|
PA.PasswordConfirmationValidation,
|
||||||
|
confirmation_required?
|
||||||
) do
|
) do
|
||||||
PA.UserValidations.validate_action_has_validation(
|
validate_action_has_change(action, PA.GenerateTokenChange)
|
||||||
action,
|
|
||||||
PA.PasswordConfirmationValidation,
|
|
||||||
confirmation_required?
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,8 +25,6 @@ defmodule AshAuthentication.Plug.Dispatcher do
|
||||||
|> return(return_to)
|
|> return(return_to)
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, {_phase, _routes, return_to}), do: return_to.handle_failure(conn)
|
|
||||||
|
|
||||||
defp dispatch(
|
defp dispatch(
|
||||||
%{params: %{"subject_name" => subject_name, "provider" => provider}} = conn,
|
%{params: %{"subject_name" => subject_name, "provider" => provider}} = conn,
|
||||||
phase,
|
phase,
|
||||||
|
|
Loading…
Reference in a new issue