Skip to content

Commit ffb707b

Browse files
committed
properly cache jwks
1 parent d08c878 commit ffb707b

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
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

0 commit comments

Comments
 (0)