benswift
I’ve got an AshPhoenix app which needs to make authenticated HTTP requests to other APIs. I’m using Req.
These requests need an auth token, which I’m currently storing as a field on the User resource (the resource was originally created as part of the AshAuthentication setup).
The req “call site” is several layers deep in application code, and I’d like to avoid having to pass the auth/user info through all those layers if at all possible. So I’d like to be able to pull the current_user assign from the current session as close as possible to where I create (and perform) the Req.Request.
I’ve tried Ash.PlugHelpers.get_context as a :plug option in Req, but that returns nil because that’s the conn that Req is using, not the conn from the current user session.
There used to be (in Ash v2) a way of getting the current context (including actor from the process dict, but it doesn’t seem like that’s possible anymore? is there an alternative?
Sorry that’s all kindof abstract. I can fake up some minimal examples if you need me to.
Trending in Questions
Other Trending Topics
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
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jackalcooper
Does the library you are using support putting a custom client? I was trying to do some response rewrite for the library
InstructorLitethat is usingreq, so I add something likeand set the custom client option
adapter_context: [http_client: MyClient,benswift
Yeah so you mean create a custom client that puts/gets stuff from the process dict like the old “Store Process in Context” stuff used to do?
I tracked down the docs page for that stuff, it was deleted in
d55864713a32but the commit message didn’t have a specific rationale - I presume it was just a general “using process dicts for state is gross and probably makes parallel testing hard” vibes.Anyway, thanks for your idea - I’m honestly thinking that the best option is to rearchitect my code so that there’s fewer layers of indirection between the action (where I do know the actor) and the code that creates the
Req.Requeststruct (where I need the auth token).zachdaniel
This is what I’d recommend.
benswift
Thanks. That’s what I did. As an added bonus testing is easier