Skip to content

Unable to create instance of JwtClaimsBuilder #9298

@sonu3706

Description

@sonu3706

@bobmcwhirter @adietish @gunnarmorling @Sanne @stalep

Issue while creating JWT token with quarkus-smallrye-jwt dependency
While creating token

JwtClaimsBuilder claims = Jwt.claims(jsonResName); throws NPE.
Initially thought file is not loading may be the path of the file is wrong, but when I
tried to read the content of the file with below code, I am getting the content. So it means file path is correct.
InputStream inputStream = JwtUtil.class.getResourceAsStream("/privateKey.pem")

Below is my piece of code to create token.


public static String generateTokenString(PrivateKey privateKey, String kid,
                                             String jsonResName, Map<String, Long> timeClaims) throws Exception {
        JwtClaimsBuilder claims = Jwt.claims(jsonResName);
        long currentTimeInSecs = currentTimeInSecs();
        long exp = timeClaims != null && timeClaims.containsKey(Claims.exp.name())
                ? timeClaims.get(Claims.exp.name()) : currentTimeInSecs + 300;

        claims.issuedAt(currentTimeInSecs);
        claims.claim(Claims.auth_time.name(), currentTimeInSecs);
        claims.expiresAt(exp);

        return claims.jws().signatureKeyId(kid).sign(privateKey);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions