artemeff / jwt

Erlang JWT library
http://jwt.io/
MIT License
38 stars 39 forks source link

Support `kid` to locate the key in a JSON Web Key Set (JWKS) #46

Closed dumbbell closed 1 year ago

dumbbell commented 2 years ago

In encode/{3,4}, it's possible to annotate the key with it key ID using a tuple:

jwt:encode(Alg, ClaimsSet, {<<"MyKeyId">>, Key}).

The kid attribute will be added to the token header.

In decode/{2,3}, it's possible to pass an encoded (JSON as a binary) or decoded (JSON as a map) JWKS:

jwt:decode(Token, JWKS).

jwt will call jwk to decode (if necessary) and select the appropriate key in the JWKS during the get_key step, as the kid was obtained previously during the decode_jwt step.

As part of that, new type specs were defined:

Care has been taken to not break the API in the process.

artemeff commented 1 year ago

thanks! sorry for delay :(

dumbbell commented 1 year ago

No problem :-) Thank you!