From a9058796d8174853a903c9b4bf8a17035f4fa60b Mon Sep 17 00:00:00 2001 From: Andy Rudd Date: Fri, 14 Jul 2017 10:16:36 +0100 Subject: [PATCH] Check automatic refresh interval before refreshing the security tokens. --- .../DiscoveryDocumentIssuerSecurityTokenProvider.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) {