lud
Hello,
I’m trying out the Ash framework for the first time. I am building an API for a mobile app and I want to implement user authentication.
We are in a first-party app and server configuration, so after reading this I’m wondering if the following could be enough:
- An API endpoint accepting email/password and sending a token
- An API endpoint using Ash Token features
It’s the first time I’m doing a mobile app so I am not sure. But to me it looks like I do not need to implement OAuth2 or OID Connect.
What do you think?
Thanks!
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
D4no0
Usually if there is mobile involved, there is the google/ios authentication involved. They basically send you a JWT token instead of username/password that you can check for validity against their public certificates.
zachdaniel
If you can leverage oauth2 that would be ideal as ash_authentication has native support for that.
zachdaniel
Not that you need to, though. You can pretty easily create an endpoint that calls the
sign_in_with_passwordaction and extracts the token.lud
I’m trying to understand if I need OAuth2 in my context. What would be the benefits when I am in control of both the app and server?
zachdaniel
well, if you wanted to support social sign on, for example. If you want to provide username/password login, you definitely don’t need oauth2 for that. The suggestion isn’t for your application to be an oauth2 provider, that is definitely overkill (and its not something
ash_authenticationdoes for you).lud
Yes thanks for the distinction. I see too many apps implementing both OAuth2 provider and clients for authentication and it never makes sense.
For social sign on the token I would get would be provided by, say, facebook. That token would allow me to fetch user data from facebook, or get an OpenID payload. But it is not a token I would use from the mobile app to connect to my API and fetch user data from my server app API. So I still need a custom token delivered by my server app, OAuth2 as a client does not help here. Am I correct ?
zachdaniel
Correct. You’d want to implement the
passwordstrategy. That strategy will add all the actions that you need to your resources. I don’t think that a JSON endpoint is created for you for signing in, but if not it is something you should be able to do with a phoenix controller.lud
Yes thank you, that is what I intended to do
So ok for now I’ll just have that special endpoint and an API with token, no OAuth2 needed.
zachdaniel
Yep! That sounds right to me
lud
Hi again! I decided to tackle this tonight.
I am not sure I understand correctly. What exactly is
user.__metadata__.token?For now I’m just trying this from a test:
But I do not understand why the token is present in the user in the metadata. I created a
MyApp.Accounts.Tokenentity like the tutorial said, but now I understand that those are for server-side-only metadata about the tokens. Do they target that same token I found in my user struct metadata?It seems so.
So now I would like the user to sign-up and then be able to sign-in from different machines and revoke their login from a specific machine.
In the AuthController I did this in the
successcallback:I seems that the purpose is not relevant for Ash to work, though required. So I can add the machine based on the user agent or a custom header or field. And I can now write a basic test controller like this
And run my full test to see if it worked:
Now I realize that there is not really a question in my message
I’ll try to create another resource and have readable by the owner only.
I added this in my router:
And the new plug here:
But in the controller
Ash.get_actoris alwaysnil. I have seen that the plug only sets it inconn.private.ash.actor. So I guess I should write a custom plug to forbid some api routes to be accessed without authentication. Is that how you would do it? I do not need any public data on those routes.Or would you rather just always set an actor on the action, even if it is nil, and let the policies reject the calls?
Thank you for reading, sorry for that unstructured post
it took me a couple hours to write because I implemented the code along.