AshAuthentication custom strategy UI

I am trying to implement a custom strategy that verifies the user login with some custom rules, but after following this documentation i am stuck on where to implement the UI (https://hexdocs.pm/ash_authentication/custom-strategy.html) Is there any demo project that can serve as a reference for this? Do i just use UI Overrides? (https://hexdocs.pm/ash_authentication_phoenix/ui-overrides.html)
3 Replies
ZachDaniel
ZachDaniel3mo ago
i don't think there is a demo for it not sure how it works, you may need to spelunk
Ahrou
AhrouOP3mo ago
got busy suddenly but will try to look at the source code sometime, i saw there was an ash_authentication_firebase dep but it seems to use the same UI as the other OAuth2 strategies so there is no ui I tried to duplicate the Password Strategy from the source code hoping it would use the same for but nothing shows up i assume because it is linked to the original strategy struct, so will just try to make a new live view for the new custom strategy but am getting:
18:49:02.085 [error] ** (UndefinedFunctionError) function AshPhoenix.Form.fetch/2 is undefined (AshPhoenix.Form does not implement the Access behaviour

You can use the "struct.field" syntax to access struct fields. You can also use Access.key!/1 to access struct fields dynamically inside get_in/put_in/update_in)
(ash_phoenix 2.3.9) AshPhoenix.Form.fetch(#AshPhoenix.Form<resource: App.Auth.Account, action: :sign_in_with_cognito_password, type: :read, params: %{}, .........>, :email)
(elixir 1.18.4) lib/access.ex:322: Access.get/3
(plaza 0.1.0) lib/desk_web/live/cognito_password_sign_in.ex:30: anonymous fn/2 in DeskWeb.Live.CognitoPasswordSignIn.render/1
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:414: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
18:49:02.085 [error] ** (UndefinedFunctionError) function AshPhoenix.Form.fetch/2 is undefined (AshPhoenix.Form does not implement the Access behaviour

You can use the "struct.field" syntax to access struct fields. You can also use Access.key!/1 to access struct fields dynamically inside get_in/put_in/update_in)
(ash_phoenix 2.3.9) AshPhoenix.Form.fetch(#AshPhoenix.Form<resource: App.Auth.Account, action: :sign_in_with_cognito_password, type: :read, params: %{}, .........>, :email)
(elixir 1.18.4) lib/access.ex:322: Access.get/3
(plaza 0.1.0) lib/desk_web/live/cognito_password_sign_in.ex:30: anonymous fn/2 in DeskWeb.Live.CognitoPasswordSignIn.render/1
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:414: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
Ahrou
AhrouOP3mo ago
tried to follow this post https://elixirforum.com/t/customizing-ash-authentication-for-dummies-like-me/66206 so i have:
#on mount
api = AshAuthentication.Info.authentication_domain!(strategy.resource)
subject_name = AshAuthentication.Info.authentication_subject_name!(strategy.resource)

AshPhoenix.Form.for_action(strategy.resource, strategy.resettable.request_password_reset_action_name,
api: api,
as: to_string(subject_name),
context: Ash.Helpers.deep_merge_maps(%{}, %{strategy: strategy, private: %{ash_authentication?: true}})
)


# and this in render
<Phoenix.Component.form for={@form} phx-change="validate" phx-submit="submit">
<.input field={@form[:email]} />
<.input field={@form[:password]} />
<.button type="submit">Submit</.button>
</Phoenix.Component.form>
#on mount
api = AshAuthentication.Info.authentication_domain!(strategy.resource)
subject_name = AshAuthentication.Info.authentication_subject_name!(strategy.resource)

AshPhoenix.Form.for_action(strategy.resource, strategy.resettable.request_password_reset_action_name,
api: api,
as: to_string(subject_name),
context: Ash.Helpers.deep_merge_maps(%{}, %{strategy: strategy, private: %{ash_authentication?: true}})
)


# and this in render
<Phoenix.Component.form for={@form} phx-change="validate" phx-submit="submit">
<.input field={@form[:email]} />
<.input field={@form[:password]} />
<.button type="submit">Submit</.button>
</Phoenix.Component.form>
Elixir Programming Language Forum
Customizing ash_authentication for dummies (like me)
I’ve been needing to customize our sign in, register, reset password, and forgot password pages for months. Every time I took a look at the ash_authentication_phoenix pages/code I ran away crying. And blog posts like Customising Ash Authentication with Phoenix LiveView did not make it seem easier. After taking the plunge last night (due to ye...

Did you find this page helpful?