Skip to content

Commit d7c8c37

Browse files
committed
Correct exception thrown when JWK not found
1 parent 1018ab5 commit d7c8c37

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/Access/Common/JWKSProvider.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ JWKSType JWKSClient::getJWKS()
2525
auto now = std::chrono::high_resolution_clock::now();
2626
auto diff = std::chrono::duration<double>(now - last_request_send).count();
2727

28-
if (diff < refresh_timeout)
29-
{
30-
jwt::jwks <jwt::traits::kazuho_picojson> result(cached_jwks);
31-
return result;
32-
}
28+
if (diff < refresh_timeout && cached_jwks.has_value())
29+
return cached_jwks.value();
3330

3431
Poco::Net::HTTPResponse response;
3532
std::string response_string;
@@ -70,7 +67,7 @@ JWKSType JWKSClient::getJWKS()
7067
}
7168

7269
cached_jwks = std::move(parsed_jwks);
73-
return cached_jwks;
70+
return cached_jwks.value();
7471
}
7572

7673
StaticJWKSParams::StaticJWKSParams(const std::string & static_jwks_, const std::string & static_jwks_file_)

src/Access/Common/JWKSProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class JWKSClient : public IJWKSProvider
4343
Poco::URI jwks_uri;
4444

4545
std::shared_mutex mutex;
46-
JWKSType cached_jwks;
46+
std::optional<JWKSType> cached_jwks;
4747
std::chrono::time_point<std::chrono::high_resolution_clock> last_request_send;
4848
};
4949

src/Access/TokenProcessorsJWT.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ bool JwksJwtProcessor::resolveAndValidate(TokenCredentials & credentials) const
334334
return false;
335335
}
336336

337+
if (!provider->getJWKS().has_jwk(decoded_jwt.get_key_id()))
338+
throw Exception(ErrorCodes::AUTHENTICATION_FAILED, "JWKS error: no JWK found for JWT");
339+
337340
auto jwk = provider->getJWKS().get_jwk(decoded_jwt.get_key_id());
338341
auto username = decoded_jwt.get_payload_claim(username_claim).as_string();
339342

src/Access/TokenProcessorsParse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::unique_ptr<DB::ITokenProcessor> ITokenProcessor::parseTokenProcessor(
4545
if (externally_configured && ! locally_configured)
4646
{
4747
return std::make_unique<OpenIdTokenProcessor>(processor_name, token_cache_lifetime, username_claim, groups_claim,
48-
config.getString(prefix + ".openid_config_endpoint"),
48+
config.getString(prefix + ".configuration_endpoint"),
4949
verifier_leeway,
5050
jwks_cache_lifetime);
5151
}

0 commit comments

Comments
 (0)