2022-09-28 09:54:05 +13:00
|
|
|
# AshAuthentication
|
|
|
|
|
2022-10-25 20:32:57 +13:00
|
|
|
AshAuthentication provides drop-in support for user authentication for users of
|
|
|
|
the [Ash framework](https://ash-hq.org). It is designed to be highly
|
|
|
|
configurable, with sensible defaults covering the most common use-cases.
|
2022-09-28 09:54:05 +13:00
|
|
|
|
2022-12-08 16:52:23 +13:00
|
|
|
## Warning
|
|
|
|
|
|
|
|
This is **beta** software. Please don't use it without talking to us!
|
|
|
|
|
2022-09-28 09:54:05 +13:00
|
|
|
## Installation
|
|
|
|
|
2022-10-25 20:32:57 +13:00
|
|
|
The package can be installed by adding `ash_authentication` to your list of
|
|
|
|
dependencies in `mix.exs`:
|
2022-09-28 09:54:05 +13:00
|
|
|
|
|
|
|
```elixir
|
|
|
|
def deps do
|
|
|
|
[
|
2022-12-15 08:00:36 +13:00
|
|
|
{:ash_authentication, "~> 3.1.0"}
|
2022-09-28 09:54:05 +13:00
|
|
|
]
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2022-10-25 20:32:57 +13:00
|
|
|
## Usage
|
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
This package assumes that you have [Ash](https://ash-hq.org/) installed and
|
|
|
|
configured. See the Ash documentation for details.
|
2022-10-25 20:32:57 +13:00
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
Once installed you can easily add support for authentication by adding the
|
|
|
|
`AshAuthentication` extension to your resource:
|
2022-10-25 20:32:57 +13:00
|
|
|
|
|
|
|
```elixir
|
|
|
|
defmodule MyApp.Accounts.User do
|
|
|
|
use Ash.Resource,
|
2022-11-23 09:09:41 +13:00
|
|
|
extensions: [AshAuthentication]
|
2022-10-25 20:32:57 +13:00
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key :id
|
|
|
|
attribute :email, :ci_string, allow_nil?: false
|
|
|
|
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
|
|
|
|
end
|
|
|
|
|
|
|
|
authentication do
|
|
|
|
api MyApp.Accounts
|
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
strategies do
|
|
|
|
password do
|
|
|
|
identity_field :email
|
|
|
|
hashed_password_field :hashed_password
|
|
|
|
end
|
|
|
|
end
|
2022-10-25 20:32:57 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
identities do
|
|
|
|
identity :unique_email, [:email]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
If you plan on providing authentication via the web, then you will need to
|
|
|
|
define a plug using
|
|
|
|
[`AshAuthentication.Plug`](https://team-alembic.github.io/ash_authentication/AshAuthentication.Plug.html)
|
2022-11-23 09:09:41 +13:00
|
|
|
which builds a [`Plug.Router`](https://hexdocs.pm/plug/Plug.Router.html) that
|
2022-10-25 20:32:57 +13:00
|
|
|
routes incoming authentication requests to the correct provider and provides
|
|
|
|
callbacks for you to manipulate the conn after success or failure.
|
|
|
|
|
2022-10-26 08:45:21 +13:00
|
|
|
If you're using AshAuthentication with Phoenix, then check out
|
|
|
|
[`ash_authentication_phoenix`](https://github.com/team-alembic/ash_authentication_phoenix)
|
2022-10-26 10:59:29 +13:00
|
|
|
which provides route helpers, a controller abstraction and LiveView components
|
2022-10-26 08:45:21 +13:00
|
|
|
for easy set up.
|
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
## Authentication Strategies
|
2022-10-25 20:32:57 +13:00
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
Currently supported strategies:
|
2022-10-25 20:32:57 +13:00
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
1. [`AshAuthentication.Strategy.Password`](https://team-alembic.github.io/ash_authentication/AshAuthentication.Strategy.Password.html)
|
|
|
|
- authenticate users against your local database using a unique identity
|
|
|
|
(such as username or email address) and a password.
|
|
|
|
2. [`AshAuthentication.Strategy.OAuth2`](https://team-alembic.github.io/ash_authentication/AshAuthentication.Strategy.OAuth2.html)
|
|
|
|
- authenticate using local or remote [OAuth 2.0](https://oauth.net/2/)
|
|
|
|
compatible services.
|
2022-10-25 20:32:57 +13:00
|
|
|
|
|
|
|
## Documentation
|
|
|
|
|
|
|
|
Documentation for the latest release will be [available on
|
|
|
|
hexdocs](https://hexdocs.pm/ash_authentication) and for the [`main`
|
|
|
|
branch](https://team-alembic.github.io/ash_authentication).
|
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
Additional support can be found on the [GitHub discussions
|
|
|
|
page](https://github.com/team-alembic/ash_authentication/discussions) and the
|
|
|
|
[Ash Discord](https://discord.gg/D7FNG2q).
|
|
|
|
|
2022-10-25 20:32:57 +13:00
|
|
|
## Contributing
|
|
|
|
|
|
|
|
* To contribute updates, fixes or new features please fork and open a
|
|
|
|
pull-request against `main`.
|
|
|
|
* Please use [conventional
|
|
|
|
commits](https://www.conventionalcommits.org/en/v1.0.0/) - this allows us to
|
|
|
|
dynamically generate the changelog.
|
|
|
|
* Feel free to ask any questions on out [GitHub discussions
|
|
|
|
page](https://github.com/team-alembic/ash_authentication/discussions).
|
2022-09-28 09:54:05 +13:00
|
|
|
|
2022-11-14 16:44:53 +13:00
|
|
|
## Licence
|
|
|
|
|
2022-11-23 09:09:41 +13:00
|
|
|
`AshAuthentication` is licensed under the terms of the [MIT
|
|
|
|
license](https://opensource.org/licenses/MIT). See the [`LICENSE` file in this
|
|
|
|
repository](https://github.com/team-alembic/ash_authentication/blob/main/LICENSE)
|
|
|
|
for details.
|