Skip to content

Commit 9aeaa44

Browse files
committed
properly cache jwks
1 parent 401936f commit 9aeaa44

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Access/Common/JWKSProvider.cpp

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

29-
if (diff < refresh_timeout)
29+
if (diff < refresh_timeout && cached_jwks.has_value())
3030
{
3131
LOG_DEBUG(getLogger("JWKSProvider"), "Returning cached JWKS");
32-
return cached_jwks;
32+
return cached_jwks.value();
3333
}
3434

3535
Poco::Net::HTTPResponse response;
@@ -73,7 +73,7 @@ JWKSType JWKSClient::getJWKS()
7373
}
7474

7575
cached_jwks = std::move(parsed_jwks);
76-
return cached_jwks;
76+
return cached_jwks.value();
7777
}
7878

7979
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)