Skip to content

Commit

Permalink
Merge pull request #7 from EasyOC/ImplicitLogout
Browse files Browse the repository at this point in the history
add ImplicitLogout module to EasyOC.Users
  • Loading branch information
hyzx86 committed Feb 18, 2023
2 parents 54ef004 + 99ff583 commit c7607a1
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions EasyOC.build/Commons.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>
EasyOC is committed to making OrchardCore development easier.
This repositry is referencing a stable build of Orchard Core (1.5.0).
国内用户 欢迎加入QQ 群:877196442
</Description>
<Copyright>Tony Han</Copyright>
Expand Down
51 changes: 51 additions & 0 deletions src/Modules/EasyOC.Users/Controllers/EocOpenIdAccessController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Server.AspNetCore;
using OrchardCore.Modules;
using OrchardCore.OpenId;
using OrchardCore.OpenId.ViewModels;

namespace EasyOC.Users.Controllers
{
[Authorize, Feature(OpenIdConstants.Features.Server)]
public class EocOpenIdAccessController : Controller
{
[AllowAnonymous, HttpGet, HttpPost, IgnoreAntiforgeryToken]
public async Task<IActionResult> Logout()
{
var response = HttpContext.GetOpenIddictServerResponse();
if (response != null)
{
return View("Error", new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
}

var request = HttpContext.GetOpenIddictServerRequest();
if (request == null)
{
return NotFound();
}

// Warning: unlike the main Logout method, this method MUST NOT be decorated with
// [IgnoreAntiforgeryToken] as we must be able to reject end session requests
// sent by a malicious client that could abuse this interactive endpoint to silently
// log the user out without the user explicitly approving the log out operation.

await HttpContext.SignOutAsync();

// If no post_logout_redirect_uri was specified, redirect the user agent
// to the root page, that should correspond to the home page in most cases.
if (string.IsNullOrEmpty(request.PostLogoutRedirectUri))
{
return Redirect("~/");
}

return SignOut(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
}
}
}
2 changes: 1 addition & 1 deletion src/Modules/EasyOC.Users/EasyOC.Users.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="$(OrchardCoreVersion)" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="$(OrchardCoreVersion)" />

<PackageReference Include="OrchardCore.OpenId.Core" Version="$(OrchardCoreVersion)" />
<PackageReference Include="OrchardCore.OpenId" Version="$(OrchardCoreVersion)" />

<PackageReference Include="OrchardCore.Users" Version="$(OrchardCoreVersion)" />
<ProjectReference Include="..\EasyOC.ReplaceAction\EasyOC.ReplaceAction.csproj" />
Expand Down
18 changes: 16 additions & 2 deletions src/Modules/EasyOC.Users/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@
[assembly: Module(
Name = "EasyOC.Users",
Author = "Tony Han",
Website = "https://github.com/EasyOC/EasyOC.Modules",
Website = "https://github.com/EasyOC/EasyOC.Modules"
)]

[assembly: Feature(
Id = "EasyOC.Users",
Name = "EasyOC.Users",
Dependencies = new[] { "OrchardCore.Users" },
Description = "EasyOC.Users",
Description = "Make the UserLogin Script supports Update custom user properties and Update `UserClaims`",
Category = "Content Management"
)]


[assembly: Feature(
Id = "EasyOC.OpenId",
Name = "Implicit logout",
Dependencies = new[] { "OrchardCore.OpenId" },
Description = "Confirmation is no longer required when logging out using OpenId",
Category = "Content Management"
)]
15 changes: 14 additions & 1 deletion src/Modules/EasyOC.Users/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EasyOC.Users.Handlers;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Modules;
using OrchardCore.OpenId.Controllers;
using OrchardCore.Users.Controllers;
using OrchardCore.Users.Handlers;

Expand All @@ -28,8 +29,20 @@ public override void ConfigureServices(IServiceCollection services)
nameof(EocAccountController.LinkExternalLogin),
nameof(EocAccountController.ExternalLoginCallback),
nameof(EocAccountController.RegisterExternalLogin)
);
);
}

}

[RequireFeatures("OrchardCore.OpenId", "EasyOC.ReplaceAction")]
public class OpenIdStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.ReplaceActionByActionNames<EocOpenIdAccessController>(
typeof(AccessController).FullName,
nameof(EocOpenIdAccessController.Logout)
);
}
}
}

0 comments on commit c7607a1

Please sign in to comment.