AshAuthentication with an already existing auth flow
I'm integrating Ash with a system that already has an authentication workflow. It's a passwordless flow that sends an OTP to the user's email and then generates a token for them, assuming everything checks out. I see that many Ash libraries integrate nicely with AshAuthentication. I noticed in the documentation that there's a method to integrate custom strategies. However, as I'm new to this, I'm having trouble fully understanding the documentation. The link can be found here: https://hexdocs.pm/ash_authentication/custom-strategy.html
Can I integrate our existing auth flow into AshAuthentication using the custom strategy model? These OTPs are used for registration, verifying the user before updating certain information (e.g., updating their email), verifying their new email, and logging in. If it's possible, I'd like to integrate it to benefit from using it. I'll just have to buckle down and do my best to learn.
If there's an easier way to integrate while maintaining compatibility with other Ash libraries, please let me know. Ultimately, I want my authentication system to work seamlessly with all the resources and tools I add.
5 Replies
Solution
Honestly, there isn't much need to integrate it as a custom strategy
AshAuthentication's job is just to set the actor for requests
You're free to do that however else you see fit
Just use
Ash.PlugHelpers.set_actor
somewhere in your pipeline and all the Ash API extensions will key off of that.
And then in your live views etc, you just have to provide the actor to calls to AshAh, so as long as I'm setting the actor then it's effectively working the same as the AshAuthentication library? No need to do anything special to get it to work with other libraries?
Does the AshAuthentication automatically have to put the actor in things like LiveViews or is that done automatically with that library?
It does have some tools like an on mount hook to set the actor, but those are just generated into the end user's codebase
so you can just set up you own on_mount hook and set the actor
Awesome, thanks very much!