Couldn't recognise the signer algorithm

Couldn't recognize the signer algorithm.
Possible values are:

["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]
Couldn't recognize the signer algorithm.
Possible values are:

["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]
Having this issue after implementing Ash Auth
46 Replies
talha-azeem
talha-azeemOP•3y ago
@jart can you please help me out here?
jart
jart•3y ago
Hi there. You turned on tokens? Can I see your config?
talha-azeem
talha-azeemOP•3y ago
yes let me share it Here it is:
# General application configuration
import Config

config :dummy,
ecto_repos: [Dummy.Repo],
ash_apis: [
Dummy.Experiments,
Dummy.Hardware
]

config :dummy,
ash_apis: [Dummy.Accounts]

config :dummy,
ecto_repos: [Dummy.Repo]

config :ash, :use_all_identities_in_manage_relationship?, false

config :dummy, :token_signing_secret, signing_secret: "<dummy_secret>"
# General application configuration
import Config

config :dummy,
ecto_repos: [Dummy.Repo],
ash_apis: [
Dummy.Experiments,
Dummy.Hardware
]

config :dummy,
ash_apis: [Dummy.Accounts]

config :dummy,
ecto_repos: [Dummy.Repo]

config :ash, :use_all_identities_in_manage_relationship?, false

config :dummy, :token_signing_secret, signing_secret: "<dummy_secret>"
Removed some comments from it so i can share it here
jart
jart•3y ago
sorry, I meant the authentication DSL section from your user resource
talha-azeem
talha-azeemOP•3y ago
@jart here it is:
defmodule Dummy.Accounts.User do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
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 Dummy.Accounts

strategies do
password :password do
identity_field :email
end
end

tokens do
enabled? true
token_resource Dummy.Accounts.Token
signing_secret fn _, _ ->
Application.fetch_env(:dummy, :token_signing_secret)
end
end
end

postgres do
table "users"
repo Dummy.Repo
end

identities do
identity :unique_email, [:email]
end
end
defmodule Dummy.Accounts.User do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
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 Dummy.Accounts

strategies do
password :password do
identity_field :email
end
end

tokens do
enabled? true
token_resource Dummy.Accounts.Token
signing_secret fn _, _ ->
Application.fetch_env(:dummy, :token_signing_secret)
end
end
end

postgres do
table "users"
repo Dummy.Repo
end

identities do
identity :unique_email, [:email]
end
end
jart
jart•3y ago
What version of Joken did hex bring in? nvm. it hasn't had a release in a year
talha-azeem
talha-azeemOP•3y ago
joken is 2.5.0
jart
jart•3y ago
Can you tell me what the result of calling AshAuthentication.Info.authentication_tokens_signing_algorithm!(Dummy.Accounts.User) is please? or is the above a compile-time error?
talha-azeem
talha-azeemOP•3y ago
Let me check @jart I am new to ash framework. how can i get the result of the above? 😅
jart
jart•3y ago
just call it from iex
talha-azeem
talha-azeemOP•3y ago
okay
iex(3)> AshAuthentication.Info.authentication_tokens_signing_algorithm!(Dummy.Accounts.User)
"HS256"
iex(3)> AshAuthentication.Info.authentication_tokens_signing_algorithm!(Dummy.Accounts.User)
"HS256"
jart
jart•3y ago
okay well that's fine. where are you encountering the error?
talha-azeem
talha-azeemOP•3y ago
After pressing the register button i get this
No description
jart
jart•3y ago
that's so weird. are you using a custom register action or just the one that ash auth defined?
talha-azeem
talha-azeemOP•3y ago
ash auth defined
jart
jart•3y ago
Can you run AshAuthentication.Info.strategy_for_action!(Dummy.Accounts.User, :register_with_password) please? if it returns the strategy then I can't see why it would be failing
talha-azeem
talha-azeemOP•3y ago
config :dummy, :token_signing_secret, signing_secret: "<dummy_secret>"
config :dummy, :token_signing_secret, signing_secret: "<dummy_secret>"
I ran mix phx.gen.secret 32 and added that here.
iex(4)> AshAuthentication.Info.strategy_for_action!(DataDrivenMicroscopy.Accounts.User, :register_with_password)
%AshAuthentication.Strategy.Password{
identity_field: :email,
hashed_password_field: :hashed_password,
hash_provider: AshAuthentication.BcryptProvider,
confirmation_required?: true,
password_field: :password,
password_confirmation_field: :password_confirmation,
register_action_name: :register_with_password,
sign_in_action_name: :sign_in_with_password,
resettable: [],
name: :password,
provider: :password,
resource: DataDrivenMicroscopy.Accounts.User
}
iex(4)> AshAuthentication.Info.strategy_for_action!(DataDrivenMicroscopy.Accounts.User, :register_with_password)
%AshAuthentication.Strategy.Password{
identity_field: :email,
hashed_password_field: :hashed_password,
hash_provider: AshAuthentication.BcryptProvider,
confirmation_required?: true,
password_field: :password,
password_confirmation_field: :password_confirmation,
register_action_name: :register_with_password,
sign_in_action_name: :sign_in_with_password,
resettable: [],
name: :password,
provider: :password,
resource: DataDrivenMicroscopy.Accounts.User
}
@jart what should i be replacing <dummy_secret> with?
jart
jart•3y ago
it's fine how it is you're getting an error about the signing algorithm not the secret I am expecting that calling this will cause an exception: AshAuthentication.Jwt.Config.token_signer(Dummy.Accounts.User) if it works it will contain your secret so don't paste it here
talha-azeem
talha-azeemOP•3y ago
it doesn't work
** (Joken.Error) Couldn't recognize the signer algorithm.

Possible values are:

["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

(joken 2.5.0) lib/joken/signer.ex:102: Joken.Signer.create/3
iex:5: (file)
** (Joken.Error) Couldn't recognize the signer algorithm.

Possible values are:

["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

(joken 2.5.0) lib/joken/signer.ex:102: Joken.Signer.create/3
iex:5: (file)
jart
jart•3y ago
just out of interest can you try this: AshAuthentication.Jwt.Config.token_signer(Dummy.Accounts.User, signing_algorithm: "HS256")
talha-azeem
talha-azeemOP•3y ago
same error
jart
jart•3y ago
that makes literally no sense. can you run mix clean --deps and recompile and try it again?
talha-azeem
talha-azeemOP•3y ago
sure
jart
jart•3y ago
looks like you're not the only one who has seen this: https://github.com/joken-elixir/joken/issues/369
GitHub
Intermittent ** (Joken.Error) Couldn't recognize the signer algorit...
Hey I&#39;m doing the following, signer = Joken.Signer.create(&quot;HS256&quot;, @config[:api_secret]) But from time to time I get: ** (Joken.Error) Couldn&#39;t recognize the signe...
talha-azeem
talha-azeemOP•3y ago
what should i do to fix it? 😅
jart
jart•3y ago
recompiling didn't work?
talha-azeem
talha-azeemOP•3y ago
compilin to check It worked strange
jart
jart•3y ago
that is so frustrating
talha-azeem
talha-azeemOP•3y ago
Thank you for your help @jart I really appreciate it yes indeed It happened again today. Can you please look into it because compiling the deps again and again is frustrating. and this time this issue is persisting.
ZachDaniel
ZachDaniel•3y ago
Unfortunately that is not our library, there is not so much that we can do. And keep in mind, this is free and open source software, we encourage the community to help with issues like this. I would suggest commenting on that issue, also Actually...I'm not entirely sure that issue reflects what is happening here that person said it was their own fault Are you setting signing_algorithm in your DSL anywhere? nvm, the fact that this line:
AshAuthentication.Jwt.Config.token_signer(Dummy.Accounts.User, signing_algorithm: "HS256")
AshAuthentication.Jwt.Config.token_signer(Dummy.Accounts.User, signing_algorithm: "HS256")
Doesn't work tells me that the issue can't be on our end TBH Its strange that you're the only one having this issue though. Is there anything special about your development set up that you can think of? You said that the issue is persisting does that mean compiling dependencies isn't helping?
jart
jart•3y ago
@talha-azeem sorry to hear it’s still going wrong. Can you call Joken.Signer.create("HS256", "s3cret") from iex? If not I think you should raise an issue on the joken repo and I’ll jump in and backfill as much info as I can.
ZachDaniel
ZachDaniel•3y ago
Will mark this as solved & close it for now, but keen to keep the conversation going if this ends up being an issue in AshAuthentication. For now we don't really have a good way of knowing where the issue is/why its coming up for you and not others.
talha-azeem
talha-azeemOP•3y ago
is ash_authentication_phoenix yours? running this gives me %Joken.Signer struct @jart https://discord.com/channels/711271361523351632/1067733106662047764 I enabled tokens in his app as well just to check if i am missing something but his app gives the same error as well.
ZachDaniel
ZachDaniel•3y ago
Are you on windows? Tokens are working for me just fine in my app, I’m just trying to understand what might be different about your setup.
talha-azeem
talha-azeemOP•3y ago
I am using MacOS
ZachDaniel
ZachDaniel•3y ago
Can you push the changes you made to that example app up as a fork? I will clone it and see if I get the same results
talha-azeem
talha-azeemOP•3y ago
okay let me do that.
talha-azeem
talha-azeemOP•3y ago
GitHub
GitHub - talhaazeemmughal/ash_authentication_phoenix_example: The s...
The simplest password authentication with Ash Framework, Ash Authentication and Phoenix. - GitHub - talhaazeemmughal/ash_authentication_phoenix_example: The simplest password authentication with As...
talha-azeem
talha-azeemOP•3y ago
here is the forked version
ZachDaniel
ZachDaniel•3y ago
Found it 🙂 I don't know why the JWT library gives such a bad error here This config:
config :ash_auth_phoenix_example, :token_signing_secret, signing_secret: "dummy salt"
config :ash_auth_phoenix_example, :token_signing_secret, signing_secret: "dummy salt"
Combined with this:
signing_secret fn _, _ ->
Application.fetch_env(:ash_auth_phoenix_example, :token_signing_secret)
end
signing_secret fn _, _ ->
Application.fetch_env(:ash_auth_phoenix_example, :token_signing_secret)
end
Is returning {:ok, signing_secret: "dummy_salt"} causing us to call Joken.Signer.create(algorithm, signing_secret: "dummy_salt") The signing_secret fn _, _ -> callback should be returning {:ok, <string>} not {:ok, signing_secret: <string>} If the config was this instead:
config :ash_auth_phoenix_example, :token_signing_secret, "dummy salt"
config :ash_auth_phoenix_example, :token_signing_secret, "dummy salt"
Then it would work
talha-azeem
talha-azeemOP•3y ago
okay let me check yes it worked. Thank you so much It should be adding tokens automatically now, right?
ZachDaniel
ZachDaniel•3y ago
Do you want a token created for every session?
talha-azeem
talha-azeemOP•3y ago
yes
ZachDaniel
ZachDaniel•3y ago
You probably want this config in your tokens section then:
store_all_tokens? true
require_token_presence_for_authentication? true
store_all_tokens? true
require_token_presence_for_authentication? true
without store_all_tokens it only stores confirmation/reset tokens and with require_token_presence_for_authentication? it will look up tokens in the tokens table before authenticating
talha-azeem
talha-azeemOP•3y ago
Noted. Thank you @Zach Daniel . I have gotten really interested in it.
ZachDaniel
ZachDaniel•3y ago
I've made a PR to prevent this error in the future by validating the value better.

Did you find this page helpful?