Giter Club home page Giter Club logo

Comments (12)

omgbanana avatar omgbanana commented on September 15, 2024 2

For those looking for the code of how to get an unverified JsonWebToken object from the token string, this code should do the trick:

    public JsonWebToken decodeTokenUnverified(String tokenString) throws InvalidJwtException {
        JwtConsumer consumer = new JwtConsumerBuilder()
                .setSkipAllValidators()
                .setDisableRequireSignature()
                .setSkipSignatureVerification()
                .build();

        JwtClaims claimsSet = consumer.processToClaims(tokenString);
        return new DefaultJWTCallerPrincipal(tokenString, claimsSet);
    }

And how will this inject it into the quarkus-smallrye security context for authorization? (For RolesAllowed purposes)

from smallrye-jwt.

sberyozkin avatar sberyozkin commented on September 15, 2024 1

See the documentation, Custom Factories, how to inject custom factories which will bypass the verification,
https://github.com/smallrye/smallrye-jwt/blob/master/doc/modules/ROOT/pages/configuration.adoc

from smallrye-jwt.

sberyozkin avatar sberyozkin commented on September 15, 2024

@FreifeldRoyi What I can suggest is to register a custom JWTCallerPrincipalFactory, similarly to the way it is done for the Thorntail Keycloak integration. There you'd just parse the token with Jose4J and use DefaultJWTCallerPrincipal.
Let me know how it goes please

from smallrye-jwt.

sberyozkin avatar sberyozkin commented on September 15, 2024

@FreifeldRoyi if we update smallrye-jwt to allow for the unverified tokens then it won't pass any security review, even though it would be done with some configuration, and as in your case, you can be assured enough that it won't be a problem. So I'll close this issue, but I'll wait till you confirm the customization works in principle for you

from smallrye-jwt.

FreifeldRoyi avatar FreifeldRoyi commented on September 15, 2024

Is there any preference doing that instead of implementing a parser in Jax-rs filter and adding to request context?

from smallrye-jwt.

sberyozkin avatar sberyozkin commented on September 15, 2024

@FreifeldRoyi No, not really, if all you need is to use MP JWT API, then indeed just convert it into JsonWebToken and set it as a new (JAX-RS) security context

from smallrye-jwt.

omgbanana avatar omgbanana commented on September 15, 2024

Hello!

There was a whole conversation about this (https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/MP-JWT.20validation.20skip). The thing is at some point You do not need to verify the token, but You still want to get the roles out of it and use the quarkus-jwt for authorization purposes.

It makes it hard to use in bigger solutions that have the validation done before it reaches the quarkus application (part of the whole cluster-eco-system).

Would injecting JWTCallerPrincipalFactory make it possible for me to extract the roles from the un-verified token and inject them into the quarkus security principal used for role matching? (I tried it briefly and I could not find a way to inject it). Is there a solution that is not too hacky-slashy in the global view of software development? One that can be reused in all microservices of the eco-system that is not copy paste this solution manually and override the default implementation?

I was wondering if this is going to live, or get discarded. It is quite important for me to know.

from smallrye-jwt.

sberyozkin avatar sberyozkin commented on September 15, 2024

@omgbanana this is why I'm keeping this issue open :-). Custom factory path should be good enough but it requires a bit more thinking how to do it right, I'll try to prioritize on it soon

from smallrye-jwt.

andreas-eberle avatar andreas-eberle commented on September 15, 2024

For those looking for the code of how to get an unverified JsonWebToken object from the token string, this code should do the trick:

    public JsonWebToken decodeTokenUnverified(String tokenString) throws InvalidJwtException {
        JwtConsumer consumer = new JwtConsumerBuilder()
                .setSkipAllValidators()
                .setDisableRequireSignature()
                .setSkipSignatureVerification()
                .build();

        JwtClaims claimsSet = consumer.processToClaims(tokenString);
        return new DefaultJWTCallerPrincipal(tokenString, claimsSet);
    }

from smallrye-jwt.

andreas-eberle avatar andreas-eberle commented on September 15, 2024

It won't. There currently does not seem to be an option to skip verification (afaik). Just wanted to share this code on how to get a JWT parsed, since I also first had to find a way to do it and thought it might help you, although it doesn't solve your problem.

from smallrye-jwt.

radcortez avatar radcortez commented on September 15, 2024

The factory solution should work.

Unfortunately, it seems that Quarkus instantiates the DefaultJWTTokenParser directly, instead of using the factory:
quarkusio/quarkus@08777bb#diff-4dabe1f5911b23eb33fd6188eefe39c2

@sberyozkin what do you think?

from smallrye-jwt.

sberyozkin avatar sberyozkin commented on September 15, 2024

It now (on master) deals with the injected JWTParser.
Once #194 is merged it will all work

from smallrye-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.