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

Commit b36804e

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

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ 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+
if (Options.RemoteSignOutPath.HasValue && Options.RemoteSignOutPath == Request.Path && HttpMethods.IsGet(Request.Method)
61+
&& string.Equals(Request.Query[WsFederationConstants.WsFederationParameterNames.Wa],
62+
WsFederationConstants.WsFederationActions.SignOutCleanup, StringComparison.OrdinalIgnoreCase))
6163
{
64+
// We've received a remote sign-out request
6265
return HandleRemoteSignOutAsync();
6366
}
6467

@@ -374,18 +377,12 @@ public async virtual Task SignOutAsync(AuthenticationProperties properties)
374377
}
375378

376379
/// <summary>
377-
/// Handles requests to the RemoteSignOutPath and signs out the user.
380+
/// Handles wsignoutcleanup1.0 messages sent to the RemoteSignOutPath
378381
/// </summary>
379382
/// <returns></returns>
380383
protected virtual async Task<bool> HandleRemoteSignOutAsync()
381384
{
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-
385+
var message = new WsFederationMessage(Request.Query.Select(pair => new KeyValuePair<string, string[]>(pair.Key, pair.Value)));
389386
var remoteSignOutContext = new RemoteSignOutContext(Context, Scheme, Options, message);
390387
await Events.RemoteSignOut(remoteSignOutContext);
391388

@@ -403,15 +400,8 @@ protected virtual async Task<bool> HandleRemoteSignOutAsync()
403400
}
404401
}
405402

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

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

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

0 commit comments

Comments
 (0)