Coder Social home page Coder Social logo

Comments (6)

lhazlewood avatar lhazlewood commented on May 18, 2024 5
int i = jws.lastIndexOf('.')
String withoutSignature = jws.substring(0, i+1);
Jwt<Header,Claims> untrusted = Jwts.parser().parseClaimsJwt(withoutSignature);

That should work until we figure out a way to (safely) make this available in the library.

from jjwt.

josebarrueta avatar josebarrueta commented on May 18, 2024 1

With the JJWT library you can already do this in a secure way, by setting a SigningKeyResolver

SigningKeyResolver resolver = new MySigningKeyResolver();

Jws<Claims> jws = Jwts.parser().setSigningKeyResolver(resolver).parseClaimsJws(compact);

The signature is still validated, and the JWT instance will still not be returned if the jwt string is invalid, as expected. You just get to 'see' the JWT data for key discovery before the parser validates.

As small sample of how to use it and look for the JwsHeader and/or Claims:

Jws<Claims> jws = Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() {
        @Override
        public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) {
            //inspect the header or claims, lookup and return the signing key
            String keyId = header.getKeyId(); //or any other field that you need to inspect
            return getSigningKey(keyId); //implement me
        }})
    .parseClaimsJws(compact);

from jjwt.

nrktkt avatar nrktkt commented on May 18, 2024

Perfect, thank you.
I should have searched the closed issues better before posting, so sorry about that.

from jjwt.

lhazlewood avatar lhazlewood commented on May 18, 2024

No worries! :)

from jjwt.

thiloplanz avatar thiloplanz commented on May 18, 2024

I am in the situation where a proxy should check the claims and expiration date of a signed token before passing it on. The proxy itself is not able to verify the signature, but I still want to be able to drop requests with invalid tokens (expired or missing claims).

Is there a good way to do that currently? Should I just strip off the signature part using String manipulation?

from jjwt.

ircecho avatar ircecho commented on May 18, 2024

We have a similar problem. In the client, we only want to check if the token is expired or not and display a more informative message. We do not really care if the token was manipulated at this point, since our backend does the real verification. What would be a good way to do it?

from jjwt.

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.