https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077

--- Comment #16 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 211700
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211700&action=edit
Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims

This patch refactors the existing JWT methods (generate_jwt, check_jwt,
decode_jwt) to be thin wrappers around encode_claims/decode_claims,
eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions.
check_jwt delegates to check(), so the validation lives in one place.

This makes encode_claims/decode_claims the single source of truth for
JWT operations, with the id-based methods as a convenience layer on top.

It also hardens the new methods:
- decode_claims returns undef on an undefined or empty token, without
  warning or logging
- decode_claims uses Try::Tiny and logs invalid tokens
- encode_claims throws Koha::Exceptions::WrongParameter if the claims
  are not a hashref
- generate({ type => 'JWT' }) without an id returns undef, as before

Behaviour changes, documented in the POD:
- JWTs are always signed with the Koha secret: a caller-supplied secret
  is ignored (no caller in Koha passes one)
- decode_jwt returns undef and logs a warning on an invalid or expired
  token, instead of dying

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/Token.t t/Koha/Token.t
=> SUCCESS: Tests pass! t/Koha/Token.t covers tampered payloads, a
   wrong key, alg:none, garbage, expired tokens and tokens without an id
3. Sign off :-D

Assisted-by: Opus 5.5 (Anthropic)
Signed-off-by: David Nind <[email protected]>
Signed-off-by: Brendan Lawlor <[email protected]>
Signed-off-by: Martin Renvoize <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to