danww
Hi there,
I have an Elm frontend app, performing user login and token creation with Auth0 Lock, and then performing requests to a Phoenix API on the backend, passing the JWT token from Elm to Phoenix in an “Authorization: Bearer ” header.
I want the Phoenix API to be able to verify the supplied token in order to auth the request from the client app.
I’m currently using Guardian(API Reference — Guardian v2.4.0), configured along these lines:
Can I verify a JWToken created by Auth0 ? · Issue #211 · ueberauth/guardian · GitHub
I’m new to Phoenix.
I can’t get past ‘plug Guardian.Plug.EnsureAuthenticated’.
I’m not sure how to debug/inspect router/pipeline.
Ideally, I’d like Guardian.Plug.EnsureAuthenticated to reside in the pipeline, rather than in each controller.
Am I correct in assuming that Guardian will actually verify the supplied token with Auth0?
Because there doesn’t seem to be any provision in the config for the Auth0 ‘client_id’, which I expect would be necessary.
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
krapans
How do you pass in the request from front-end the JWT token?
danww
I’m adding a header (
Authorization: Bearer <token>) to the request.I understand Guardian should find and verify this token with the
plug Guardian.Plug.VerifyHeader, realm: "Bearer"in the pipeline. I’m using the same Auth0 secret in the config for both client and server.krapans
Ok, from this what you are saying everything sounds fine. I guess you need provide some code examples, so maybe then I could check out it and give you feedback.
danww
Okay - here’s my code. Let me know if I’ve missed anything out.
config.exs
###router.ex
Serializer
krapans
For me, this looks like this
plug Guardian.Plug.VerifyHeader, realm: "Bearer"And Serializer like this
danww
I currently don’t have Ecto or a Repo set up - not sure I’ll need one, since this API is going to talk straight to another third-party API, so the Serializer isn’t really required, in my case.
I’m still not getting past the VerifyHeader plug - EnsureAuthenticated is failing.
I’m thinking my issue is around the Guardian config. I’m wondering if I’m missing something.
bryanjos
Was on a project recently with auth0 and guardian and got it to work. I think maybe try setting verify_issuer to false
danww
I started from the beginning, setting up Guardian from scratch, and it worked.
I’m still not clear why it wasn’t working in the first instance.
If anyone is interested, I did the following:
mix.exs:
…then ran
mix deps.getconfig.exs
allowed_algosto HS256issuerto Auth0 domainverify_issuerto false. This may have been what solved it, although I did try changing this in my initial attempt.secret_keyto Auth0 client secretserializer.ex
router.ex
:apipipeline, as followsAnd that seemed to do the trick.
Thanks all, for your help
mihaimartalogu
Late to the party, but I use the same scenario, and I just managed to make it work after a bit of pain.
I had to:
Authorization API signs JWTs as RS256 when HS256 is selected - Auth0 Community
Note that, as mentioned in %FunctionClauseError{arity: 1, function: :jose_jwk, module: Guardian} · Issue #291 · ueberauth/guardian · GitHub, you can’t call JOSE.JWK.from_pem/1 from config.exs, so I had to move that call into the application start/2 function:
Hope this helps
arcseldon
This blog details how the OP performed the same JWT Verification of Auth0 access token. Code also provided.
https://madebymany.com/stories/how-we-built-passwordless-authentication-with-auth0-and-elixir-phoenix