Ash Authentication password strategy token error when following Getting Started Guide

Following the Ash Authentication Phoenix Getting Started Guide, I get the following error message when trying to save/compile the user.ex resource:

    ** (Spark.Error.DslError) [nil]
 authentication -> tokens -> enabled?:
  The `:password` authentication strategy requires tokens be enabled.

To fix this error you can either:
  1. disable the `:password` strategy, or
  2. enable tokens.

The authentication section of the user.ex resource is as specified in the guide:

  authentication do
    strategies do
      password :password do
        identity_field :email
      end
    end
    ...
 end

I tried adding “sign_in_tokens_enabled? true” in the password section of authentication. However, they did not work either.

How would I enable the tokens to be able to use the password authentication strategy? Docs say tokens are enabled by default?

I expect I am overlooking something obvious.

Any help would be appreciated. Thanks to everyone for the great work on Ash 3.0.

There have been some changes to this just recently that are likely the cause of the confusion.

authentication do
    tokens do
      token_resource MyApp.Accounts.Token
      signing_secret fn _, _ ->
        Application.fetch_env(:my_app, :token_signing_secret)
      end
    end
end

You need to configure the tokens resource, or set sign_in_tokens_enabled? false.

Make sure to check the very latest version of the docs, and then if you could please open an issue on ash_authentication pointing out the docs that caused confusion and we will address.

1 Like

Yeah I ran into that one too. To fix the immediate problem, you just need to add enabled? true in the tokens section:

    tokens do
      enabled? true # Add this line
      token_resource Example.Accounts.Token
      signing_secret Example.Accounts.Secrets
    end
3 Likes