Keats / jsonwebtoken

JWT lib in rust
MIT License
1.61k stars 253 forks source link

How to customize the Header field #368

Open jiashiwen opened 5 months ago

jiashiwen commented 5 months ago

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?

Keats commented 5 months ago

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

jiashiwen commented 5 months ago

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

kitty-eu-org commented 2 months ago

+1