enkr1
How to verify RS256 JWT with Joken.Signer.verify/2 - 2022
Hi community,
I am trying to verify the JWT with my public key (.pem) before decrypting it, and then proceeding to process the payload.
Similar to Joken: Using Joken.verify - trying to verify with a RS256 public key
I have tried to read through the documentation, but there are not many efficient examples.
Here is how I did it:
return_token = "eyJhb...."
case File.read("./public.pem") do
{:ok, public_key} ->
{_, %{"n" => n} = key_map} =
JOSE.JWK.from_pem(public_key)
|> JOSE.JWK.to_map()
signer =
Joken.Signer.create("RS256", key_map)
|> IO.inspect(label: "signer")
Joken.Signer.verify(return_token, signer)
|> IO.inspect(label: "verify") # Here is the part where it gives error
{:error, unsupported_case} ->
unsupported_case |> IO.inspect(label: "i didnt expect this.")
{:erorr, "Something went wrong while trying to read the public.pem ..."}
end
output:
# ...
signer: %Joken.Signer{
jwk: %JOSE.JWK{
keys: :undefined,
kty: {:jose_jwk_kty_rsa,
{:RSAPublicKey,
2374353...43,
65537}},
fields: %{}
},
jws: %JOSE.JWS{
alg: {:jose_jws_alg_rsa_pkcs1_v1_5, :RS256},
b64: :undefined,
fields: %{"typ" => "JWT"}
},
alg: "RS256"
}
verify: {:error, :signature_error}
# ...
I also tried this @vinagrito1’s solution Using Joken to validate Google JWTs - #12 by vinagrito1
but what I am getting is false instead of true:
{false,
%JOSE.JWT{
fields: %{
# ...
}
},
%JOSE.JWS{
alg: {:jose_jws_alg_rsa_pkcs1_v1_5, :RS256},
b64: :undefined,
fields: %{"typ" => "JWT"}
}}
Thank you so much in advance.
Best,
Jing Hui P.
Most Liked
vasumur
Facing similar issue with Joken. The result is always false when I trying with azure access token but it works fine for id token from azure.
Any reason why we can’t verify the access token signature to be valid?
1
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
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
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New







