Browse Source

Added new Logout functionality for identityserver post logout redirect event.

pull/2670/head
Galip Tolga Erdem 7 years ago
parent
commit
0139e72b02
  1. 44
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs
  2. 1
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs
  3. 3
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Logout.cshtml
  4. 27
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Logout.cshtml.cs

44
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs

@ -0,0 +1,44 @@
using IdentityServer4.Services;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Account.Web.Pages.Account
{
[ExposeServices(typeof(LogoutModel))]
public class IdentityServerSupportedLogoutModel : LogoutModel
{
protected IIdentityServerInteractionService Interaction { get; }
public IdentityServerSupportedLogoutModel(IIdentityServerInteractionService interaction)
{
Interaction = interaction;
}
public override async Task<IActionResult> OnGetAsync()
{
await SignInManager.SignOutAsync().ConfigureAwait(false);
var logoutId = Request.Query["logoutId"].ToString();
if (!string.IsNullOrEmpty(logoutId))
{
var logoutContext = await Interaction.GetLogoutContextAsync(logoutId).ConfigureAwait(false);
var postLogoutUri = logoutContext.PostLogoutRedirectUri;
if (!string.IsNullOrEmpty(postLogoutUri))
{
return Redirect(postLogoutUri);
}
}
if (ReturnUrl != null)
{
return LocalRedirect(ReturnUrl);
}
return RedirectToPage("/Account/Login");
}
}
}

1
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs

@ -17,6 +17,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
}
//todo@alper: this method can be moved to AccountController like "account/logout"
//No longer needed. Already implemented Pages/Account/Logout
public async Task<IActionResult> Index(string returnUrl = null)
{
await _signInManager.SignOutAsync().ConfigureAwait(false);

3
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Logout.cshtml

@ -0,0 +1,3 @@
@page "/Account/Logout"
@inherits Volo.Abp.Account.Web.Pages.Account.AccountPage
@model Volo.Abp.Account.Web.Pages.Account.LogoutModel

27
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Logout.cshtml.cs

@ -0,0 +1,27 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.Account.Web.Pages.Account
{
public class LogoutModel : AccountPageModel
{
[HiddenInput]
[BindProperty(SupportsGet = true)]
public string ReturnUrl { get; set; }
[HiddenInput]
[BindProperty(SupportsGet = true)]
public string ReturnUrlHash { get; set; }
public virtual async Task<IActionResult> OnGetAsync()
{
await SignInManager.SignOutAsync().ConfigureAwait(false);
if (ReturnUrl != null)
{
return RedirectSafely(ReturnUrl, ReturnUrlHash);
}
return RedirectToPage("/Account/Login");
}
}
}
Loading…
Cancel
Save