When i use java application to get token (JWT) error

every time when i use java application to get token (JWT)
and i will receive a string like this

"
i use this string to access https://api.zoom.us/v2/users?page_number=1&page_size=30&status=active

header is
Bearer

it return

{
“code”: 124,
“message”: “The Token’s Signature resulted invalid when verified using the Algorithm: HmacSHA256”
}

who can help me please.

Hi @fsx,

How are you creating the JWT token? Did you use one of the support jwt.io java libraries? You can use these guides below.
1 - https://marketplace.zoom.us/docs/guides/authorization/jwt
2 - https://marketplace.zoom.us/docs/guides/authorization/jwt/jwt-with-zoom

Thanks

1 Like

thanks i get it ,I tried many libaries of your provides。the one maven: io.jsonwebtoken / jjwt / 0.9.0
successed。thank u。

1 Like

Glad it is working now! :slight_smile:

Let us know if you have additional questions! :slight_smile:

-Tommy

Hi fsx, can you share the code pls ? Thanks a lot

Map<String,Object> header = new HashMap<>();
header.put(“alg”,“HS256”);
header.put(“type”,“JWT”);

    String headerEncode = Base64.getUrlEncoder().encodeToString(header.toString().getBytes());
    SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
    SecretKey key = Keys.hmacShaKeyFor("".getBytes(StandardCharsets.UTF_8));
    String jwt = Jwts.builder().setHeader(header).setIssuer("").
            setExpiration(new Date(new Date().getTime()+80000000)).signWith(key,signatureAlgorithm).compact();
    System.out.println(headerEncode);
    System.out.println(jwt);
2 Likes

Great, thank yo very much. Work Perfect !!!

1 Like

Hey @jmery24 happy to hear it worked! :slight_smile:

Thanks for your help @fsx!

-Tommy

1 Like

Hi can you share jar you have been used in this code

Hey @mformayank10,

Let us know if there is something we can help with.

Thanks,
Tommy