Ash Authentication ApiKey strategy

How is the correct way to create a ApiKey to be used for users. https://gist.github.com/phsacramento/ad22e42fb4c357d99b694fb8ed511b52 On this example, i'm not able to get generated ApiKey using Api's request.
Gist
api_key.ex
GitHub Gist: instantly share code, notes, and snippets.
3 Replies
ZachDaniel
ZachDaniel2mo ago
You can add metadata :plaintext_api_key, :string, allow_nil?: false ah, actually it may only be AshGraphql that supports this You can add a metadata function to expose route metadata
post :create, metadata: fn subject, result, request -> %{api_key: result.__metadata__.plaintext_api_key} end
post :create, metadata: fn subject, result, request -> %{api_key: result.__metadata__.plaintext_api_key} end
something like that
PH
PHOP2mo ago
So, using REST with ApiKey only will not work?
ZachDaniel
ZachDaniel2mo ago
No you can do it You just might have to do one of two things: 1. use that metadata example I gave above, that adds the api key to metadata 2. write a custom generic action that returns the api key and hook that up.

Did you find this page helpful?