bponghneng
I’m trying to verify an AWS Cognito JWT. The closest help I have found is this thread:
https://forum.elixirforum.com/t/joken-using-joken-verify/10081/5
I’m attempting a similar technique:
authorization = conn |> get_req_header("authorization")
[authorizationHeaderValue | rest] = authorization
jwt = String.slice(authorizationHeaderValue, 7..1500)
awsJwks = Poison.decode!(~s({"keys":[{"alg":"RS256","e":"AQAB","kid":"hcju2zKBpJjOTDd214wkKnrRY9ApwTiPJq+Oe+q6Jz0=","kty":"RSA","n":"rDfAEMwYGBrol5mIA1aEcwtZBUgwYKcs8uVaLW64tZwcn9Nc4G6XMAw9igucWz-yt-4aFyKzw9mpBMqSUeNs7mDUczrMO4UbPn-5fN-cSgCKyLdAUjFKS8-L9O0tqXmBdEbtmferUrz2Nqt1pnCKU0gl2ZHb64hD98feBptqTYiCqh6VZnookBrjhvn9b0CHJnwEgPF__DeeSwlRYPt-pYpSCmI851zspLsnMwtoQQdfe1bL7H28OEa0-O4rRxcI_BJz79c7bHWllDMMhD51xmsn1rngCn8Y2tHIsGr_81Hx7k0Awma-ibJ8Zll8MNrJgmCG7ykz3bAfuDW20vKtpw","use":"sig"},{"alg":"RS256","e":"AQAB","kid":"ttY6v6AGiOqL+ZaDvyg953iG7RWLTwDVq9+cOa1hrZE=","kty":"RSA","n":"q70S6cdm28a0LRj_o8QP7Getgh-QygMbFFp_z-Yxjs1FkKrJva_yNYOdjiO5YC8Dqazcr6OEUYV6iSe7XyOvG6MeAh9Y9gvw_0HmFg-vYb_-pifht5C9E7iKRp5QIcyEO2rie-Gas7QyW8k1uTHJT68gxdoV8hverMwWw2H7L1Y7ec6-jN1tsq1ExYQbi8ELDxzCpeDF_e4FKp2COZEdV_CVN8qxdC6aBTIN7dSNPjXCOQSUv_gw_XIk_G_S2JDJCty_ffdiiXZItviIfi9WZP_2uW8xAo2KX2ssno_wVbTJ_XxxnWy6aFNeaW5yFzHNenSvjJGnKMgVRbkMClXLRQ","use":"sig"}]}))
token = Joken.token(jwt)
with_signer = token |> Joken.with_signer(Joken.rs256(JOSE.JWK.from_map(awsJwks)))
{:ok, claims} = with_signer |> Joken.verify!
BTW, in case it’s not obvious, the String.slice() is to trim off "Bearer " from the header value.
I only get an invalid signature error:
(MatchError) no match of right hand side value: {:error, "Invalid signature"}
FWIW, here is the token I’m trying to verify:
eyJraWQiOiJ0dFk2djZBR2lPcUwrWmFEdnlnOTUzaUc3UldMVHdEVnE5K2NPYTFoclpFPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI5MGY4MTY1Mi0yYTQ3LTQ2MzgtYTU2ZC01NGU1Y2YwNTAwMWMiLCJldmVudF9pZCI6ImQ0OWYwNjYxLTBjYWMtMTFlOC1hZjE3LTZiODc1OTYxNTIzOCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9XaHRwQ1hlb1UiLCJleHAiOjE1MTgwODMzMDcsImlhdCI6MTUxODA3OTcwNywianRpIjoiZGJlNGQ5N2MtZWE4ZC00NmYyLTliODYtMDUyYjA0N2VmNjM5IiwiY2xpZW50X2lkIjoidW80bDNkdDNsYWwxamEwNGNiZDVlN3F0NCIsInVzZXJuYW1lIjoiOTBmODE2NTItMmE0Ny00NjM4LWE1NmQtNTRlNWNmMDUwMDFjIn0.J_9u8Wkx4-KY6ac5d57Ff_gEMCowpCD-ymyA2pzKMfeKGJ0Uz5ukufcsoEpPgaGcRQYTKKmYEXVhOz-gCwS1LninalrgTsEpyv8ULGmZaKDBsYvQIM5LaBXtW4ZVNGPzRKctjyXbV2tWGA-bSnu34CnEET-HQwgKUH4KkT9IOOGUHPUCDKKwLw1l-lZN2Q1lrCXNtUBJVyY7ZxuzFaiywARxSGBFZom797mEdEwb49_uugXoMRgTE-kS4pvVLgMYMXNqAROXyCkzRoF9Zs2Qkv9IWD27IjPShRBFkZbGdKsIoJu2c-vBDudh9dXD4YGZfsU5I5N7-PYLgEENhWDabA
Am I missing something in creating the Joken.Signer?
Cheers,
Robert
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
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
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cs-victor-nascimento
It is difficult to know how you’ve signed your token. Though this token has a different “kid” claim on its header than the one your passing for
JOSE.JWK.from_map/1.Does this help? The kid on the token is:
ttY6v6AGiOqL+ZaDvyg953iG7RWLTwDVq9+cOa1hrZE=\reneerojas
i’ve tryed with this kid and the same token
awsJwks = Poison.decode!(~s({“alg”:“RS256”,“e”:“AQAB”,“kid”:“ttGiOqL+ZaDvyg953iG7R=”,“kty”:“RSA”,“n”:“q70S6cdm28a0LRj_o8QP7Getgh-QygM7iKRp5QIcyEO2rie-Gas7QyW8k1uTHJT68gxdoV8hverMwWw2H7L1Y7ec6-jN1tsq1ExYQbi8ELDxzCpeDF_e4FKp2COZEdV_CVN8qxdC6aBTIN7dSNP_gw_XIk_G_S2JDJCty_fviIfi9WZP_2uW8xAo2KX2ssno_wVbTJ_XxxnWy6aFNeaW5yFzHKMgVRbkMClXLRQ”,“use”:“sig”}))
BTW, i’m trying to decode the same token…
thanks for help
regards,
Renee
bponghneng
@cs-victor-nascimento Thanks for your reply! @reneerojas and I are working on the same problem
To clarify, we are trying to verify JWTs signed by AWS, which provides the following public key set:
https://cognito-idp.us-east-1.amazonaws.com/us-east-1_WhtpCXeoU/.well-known/jwks.json
Is the technique above the correct way to create a Joken.Signer?
I cannot see any other technique to create the Joken.Signer except to read the provided AWS key set JSON and observe that both keys in the set list RS256 as the encryption. Then hard code that by using Joken.rs256().
Is it best if we extract the AWS key with the correct kid from the set before creating the JOSE.JWK? (I think that is what @reneerojas has tried.)
Cheers,
Robert
Azolo
I had to do something similar with
Auth0, I ended up just usingJOSEdirectly instead ofJokenthough.But anyway, it looks like what you’re missing to me is the fact that the
jwksis actually a key set. Meaning you need to get your token from the list before you try to verify. Assuming you only have one key then this should probably do it:If not, this is the crazy function that I ended up getting to:
bponghneng
@Azolo Yeah, the Auth0 JWK set is exactly the same format as the AWS set, so I think we need your function, thanks! How are you verifying after extracting the key? Using Joken for that?
Cheers,
Robert
Azolo
Well you’re supposed to use the data in the JWT to get the name of the key in the jwks, but I was pretty frustrated at that point, so I just did:
bponghneng
Cool! We will give a try just directly with JOSE.JWT
Cheers,
Robert
bponghneng
@Azolo Worked! Wow, great: Clears a big block for us. We’ll use your technique
Cheers,
Robert
Azolo
Glad I could help
zycavi
I’ve stumbled upon the same issue - thanks for the useful answers, which pointed me the right way
I actually took it a little further and got it integrated with Joken:
verified_token = payload_fun.(conn)(see https://github.com/bryanjos/joken/blob/master/lib/joken/plug.ex#L174) Let’s call itYouproject.modifiedJokenPlugAdjust your router’s verify_function to take on argument:
def verify_function(conn) doand your plug:
plug Youproject.modifiedJokenPlug, verify: &Youproject.Router.verify_function/1(don’t forget, you cb now takes one argument, so it’s/1)