lcabrini

lcabrini

Cannot get Ash authentication to work with the JSON API

I have a user resource that looks more or less like that one in the Ash Authentication getting started doc, with one added field: role. Role can be one of admin, merchant, client. Only admins should be able to log in via the web frontend, merchants and clients should only be able to register and “sign in” (that is, receive a token) only via a JSON API.

At this time, I’m only interested in the password strategy.

On the web side, everything works well (registration is disabled, I seed an initial admin, who can log in and create more admins, if needed).

However, I cannot get authentication to work with the JSON API. I have followed the documentation for ash-authentication and ash-json-api as well as peeked at this: Ash authentication on mobile - #11 by lud which is the closest I have found to what I’m looking to do.

Right now I’m not sure if I have completely missunderstood everything or if I’m just missing out on some little part. I was expecting registration to be fairly straight-forward, but not even that seems to be working.

I have created a router as per the getting started guide for ash-json-api. Do I need a controller as well? The documentation says the router partly plays the role of a controller, the forum post above says to add a controller. I’m a bit lost here.

Could somebody explain the steps required to get authentication working together with JSON API? Or even better, if you are working on a project that does this and is open source, I unfortunately seem to be better at reading code than explanations, or so it would seem.

First 5 of 5 Posts Switch mode

zachdaniel

zachdaniel

Creator of Ash

This is definitely an area we intend to improve at some point. The tools are all there, it’s just a matter of providing the guidance of how to use them. I will let @jimsynz answer because he is much more familiar with AshAuthentication’s internals than I.

lcabrini

lcabrini OP

Yeah, I’ve noticed that Ash can really do a lot, but that the documentation, especially when it’s outside of the default use cases can be a bit lacking at times. I guess that’s normal for projects that move relatively fast. I’d be happy to help out in any way to rectify that situation.

jimsynz

jimsynz

Ash Core Team

Hi there.

Ash Authentication’s dev/test setup includes an example of using JSON:API for password registration. Can you give us more information about what’s not working?

lcabrini

lcabrini OP

Hi. Thanks for the pointer to the dev/test code. I’m looking through to see what I can figure out. To start off I’m trying to get registration to work. This is what I’m currently getting and I’m a little bit stumped, because I think if followed the documentation properly.

$ curl -X POST --data-raw '{"data": {"email": "foo@bar.bim", "password": "f00#b4Rb1mBAzzZ"}}' --header 'Accept: application/vnd.api+json' --header 'Content-Type: application/vnd.api+json' http://localhost:4000/api/accounts/users
{"errors":[{"code":"InvalidBody","id":"6f4fa33a-82ab-4840-a766-34fd349a0b19","status":"400","title":"Invalid Body","source":{"pointer":"data/email"},"detail":"Expected only defined properties, got key [\"data\", \"email\"]."},{"code":"InvalidBody","id":"b9be9233-73fa-4e1a-9188-5ae6d3735ed7","status":"400","title":"Invalid Body","source":{"pointer":"data/password"},"detail":"Expected only defined properties, got key [\"data\", \"password\"]."}],"jsonapi":{"version":"1.0"}}

Clearly I’m missing something or I’ve done something wrong. I just don’t really know what and I’m just running around in a circle at this point.

zachdaniel

zachdaniel

Creator of Ash

Have you followed the set up for the ash json api open api features? I’d suggest doing that and then you can look at your own api docs to see how it works :slight_smile:

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement