Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verifying JWT with the RS256 algorithm using public key #37

Open
truonglx-56 opened this issue Apr 21, 2017 · 3 comments
Open

Verifying JWT with the RS256 algorithm using public key #37

truonglx-56 opened this issue Apr 21, 2017 · 3 comments
Projects

Comments

@truonglx-56
Copy link

Can i read public key from file and verify token?

@potatosalad
Copy link
Owner

Yes, there are a few functions provided for reading JSON Web Keys from files:

Here is a list of examples of each of the signing and verification operations by algorithm type: https://hexdocs.pm/jose/JOSE.JWS.html#module-examples

If you're using RS256, for example, you might do the following:

public_jwk = JOSE.JWK.from_openssh_key_file("my-rsa-key.pub")
case JOSE.JWT.verify_strict(public_jwk, ["RS256"], token) do
  {true, jwt, _jws} ->
    # use the verified jwt claims however you would like...
    # NOTE: only the signature has been verified,
    #       things like token expiration are not part of this library
  _ ->
    # invalid token, do something else
end

Please let me know whether that works for you or if you have any other questions.

@truonglx-56
Copy link
Author

truonglx-56 commented Apr 24, 2017

read_key(RsaKey) ->
case jose_jwk:from_pem_file(RsaKey) of {error, _} -> {undefined}; RsaPrivateKey -> jose_jwk:to_public(RsaPrivateKey) end.

Work for me, but when i check a expired token with: jose_jwt:verify_strict(RsaPublicKey, [<<"RS512">>], Token) return {true, _ , _ }.Second, when i change data in a claim, verify return {flase,,} ,although i didn't change key and use algorithm "RS512" .This is a bug or my fault?

@imranismail
Copy link

Same with me, expired token seems to work.

@potatosalad potatosalad added this to To do in jose 2.0.x Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To do
jose 2.0.x
  
To do
Development

No branches or pull requests

3 participants