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’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #ai
- #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)
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)