The Ash Authentication framework
Find a file
2022-11-02 18:18:20 +13:00
.devcontainer feat(PasswordAuthentication): Registration and authentication with local credentials (#4) 2022-10-25 11:07:07 +13:00
.github chore(ci): update to latest staple-actions 2022-09-30 16:04:41 +13:00
config feat(Ash.PlugHelpers): Support standard actor configuration. (#16) 2022-10-31 16:43:00 +13:00
dev feat(Ash.PlugHelpers): Support standard actor configuration. (#16) 2022-10-31 16:43:00 +13:00
lib feat(PasswordReset): allow users to request and reset their password. (#22) 2022-11-02 18:18:20 +13:00
priv feat(PasswordAuthentication): Registration and authentication with local credentials (#4) 2022-10-25 11:07:07 +13:00
test feat(PasswordReset): allow users to request and reset their password. (#22) 2022-11-02 18:18:20 +13:00
.doctor.exs feat(PasswordReset): allow users to request and reset their password. (#22) 2022-11-02 18:18:20 +13:00
.formatter.exs feat(Ash.PlugHelpers): Support standard actor configuration. (#16) 2022-10-31 16:43:00 +13:00
.gitignore chore: install and configure dialyxir. 2022-09-28 10:11:00 +13:00
.tool-versions feat(PasswordReset): allow users to request and reset their password. (#22) 2022-11-02 18:18:20 +13:00
CHANGELOG.md chore: release version v0.3.0 2022-10-31 03:56:53 +00:00
mix.exs feat(PasswordReset): allow users to request and reset their password. (#22) 2022-11-02 18:18:20 +13:00
mix.lock feat(PasswordReset): allow users to request and reset their password. (#22) 2022-11-02 18:18:20 +13:00
README.md chore: release version v0.3.0 2022-10-31 03:56:53 +00:00

AshAuthentication

AshAuthentication provides drop-in support for user authentication for users of the Ash framework. It is designed to be highly configurable, with sensible defaults covering the most common use-cases.

Installation

The package can be installed by adding ash_authentication to your list of dependencies in mix.exs:

def deps do
  [
    {:ash_authentication, "~> 0.3.0"}
  ]
end

Usage

This package assumes that you have Phoenix and Ash installed and configured. See their individual documentation for details.

Once installed you can easily add support for authentication by configuring one or more extensions onto your Ash resource:

defmodule MyApp.Accounts.User do
  use Ash.Resource,
    extensions: [AshAuthentication, AshAuthentication.PasswordAuthentication]

  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
  end

  password_authentication do
    identity_field :email
    hashed_password_field :hashed_password
  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 which builds a Plug.Router which routes incoming authentication requests to the correct provider and provides callbacks for you to manipulate the conn after success or failure.

If you're using AshAuthentication with Phoenix, then check out ash_authentication_phoenix which provides route helpers, a controller abstraction and LiveView components for easy set up.

Authentication Providers

Currently the only supported authentication provider is AshAuthentication.PasswordAuthentication which provides actions for registering and signing in users using an identifier and a password.

Planned future providers include:

  • OAuth 1.0
  • OAuth 2.0
  • OpenID Connect

Documentation

Documentation for the latest release will be available on hexdocs and for the main branch.

Contributing

  • To contribute updates, fixes or new features please fork and open a pull-request against main.
  • Please use conventional commits - this allows us to dynamically generate the changelog.
  • Feel free to ask any questions on out GitHub discussions page.