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

Commit 9ebfc56

Browse files
committed
Rework WsFed RemoteSignOutPath logic to work with ADFS #1581
1 parent eb96f4f commit 9ebfc56

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/Microsoft.AspNetCore.Authentication.WsFederation/WsFederationHandler.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ public WsFederationHandler(IOptionsMonitor<WsFederationOptions> options, ILogger
5757
/// <returns></returns>
5858
public override Task<bool> HandleRequestAsync()
5959
{
60-
if (Options.RemoteSignOutPath.HasValue && Options.RemoteSignOutPath == Request.Path)
60+
// RemoteSignOutPath and CallbackPath may be the same, fall through if the message doesn't match.
61+
if (Options.RemoteSignOutPath.HasValue && Options.RemoteSignOutPath == Request.Path && HttpMethods.IsGet(Request.Method)
62+
&& string.Equals(Request.Query[WsFederationConstants.WsFederationParameterNames.Wa],
63+
WsFederationConstants.WsFederationActions.SignOutCleanup, StringComparison.OrdinalIgnoreCase))
6164
{
65+
// We've received a remote sign-out request
6266
return HandleRemoteSignOutAsync();
6367
}
6468

@@ -374,18 +378,12 @@ public async virtual Task SignOutAsync(AuthenticationProperties properties)
374378
}
375379

376380
/// <summary>
377-
/// Handles requests to the RemoteSignOutPath and signs out the user.
381+
/// Handles wsignoutcleanup1.0 messages sent to the RemoteSignOutPath
378382
/// </summary>
379383
/// <returns></returns>
380384
protected virtual async Task<bool> HandleRemoteSignOutAsync()
381385
{
382-
WsFederationMessage message = null;
383-
384-
if (string.Equals(Request.Method, "GET", StringComparison.OrdinalIgnoreCase))
385-
{
386-
message = new WsFederationMessage(Request.Query.Select(pair => new KeyValuePair<string, string[]>(pair.Key, pair.Value)));
387-
}
388-
386+
var message = new WsFederationMessage(Request.Query.Select(pair => new KeyValuePair<string, string[]>(pair.Key, pair.Value)));
389387
var remoteSignOutContext = new RemoteSignOutContext(Context, Scheme, Options, message);
390388
await Events.RemoteSignOut(remoteSignOutContext);
391389

@@ -403,15 +401,8 @@ protected virtual async Task<bool> HandleRemoteSignOutAsync()
403401
}
404402
}
405403

406-
if (message == null
407-
|| !string.Equals(message.Wa, WsFederationConstants.WsFederationActions.SignOutCleanup, StringComparison.OrdinalIgnoreCase))
408-
{
409-
return false;
410-
}
411-
412404
Logger.RemoteSignOut();
413405

414-
// We've received a remote sign-out request
415406
await Context.SignOutAsync(Options.SignOutScheme);
416407
return true;
417408
}

src/Microsoft.AspNetCore.Authentication.WsFederation/WsFederationOptions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public class WsFederationOptions : RemoteAuthenticationOptions
3333
public WsFederationOptions()
3434
{
3535
CallbackPath = "/signin-wsfed";
36-
RemoteSignOutPath = "/signout-wsfed";
36+
// In ADFS the cleanup messages are sent to the same callback path as the initial login.
37+
// In AAD it sends the cleanup message to a random Reply Url and there's no deterministic way to configure it.
38+
// If you manage to get it configured, then you can set RemoteSignOutPath accordingly.
39+
RemoteSignOutPath = "/signin-wsfed";
3740
Events = new WsFederationEvents();
3841
}
3942

@@ -163,7 +166,7 @@ public TokenValidationParameters TokenValidationParameters
163166
public bool AllowUnsolicitedLogins { get; set; }
164167

165168
/// <summary>
166-
/// Requests received on this path will cause the handler to invoke SignOut using the SignInScheme.
169+
/// Requests received on this path will cause the handler to invoke SignOut using the SignOutScheme.
167170
/// </summary>
168171
public PathString RemoteSignOutPath { get; set; }
169172

test/Microsoft.AspNetCore.Authentication.WsFederation.Test/WsFederationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public async Task RemoteSignoutRequestTriggersSignout()
117117
{
118118
var httpClient = CreateClient();
119119

120-
var response = await httpClient.GetAsync("/signout-wsfed?wa=wsignoutcleanup1.0");
120+
var response = await httpClient.GetAsync("/signin-wsfed?wa=wsignoutcleanup1.0");
121121
response.EnsureSuccessStatusCode();
122122

123123
var cookie = response.Headers.GetValues(HeaderNames.SetCookie).Single();

0 commit comments

Comments
 (0)