The Ash Authentication framework
Find a file
2022-12-16 11:49:39 +13:00
.devcontainer chore(devcontainer): store Dialyzer PLTs in a volume. 2022-12-16 11:49:39 +13:00
.github chore(ci): Use my PAT to create releases. 2022-12-15 10:06:24 +13:00
config improvement(Jwt)!: Use token signing secret into the DSL. 2022-12-12 10:45:28 +13:00
dev improvement!: Major redesign of DSL and code structure. (#35) 2022-11-23 09:09:41 +13:00
documentation/getting_started improvement(Jwt)!: Use token signing secret into the DSL. 2022-12-12 10:45:28 +13:00
lib feat: Add option to store all tokens when they're created. (#91) 2022-12-14 15:06:13 +13:00
priv improvement(Confirmation): Store confirmation changes in the token resource. 2022-12-05 10:48:23 +13:00
test feat: Add option to store all tokens when they're created. (#91) 2022-12-14 15:06:13 +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: Add option to store all tokens when they're created. (#91) 2022-12-14 15:06:13 +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 v3.1.0 2022-12-14 19:00:36 +00:00
LICENSE improvement!: Major redesign of DSL and code structure. (#35) 2022-11-23 09:09:41 +13:00
mix.exs chore: release version v3.1.0 2022-12-14 19:00:36 +00:00
mix.lock chore(deps-dev): bump ash_postgres from 1.2.1 to 1.2.3 (#96) 2022-12-16 09:02:42 +13:00
README.md chore: release version v3.1.0 2022-12-14 19:00:36 +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.

Warning

This is beta software. Please don't use it without talking to us!

Installation

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

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

Usage

This package assumes that you have Ash installed and configured. See the Ash documentation for details.

Once installed you can easily add support for authentication by adding the AshAuthentication extension to your resource:

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

  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

    strategies do
      password do
        identity_field :email
        hashed_password_field :hashed_password
      end
    end
  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 that 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 Strategies

Currently supported strategies:

  1. AshAuthentication.Strategy.Password
    • authenticate users against your local database using a unique identity (such as username or email address) and a password.
  2. AshAuthentication.Strategy.OAuth2
    • authenticate using local or remote OAuth 2.0 compatible services.

Documentation

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

Additional support can be found on the GitHub discussions page and the Ash Discord.

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.

Licence

AshAuthentication is licensed under the terms of the MIT license. See the LICENSE file in this repository for details.