Skip to content
This repository has been archived by the owner on Dec 14, 2017. It is now read-only.

Check automatic refresh interval before refreshing the security tokens. #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class DiscoveryDocumentIssuerSecurityTokenProvider : IIssuerSecurityTok
private readonly ILogger _logger;
private string _issuer;
private IEnumerable<SecurityToken> _tokens;
private DateTimeOffset _syncAfter = new DateTimeOffset(new DateTime(2001, 1, 1));

public DiscoveryDocumentIssuerSecurityTokenProvider(string discoveryEndpoint, IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory)
{
Expand All @@ -55,7 +56,7 @@ public DiscoveryDocumentIssuerSecurityTokenProvider(string discoveryEndpoint, Id
{
AutomaticRefreshInterval = options.AutomaticRefreshInterval
};

if (!options.DelayLoadMetadata)
{
RetrieveMetadata();
Expand Down Expand Up @@ -131,6 +132,11 @@ public IEnumerable<SecurityToken> SecurityTokens

private void RetrieveMetadata()
{
if (_syncAfter >= DateTimeOffset.UtcNow)
{
return;
}

_synclock.EnterWriteLock();
try
{
Expand All @@ -157,6 +163,7 @@ private void RetrieveMetadata()

_issuer = result.Issuer;
_tokens = tokens;
_syncAfter = DateTimeOffset.UtcNow + _configurationManager.AutomaticRefreshInterval;
}
catch (Exception ex)
{
Expand Down