Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
ensure we call signout on user service for federated signout
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Nov 23, 2015
1 parent 6678528 commit f7856c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
22 changes: 9 additions & 13 deletions source/Core/Endpoints/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,21 +604,17 @@ public async Task<IHttpActionResult> Logout(string id = null)
context.QueueRemovalOfSignOutMessageCookie(id);
context.ClearAuthenticationCookies();
context.SignOutOfExternalIdP();

if (user != null && user.Identity.IsAuthenticated)
{
var message = signOutMessageCookie.Read(id);
var signOutContext = new SignOutContext
{
Subject = user
};

if (message != null)
{
signOutContext.ClientId = message.ClientId;
}
string clientId = null;
var message = signOutMessageCookie.Read(id);
if (message != null)
{
clientId = message.ClientId;
}
await context.CallUserServiceSignOutAsync(clientId);

await this.userService.SignOutAsync(signOutContext);
if (user != null && user.Identity.IsAuthenticated)
{
await eventService.RaiseLogoutEventAsync(user, id, message);
}

Expand Down
23 changes: 23 additions & 0 deletions source/Core/Extensions/InternalOwinExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using IdentityServer3.Core.Configuration;
using IdentityServer3.Core.Configuration.Hosting;
using IdentityServer3.Core.Models;
using IdentityServer3.Core.Services;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using System;
Expand Down Expand Up @@ -506,5 +507,27 @@ public static void SignOutOfExternalIdP(this IOwinContext context)
}
}
}

public static async Task CallUserServiceSignOutAsync(this IOwinContext context, string clientId = null)
{
if (context == null) throw new ArgumentNullException("context");

var result = await context.Authentication.AuthenticateAsync(Constants.PrimaryAuthenticationType);
if (result != null)
{
var user = result.Identity;
if (user != null && user.IsAuthenticated)
{
var signOutContext = new SignOutContext
{
Subject = new ClaimsPrincipal(user),
ClientId = clientId
};

var userService = context.ResolveDependency<IUserService>();
await userService.SignOutAsync(signOutContext);
}
}
}
}
}
1 change: 1 addition & 0 deletions source/Core/Extensions/OwinEnvironmentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ public static async Task ProcessFederatedSignoutAsync(this IDictionary<string, o

var context = new OwinContext(env);
context.ClearAuthenticationCookies();
await context.CallUserServiceSignOutAsync();

var sessionCookie = context.ResolveDependency<SessionCookie>();
var sid = sessionCookie.GetSessionId();
Expand Down

0 comments on commit f7856c1

Please sign in to comment.