Skip to content

Commit 903c0a2

Browse files
committed
Set kid in header instead of body
Seems like the correct thing according to the RFC standards and is used by auth0 as well.
1 parent b5df2ca commit 903c0a2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

prolog/jwt_io.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
claims_with_aud(Claims, ClaimsWithAud),
103103
claims_with_iat(ClaimsWithAud, ClaimsWithIat),
104104
claims_with_iss(ClaimsWithIat, Key, ClaimsWithIss),
105-
ClaimsNew = ClaimsWithIss.put(_{kid: Kid, jti: Jti}),
105+
ClaimsNew = ClaimsWithIss.put(_{jti: Jti}),
106106
atom_json_dict(Data,ClaimsNew,[as(atom)]),
107-
jwt_encode_from_string(Data, Token, Key.key, Key.algorithm).
107+
jwt_encode_from_string(Data, Token, Key.key, Key.algorithm, Kid).
108108

109109
%! jwt_decode(+Data: atom, -Payload:dict, +Options:options) is semidet
110110
%

src/jwt_io.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ static void get_pl_arg_str(char *predicate_name, char *term_name, term_t term, c
1616
}
1717
}
1818

19-
static foreign_t pl_jwt_encode(term_t in, term_t out, term_t key_term, term_t algorithm) {
19+
static foreign_t pl_jwt_encode(term_t in, term_t out, term_t key_term, term_t algorithm, term_t key_id) {
2020
jwt_t *jwt;
21-
char *result, *grants, *alg_str, *key;
21+
char *result, *grants, *alg_str, *key, *kid;
2222
int rval;
2323

2424
get_pl_arg_str("jwt_encode_from_string/4", "in", in, &grants);
2525
get_pl_arg_str("jwt_encode_from_string/4", "key", key_term, &key);
26+
get_pl_arg_str("jwt_encode_from_string/4", "kid", key_id, &kid);
2627
get_pl_arg_str("jwt_encode_from_string/4", "algorithm", algorithm, &alg_str);
2728
jwt_new(&jwt);
2829
jwt_add_grants_json(jwt, grants);
30+
jwt_add_header(jwt, "kid", kid);
2931
jwt_set_alg(jwt, jwt_str_alg(alg_str), (const unsigned char *)key, strlen(key));
3032
result = jwt_encode_str(jwt);
3133
rval = PL_unify_atom_chars(out, result);
@@ -81,6 +83,6 @@ static foreign_t pl_jwt_decode(term_t in, term_t out_payload, term_t out_algorit
8183

8284
install_t install(void) {
8385
PL_register_foreign("jwt_parse_head", 2, pl_jwt_parse_head, 0);
84-
PL_register_foreign("jwt_encode_from_string", 4, pl_jwt_encode, 0);
86+
PL_register_foreign("jwt_encode_from_string", 5, pl_jwt_encode, 0);
8587
PL_register_foreign("jwt_decode_from_string", 4, pl_jwt_decode, 0);
8688
}

0 commit comments

Comments
 (0)