Skip to content

Commit

Permalink
Merge branch 'release' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Apr 5, 2017
2 parents 6d483c8 + 1e6aacf commit c8abf43
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ internal class WsFedCachingSecurityTokenProvider : IIssuerSecurityTokenProvider
{
private readonly TimeSpan _refreshInterval = new TimeSpan(1, 0, 0, 0);

private readonly ReaderWriterLockSlim _synclock = new ReaderWriterLockSlim();

private readonly string _metadataEndpoint;

private readonly TimeSpan _backchannelTimeout;
Expand Down Expand Up @@ -63,16 +61,8 @@ public string Issuer
{
get
{
RetrieveMetadata();
_synclock.EnterReadLock();
try
{
return _issuer;
}
finally
{
_synclock.ExitReadLock();
}
RefreshMetadata();
return _issuer;
}
}

Expand All @@ -86,39 +76,40 @@ public IEnumerable<SecurityToken> SecurityTokens
{
get
{
RetrieveMetadata();
_synclock.EnterReadLock();
try
{
return _tokens;
}
finally
{
_synclock.ExitReadLock();
}
RefreshMetadata();
return _tokens;
}
}

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

_synclock.EnterWriteLock();
try
// Queue a refresh, but discourage other threads from doing so.
_syncAfter = DateTimeOffset.UtcNow + _refreshInterval;
ThreadPool.UnsafeQueueUserWorkItem(state =>
{
IssuerSigningKeys metaData = WsFedMetadataRetriever.GetSigningKeys(_metadataEndpoint,
_backchannelTimeout, _backchannelHttpHandler);
_issuer = metaData.Issuer;
_tokens = metaData.Tokens;
_syncAfter = DateTimeOffset.UtcNow + _refreshInterval;
}
finally
{
_synclock.ExitWriteLock();
}
try
{
RetrieveMetadata();
}
catch (Exception)
{
// Don't throw exceptions on background threads.
}
}, state: null);
}

private void RetrieveMetadata()
{
_syncAfter = DateTimeOffset.UtcNow + _refreshInterval;
IssuerSigningKeys metaData = WsFedMetadataRetriever.GetSigningKeys(_metadataEndpoint,
_backchannelTimeout, _backchannelHttpHandler);
_issuer = metaData.Issuer;
_tokens = metaData.Tokens;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ protected override Task ApplyResponseChallengeAsync()

AddQueryString(queryStrings, properties, "access_type", Options.AccessType);
AddQueryString(queryStrings, properties, "approval_prompt");
AddQueryString(queryStrings, properties, "prompt");
AddQueryString(queryStrings, properties, "login_hint");
AddQueryString(queryStrings, properties, "include_granted_scopes");

string state = Options.StateDataFormat.Protect(properties);
queryStrings.Add("state", state);
Expand Down
5 changes: 4 additions & 1 deletion tests/Katana.Sandbox.WebServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ public void Configuration(IAppBuilder app)
{
map.Run(context =>
{
context.Authentication.Challenge(new AuthenticationProperties() { RedirectUri = "/" }, context.Request.Query["scheme"]);
var properties = new AuthenticationProperties();
properties.RedirectUri = "/"; // Go back to the home page after authenticating.
properties.Dictionary["prompt"] = "select_account"; // Google
context.Authentication.Challenge(properties, context.Request.Query["scheme"]);
return Task.FromResult(0);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public async Task ChallengeWillTriggerRedirection()

location.ShouldNotContain("access_type=");
location.ShouldNotContain("approval_prompt=");
location.ShouldNotContain("prompt=");
location.ShouldNotContain("login_hint=");
location.ShouldNotContain("include_granted_scopes=");
}

[Fact]
Expand Down Expand Up @@ -162,7 +164,9 @@ public async Task ChallengeWillUseAuthenticationPropertiesAsParameters()
{ "scope", "https://www.googleapis.com/auth/plus.login" },
{ "access_type", "offline" },
{ "approval_prompt", "force" },
{ "login_hint", "[email protected]" }
{ "prompt", "consent" },
{ "login_hint", "[email protected]" },
{ "include_granted_scopes", "true" }
}), "Google");
res.StatusCode = 401;
}
Expand All @@ -175,7 +179,9 @@ public async Task ChallengeWillUseAuthenticationPropertiesAsParameters()
query.ShouldContain("scope=" + Uri.EscapeDataString("https://www.googleapis.com/auth/plus.login"));
query.ShouldContain("access_type=offline");
query.ShouldContain("approval_prompt=force");
query.ShouldContain("prompt=consent");
query.ShouldContain("login_hint=" + Uri.EscapeDataString("[email protected]"));
query.ShouldContain("include_granted_scopes=true");
}

[Fact]
Expand Down

0 comments on commit c8abf43

Please sign in to comment.