Coder Social home page Coder Social logo

Decoding RS256 JWT about pyjwt HOT 10 CLOSED

jpadilla avatar jpadilla commented on May 19, 2024 1
Decoding RS256 JWT

from pyjwt.

Comments (10)

cancan101 avatar cancan101 commented on May 19, 2024

Following this to get a :

-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----

and then setting this to JWT_SECRET_KEY seems to do the trick.

from pyjwt.

jpadilla avatar jpadilla commented on May 19, 2024

This might be related to #90

from pyjwt.

cancan101 avatar cancan101 commented on May 19, 2024

The issue is mentioned here: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#pem and also talked about in #82.

The solution is to load the certificate using:

key = cryptography.x509.load_pem_x509_certificate(PUBLIC_KEY, default_backend()).public_key()

rather than:

 key = cryptography.hazmat.primitives.serialization.load_pem_public_key(key, backend=default_backend())

from pyjwt.

jpadilla avatar jpadilla commented on May 19, 2024

Still not clear with this if there's something we can do to prevent this confusion.

from pyjwt.

cancan101 avatar cancan101 commented on May 19, 2024

You could make this logic try to fall back one to one more attempt. You could add some additional logic to look for the begin/end public key string as well.

from pyjwt.

jpadilla avatar jpadilla commented on May 19, 2024

Interested in seeing a PR for this.

@wbolster @mark-adams I'd love your thoughts on this.

from pyjwt.

mark-adams avatar mark-adams commented on May 19, 2024

I think we should update the documentation to indicate how to load a key from an x509 certificate.

I don't think adding more fallback logic is the right approach. The API expects a key and it works when you pass in a key. A certificate is way more than a key so it's a bit outside the scope of our code and would only add complexity.

It should be the consumer's responsibility to make sure they are passing in a key and not something else. If we do something like this, why not check to see if it is ZIP compressed, or embedded in a Word doc, or maybe a reversed string? :)

from pyjwt.

cancan101 avatar cancan101 commented on May 19, 2024

I would say more important than the fallback logic would just be documentation.

from pyjwt.

jpadilla avatar jpadilla commented on May 19, 2024

Sold! If anyone wants to take a stab at that, pull requests are welcome.

from pyjwt.

wbolster avatar wbolster commented on May 19, 2024

+1 on having this as documentation. Adding magic detection logic to the jwt API isn't the right way imho, as @mark-adams pointed out.

from pyjwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.