tmariaz
API token is invalid_token when decoding with guardian
My API which authenticates via auth0 and returns the access_token. During the callback, the access_token throws invalid_token error. Not sure what is going on.
Here are my codes.
router.ex
scope "/auth", PxrfWeb do
pipe_through [:browser]
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
end
config.exs
config :pxrf, Pxrf.Auth.Guardian,
issuer: "https://myissuer.xx.auth0.com/",
secret_key: "xxxxxxxx"
auth_controller.ex
...
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, %{"state" => state} = _params) do
IO.inspect(auth)
token = auth.extra.raw_info.token.access_token
case Pxrf.Auth.Guardian.decode_and_verify(token) do
{:ok, claims} ->
user = Accounts.get_user_by_username(claims["sub"])
{:error, _reason} ->
nil
end
end
...
When I run the following
iex> Guardian.decode_and_verify("eyJasds-----access-token-")
{:error, :invalid_token}
Been breaking my head for the past couple of days and can’t figure it out what is wrong. Looks like all my configuration and setup in the auth0 application seems to be correct. But still no luck.
First Post!
tmariaz
Tried 2 methods
Method 1
- Login via frontend to auth0
- Read the token and pass it to api
- Backend API is to validate the token
Method 2
- Send the request from api to auth0
- Callback should validate the return struct
- There the token shows invalid_token when decoding it.
Not sure which method is correct?
0
Last Post!
tmariaz
Hi… sorry for late reply…
I just happen to try with the following and it still throws invalid_token
plug Guardian.Plug.VerifyHeader, scheme: "Bearer", claims: %{"typ" => "JWT"}
Should I just remove the claims altogether? Without claims it works fine. Or is this security issue?
0
Popular in Questions
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









