@@ -270,9 +270,6 @@ class Validator {
270270 if (!jwt.has_payload_claim (" iss" )) {
271271 throw jwt::token_verification_exception (" 'iss' claim is mandatory" );
272272 }
273- if (!jwt.has_header_claim (" kid" )) {
274- throw jwt::token_verification_exception (" 'kid' claim is mandatory" );
275- }
276273 if (!m_allowed_issuers.empty ()) {
277274 std::string issuer = jwt.get_issuer ();
278275 bool permitted = false ;
@@ -297,9 +294,17 @@ class Validator {
297294
298295 std::string public_pem;
299296 std::string algorithm;
300- get_public_key_pem (jwt.get_issuer (), jwt.get_key_id (), public_pem, algorithm);
297+ // Key id is optional in the RFC, set to blank if it doesn't exist
298+ std::string key_id;
299+ try {
300+ key_id = jwt.get_key_id ();
301+ } catch (const std::runtime_error&) {
302+ // Don't do anything, key_id is empty, as it should be.
303+ }
304+
305+ get_public_key_pem (jwt.get_issuer (), key_id, public_pem, algorithm);
301306 // std::cout << "Public PEM: " << public_pem << std::endl << "Algorithm: " << algorithm << std::endl;
302- SciTokenKey key (jwt. get_key_id () , algorithm, public_pem, " " );
307+ SciTokenKey key (key_id , algorithm, public_pem, " " );
303308 auto verifier = jwt::verify ()
304309 .allow_algorithm (key);
305310
0 commit comments