jsonwebtoken icon indicating copy to clipboard operation
jsonwebtoken copied to clipboard

How to customize the Header field

Open jiashiwen opened this issue 2 years ago • 4 comments

Some of my python or java programs found the following definitions

python

  return jwt.encode(
    payload,
    secret,
    algorithm="HS256",
    headers={"alg": "HS256", "sign_type": "SIGN"},
)

java

 headerClaims.put("alg", "HS256");
 headerClaims.put("sign_type", "SIGN");
 String token = JWT.create().withPayload(payload).withHeader(headerClaims).sign(alg);

However, the "sign_type" field is not seen in the jsonwebtoken::Header definition. How to customize the header's custom fields?

jiashiwen avatar Jan 23 '24 05:01 jiashiwen

You can't, you can only use header fields from the spec in this library

Keats avatar Jan 23 '24 07:01 Keats

A hashmap may be needed to provide the function of custom fields, and some access may require

jiashiwen avatar Jan 24 '24 06:01 jiashiwen

+1

kitty-eu-org avatar Apr 25 '24 03:04 kitty-eu-org

very unfortunate, makes the library unusable for cases like https://developer.apple.com/documentation/weatherkitrestapi/request_authentication_for_weatherkit_rest_api

which needs an id field in the header

yspreen avatar Aug 23 '24 01:08 yspreen