Code Monkey home page Code Monkey logo

Comments (11)

juliangp avatar juliangp commented on May 19, 2024 1

I will try your suggestion above - thanks.

from jwt.

juliangp avatar juliangp commented on May 19, 2024 1

@cristaloleg thanks for the fix, it is not very intuitive for an optional header but it does work!

from jwt.

cristaloleg avatar cristaloleg commented on May 19, 2024

Hey, sorry for the trouble. That's an interesting case.

Can you clarify why your tokens don't have 'typ:"JWT"' ? (or another value if any)

Also https://datatracker.ietf.org/doc/html/rfc7519#section-5.1

from jwt.

frankdvd avatar frankdvd commented on May 19, 2024

Hi @cristaloleg The "typ" field in a JSON Web Token (JWT) is an optional field. According to the JWT specification (RFC 7519), it's used to specify the token type. However, it's not required, and many JWT implementations don't include it. So, maybe we should check the type only when it exists?

from jwt.

cristaloleg avatar cristaloleg commented on May 19, 2024

Yeah, that's another solution that came to my mind.

However, it looks very unintuitive 'cause sometimes it does a check and sometimes not.

from jwt.

cristaloleg avatar cristaloleg commented on May 19, 2024

Right now I see this as the simplest fix:

token, err := jwt.Parse(...) // or any other parse function from jwt
if err != nil {
    if !errors.Is(err, jwt.ErrNotJWTType) {
        // bad token data or bad signature or ...
    }
    // proper token BUT 'typ' field is not 'JWT'
}

from jwt.

juliangp avatar juliangp commented on May 19, 2024

Hi, I do not own the service that provides the token but as far as I can see the header only contains alg and kid.

from jwt.

cristaloleg avatar cristaloleg commented on May 19, 2024

Again, sorry for the trouble. I hope it didn't end up as an emergency.

Please confirm if the solution above works for you. If so, I will document that. Thanks!

from jwt.

juliangp avatar juliangp commented on May 19, 2024

Hi, unfortunately your suggestion does not work because the token is coming back as nil?

from jwt.

cristaloleg avatar cristaloleg commented on May 19, 2024

Ah, indeed, can you check this PR #148 ?

from jwt.

cristaloleg avatar cristaloleg commented on May 19, 2024

New minor version https://github.com/cristalhq/jwt/releases/tag/v5.3.0

from jwt.

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.