diff --git a/source/AccessTokenValidation/Plumbing/DiscoveryDocumentIssuerSecurityTokenProvider.cs b/source/AccessTokenValidation/Plumbing/DiscoveryDocumentIssuerSecurityTokenProvider.cs index 75c7711..901f3a4 100644 --- a/source/AccessTokenValidation/Plumbing/DiscoveryDocumentIssuerSecurityTokenProvider.cs +++ b/source/AccessTokenValidation/Plumbing/DiscoveryDocumentIssuerSecurityTokenProvider.cs @@ -33,6 +33,7 @@ internal class DiscoveryDocumentIssuerSecurityTokenProvider : IIssuerSecurityTok private readonly ILogger _logger; private string _issuer; private IEnumerable _tokens; + private DateTimeOffset _syncAfter = new DateTimeOffset(new DateTime(2001, 1, 1)); public DiscoveryDocumentIssuerSecurityTokenProvider(string discoveryEndpoint, IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) { @@ -55,7 +56,7 @@ public DiscoveryDocumentIssuerSecurityTokenProvider(string discoveryEndpoint, Id { AutomaticRefreshInterval = options.AutomaticRefreshInterval }; - + if (!options.DelayLoadMetadata) { RetrieveMetadata(); @@ -131,6 +132,11 @@ public IEnumerable SecurityTokens private void RetrieveMetadata() { + if (_syncAfter >= DateTimeOffset.UtcNow) + { + return; + } + _synclock.EnterWriteLock(); try { @@ -157,6 +163,7 @@ private void RetrieveMetadata() _issuer = result.Issuer; _tokens = tokens; + _syncAfter = DateTimeOffset.UtcNow + _configurationManager.AutomaticRefreshInterval; } catch (Exception ex) {