Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 1537ece

Browse files
authored
OpenIdMetadata signing keys should refresh every 24 hours (#930)
1 parent 2e7499e commit 1537ece

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/CachingOpenIdMetadata.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
*/
2828
class CachingOpenIdMetadata implements OpenIdMetadata {
2929
private static final Logger LOGGER = LoggerFactory.getLogger(CachingOpenIdMetadata.class);
30-
private static final int CACHE_DAYS = 5;
30+
private static final int CACHE_DAYS = 1;
31+
private static final int CACHE_HOURS = 1;
3132

3233
private String url;
3334
private long lastUpdated;
@@ -58,13 +59,19 @@ class CachingOpenIdMetadata implements OpenIdMetadata {
5859
@Override
5960
public OpenIdMetadataKey getKey(String keyId) {
6061
synchronized (sync) {
61-
// If keys are more than 5 days old, refresh them
62+
// If keys are more than CACHE_DAYS days old, refresh them
6263
if (lastUpdated < System.currentTimeMillis() - Duration.ofDays(CACHE_DAYS).toMillis()) {
6364
refreshCache();
6465
}
6566

6667
// Search the cache even if we failed to refresh
67-
return findKey(keyId);
68+
OpenIdMetadataKey key = findKey(keyId);
69+
if (key == null && lastUpdated < System.currentTimeMillis() - Duration.ofHours(CACHE_HOURS).toMillis()) {
70+
// Refresh the cache if a key is not found (max once per CACHE_HOURS)
71+
refreshCache();
72+
key = findKey(keyId);
73+
}
74+
return key;
6875
}
6976
}
7077

0 commit comments

Comments
 (0)