AE
Ash Elixir•3y ago
Jason

Assumption failed: Action does not correlate with an authentication strategy

Follow up question related to https://github.com/ash-project/ash/issues/516 The same error persists after adding change set_context(%{strategy_name: :password})
update :change_user_timezone do
argument :user_timezone, :string do
allow_nil? true
end

change set_attribute(:user_timezone, arg(:user_timezone))
end

update :change_user_password do
argument :hashed_password, :string do
allow_nil? true
end

argument :password_confirmation, :string do
allow_nil? true
sensitive? true
end

argument :password, :string do
allow_nil? true
sensitive? true
end

# https://github.com/ash-project/ash/issues/516
change set_context(%{strategy_name: :password}) #### THIS DIDN"T FIX THE PROBLEM
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation

change AshAuthentication.Strategy.Password.HashPasswordChange
change AshAuthentication.GenerateTokenChange
update :change_user_timezone do
argument :user_timezone, :string do
allow_nil? true
end

change set_attribute(:user_timezone, arg(:user_timezone))
end

update :change_user_password do
argument :hashed_password, :string do
allow_nil? true
end

argument :password_confirmation, :string do
allow_nil? true
sensitive? true
end

argument :password, :string do
allow_nil? true
sensitive? true
end

# https://github.com/ash-project/ash/issues/516
change set_context(%{strategy_name: :password}) #### THIS DIDN"T FIX THE PROBLEM
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation

change AshAuthentication.Strategy.Password.HashPasswordChange
change AshAuthentication.GenerateTokenChange
GitHub
This error was unhandled because it did not implement the `AshPhoen...
Describe the bug The following error when running validation of a password change form. iex(1)> [debug] HANDLE EVENT View: MyAppWeb.UserLive.UserSettings Event: "validate_password&a...
33 Replies
ZachDaniel
ZachDaniel•3y ago
🤔 I summon the great and powerful @jart (when he has time)
jart
jart•3y ago
Quick Q: is your password strategy named :password? It will be if it's just password do
Jason
JasonOP•3y ago
Does this answer your question?
strategies do
password :password do
identity_field :username
hashed_password_field(:hashed_password)

resettable do
sender(MyApp.Accounts.User.Senders.SendPasswordResetEmail)
end
end
end
strategies do
password :password do
identity_field :username
hashed_password_field(:hashed_password)

resettable do
sender(MyApp.Accounts.User.Senders.SendPasswordResetEmail)
end
end
end
jart
jart•3y ago
yes
ZachDaniel
ZachDaniel•3y ago
Do both of those changes know to check the context? or, the validation and changes?
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation

change AshAuthentication.Strategy.Password.HashPasswordChange
change AshAuthentication.GenerateTokenChange
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation

change AshAuthentication.Strategy.Password.HashPasswordChange
change AshAuthentication.GenerateTokenChange
jart
jart•3y ago
please hold I'd be pretty surprised if they don't - they're used all over the place found the problem.
jasono
jasono•3y ago
I will be away for a while. sorry
jart
jart•3y ago
PasswordValidationConfirmation only looks in the changeset context because the other context isn't passed in to validations I think we should make it take strategy_name as an option too
ZachDaniel
ZachDaniel•3y ago
Not sure I follow
jart
jart•3y ago
@callback validate(Ash.Changeset.t(), Keyword.t()) :: :ok | {:error, term}
@callback validate(Ash.Changeset.t(), Keyword.t()) :: :ok | {:error, term}
the set_context builtin sets the "action context" but validations don't see that
ZachDaniel
ZachDaniel•3y ago
The context is in changeset.context Which is a very confusing thing I see now But they aren’t the same thing
jart
jart•3y ago
are you sure?
ZachDaniel
ZachDaniel•3y ago
Hm… Pretty sure?
jart
jart•3y ago
@jasono can you try using the improvement/pass-strategy-name-as-option-to-password-confirmation-validation branch for me? And changing validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation to validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation, strategy_name: :password please?
jasono
jasono•3y ago
Sure. Thanks
ZachDaniel
ZachDaniel•3y ago
Wait is @Jason and @jasono the same person?
jasono
jasono•3y ago
Both are mine but I didn't know two IDs can be used in one server.
Jason
JasonOP•3y ago
@jart Is this branch for ash_authentication_phoenix that I should try?
jart
jart•3y ago
no, ash_authentication
Jason
JasonOP•3y ago
got it. @jart I may be doing something wrong, but I get this now.
== Compilation error in file lib/MyApp/accounts/resources/user.ex ==
** (UndefinedFunctionError) function AshPostgres.DataLayer.dsl_patches/0 is undefined or private
(ash_postgres 1.3.3) AshPostgres.DataLayer.dsl_patches()
(spark 0.4.5) lib/spark/dsl/extension.ex:1785: anonymous fn/2 in Spark.Dsl.Extension.get_entity_dsl_patches/2
(elixir 1.14.1) lib/enum.ex:4249: Enum.flat_map_list/2
(spark 0.4.5) lib/spark/dsl/extension.ex:1784: Spark.Dsl.Extension.get_entity_dsl_patches/2
(ash_admin 0.7.1) expanding macro: AshAdmin.Resource.admin/1
lib/MyApp/accounts/resources/user.ex:8: MyApp.Accounts.User (module)
== Compilation error in file lib/MyApp/accounts/resources/user.ex ==
** (UndefinedFunctionError) function AshPostgres.DataLayer.dsl_patches/0 is undefined or private
(ash_postgres 1.3.3) AshPostgres.DataLayer.dsl_patches()
(spark 0.4.5) lib/spark/dsl/extension.ex:1785: anonymous fn/2 in Spark.Dsl.Extension.get_entity_dsl_patches/2
(elixir 1.14.1) lib/enum.ex:4249: Enum.flat_map_list/2
(spark 0.4.5) lib/spark/dsl/extension.ex:1784: Spark.Dsl.Extension.get_entity_dsl_patches/2
(ash_admin 0.7.1) expanding macro: AshAdmin.Resource.admin/1
lib/MyApp/accounts/resources/user.ex:8: MyApp.Accounts.User (module)
user.ex:8 is this admin do actor? true end but if I comment these out, a similar error then happens on the next line which is
authentication do
authentication do
== Compilation error in file lib/MyApp/accounts/resources/user.ex ==
** (UndefinedFunctionError) function AshPostgres.DataLayer.dsl_patches/0 is undefined or private
(ash_postgres 1.3.3) AshPostgres.DataLayer.dsl_patches()
(spark 0.4.5) lib/spark/dsl/extension.ex:1785: anonymous fn/2 in Spark.Dsl.Extension.get_entity_dsl_patches/2
(elixir 1.14.1) lib/enum.ex:4249: Enum.flat_map_list/2
(spark 0.4.5) lib/spark/dsl/extension.ex:1784: Spark.Dsl.Extension.get_entity_dsl_patches/2
(ash_authentication 3.9.3) expanding macro: AshAuthentication.authentication/1
lib/MyApp/accounts/resources/user.ex:12: MyApp.Accounts.User (module)
== Compilation error in file lib/MyApp/accounts/resources/user.ex ==
** (UndefinedFunctionError) function AshPostgres.DataLayer.dsl_patches/0 is undefined or private
(ash_postgres 1.3.3) AshPostgres.DataLayer.dsl_patches()
(spark 0.4.5) lib/spark/dsl/extension.ex:1785: anonymous fn/2 in Spark.Dsl.Extension.get_entity_dsl_patches/2
(elixir 1.14.1) lib/enum.ex:4249: Enum.flat_map_list/2
(spark 0.4.5) lib/spark/dsl/extension.ex:1784: Spark.Dsl.Extension.get_entity_dsl_patches/2
(ash_authentication 3.9.3) expanding macro: AshAuthentication.authentication/1
lib/MyApp/accounts/resources/user.ex:12: MyApp.Accounts.User (module)
ZachDaniel
ZachDaniel•3y ago
I think you need to upgrade ash and ash_postgres to use that latest version
Jason
JasonOP•3y ago
Okay. that's kind of what I was suspecting. hold on hmm... no luck. Still the same "Assumption failed: Action does not correlate with an authentication strategy" error.
iex(1)> [debug] HANDLE EVENT
View: MyAppWeb.UserLive.UserSettings
Event: "validate_password"
Parameters: %{"_csrf_token" => "FzJZBBplBDkSMnk8OC10MmJUBBkTLmY7tkkcV-hQAmNvYNLu41pAcaPm", "_target" => ["_csrf_token"], "form" => %{"current_password" => "[FILTERED]", "email" => "[email protected]", "password" => "[FILTERED]", "password_confirmation" => "[FILTERED]"}}
iex(1)> [debug] Replied in 1ms
iex(1)> [warning] Unhandled error in form submission for MyApp.Accounts.User.update_user_password

This error was unhandled because it did not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Framework.AssumptionFailed) Assumption failed: Action does not correlate with an authentication strategy

This should not be possible, please report a detailed bug at:

https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=



<action definition>
...
change set_context(%{strategy_name: :password})
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation

change AshAuthentication.Strategy.Password.HashPasswordChange
change AshAuthentication.GenerateTokenChange
iex(1)> [debug] HANDLE EVENT
View: MyAppWeb.UserLive.UserSettings
Event: "validate_password"
Parameters: %{"_csrf_token" => "FzJZBBplBDkSMnk8OC10MmJUBBkTLmY7tkkcV-hQAmNvYNLu41pAcaPm", "_target" => ["_csrf_token"], "form" => %{"current_password" => "[FILTERED]", "email" => "[email protected]", "password" => "[FILTERED]", "password_confirmation" => "[FILTERED]"}}
iex(1)> [debug] Replied in 1ms
iex(1)> [warning] Unhandled error in form submission for MyApp.Accounts.User.update_user_password

This error was unhandled because it did not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Framework.AssumptionFailed) Assumption failed: Action does not correlate with an authentication strategy

This should not be possible, please report a detailed bug at:

https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=



<action definition>
...
change set_context(%{strategy_name: :password})
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation

change AshAuthentication.Strategy.Password.HashPasswordChange
change AshAuthentication.GenerateTokenChange
jart
jart•3y ago
did you change the validate line?
Jason
JasonOP•3y ago
oops.. one sec.
== Compilation error in file lib/MyApp/accounts/resources/user.ex ==
** (Spark.Error.DslError) [MyApp.Accounts.User]
actions -> validate:
unknown options [:strategy_name], valid options are: [:validation, :where, :only_when_valid?, :message, :description, :before_action?]
lib/MyApp/accounts/resources/user.ex:248: (module)
(elixir 1.14.1) lib/kernel/parallel_compiler.ex:346: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7
== Compilation error in file lib/MyApp/accounts/resources/user.ex ==
** (Spark.Error.DslError) [MyApp.Accounts.User]
actions -> validate:
unknown options [:strategy_name], valid options are: [:validation, :where, :only_when_valid?, :message, :description, :before_action?]
lib/MyApp/accounts/resources/user.ex:248: (module)
(elixir 1.14.1) lib/kernel/parallel_compiler.ex:346: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7
ZachDaniel
ZachDaniel•3y ago
it should be {Module, strategy_name: :password}
jart
jart•3y ago
doh
Jason
JasonOP•3y ago
You mean like this? validate {AshAuthentication.Strategy.Password.PasswordConfirmationValidation, strategy_name: :password}
ZachDaniel
ZachDaniel•3y ago
yep! Since its an option specific to that validation
Jason
JasonOP•3y ago
iex(1)> [warning] Unhandled error in form submission for MyApp.Accounts.User.update_user_password

This error was unhandled because it did not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Framework.AssumptionFailed) Assumption failed: Action does not correlate with an authentication strategy

This should not be possible, please report a detailed bug at:

https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=
iex(1)> [warning] Unhandled error in form submission for MyApp.Accounts.User.update_user_password

This error was unhandled because it did not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Framework.AssumptionFailed) Assumption failed: Action does not correlate with an authentication strategy

This should not be possible, please report a detailed bug at:

https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=
ZachDaniel
ZachDaniel•3y ago
hmm...do you have an update_user_password and a change_user_password action? or did you change the name of the action?
Jason
JasonOP•3y ago
I didn't realize I had both. Let me remove one 😦 It's working!!! Thank you both very much!!
jart
jart•3y ago
Enjoy! I'll do a release of ash_authentication with that fix.

Did you find this page helpful?