diff --git a/EasyOC.build/Commons.props b/EasyOC.build/Commons.props index c031bde..b5b5eb1 100644 --- a/EasyOC.build/Commons.props +++ b/EasyOC.build/Commons.props @@ -12,6 +12,7 @@ true EasyOC is committed to making OrchardCore development easier. + This repositry is referencing a stable build of Orchard Core (1.5.0). 国内用户 欢迎加入QQ 群:877196442 Tony Han diff --git a/src/Modules/EasyOC.Users/Controllers/EocOpenIdAccessController.cs b/src/Modules/EasyOC.Users/Controllers/EocOpenIdAccessController.cs new file mode 100644 index 0000000..34f7e49 --- /dev/null +++ b/src/Modules/EasyOC.Users/Controllers/EocOpenIdAccessController.cs @@ -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 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); + } + } +} diff --git a/src/Modules/EasyOC.Users/EasyOC.Users.csproj b/src/Modules/EasyOC.Users/EasyOC.Users.csproj index a6ebce4..90aedf4 100644 --- a/src/Modules/EasyOC.Users/EasyOC.Users.csproj +++ b/src/Modules/EasyOC.Users/EasyOC.Users.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Modules/EasyOC.Users/Manifest.cs b/src/Modules/EasyOC.Users/Manifest.cs index bef8c38..ebcbe7b 100644 --- a/src/Modules/EasyOC.Users/Manifest.cs +++ b/src/Modules/EasyOC.Users/Manifest.cs @@ -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" )] diff --git a/src/Modules/EasyOC.Users/Startup.cs b/src/Modules/EasyOC.Users/Startup.cs index 9918e64..a0bc1bb 100644 --- a/src/Modules/EasyOC.Users/Startup.cs +++ b/src/Modules/EasyOC.Users/Startup.cs @@ -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; @@ -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( + typeof(AccessController).FullName, + nameof(EocOpenIdAccessController.Logout) + ); + } + } } \ No newline at end of file