Last active
February 24, 2021 01:39
-
-
Save moo2u2/16d44d37648c5cb45ba98ed16cdd3348 to your computer and use it in GitHub Desktop.
Version of Sitecore's GoToLoginPage processor for sites using CallbackAuthority setting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.Abstractions; | |
using Sitecore.Diagnostics; | |
using Sitecore.Owin.Authentication.IdentityServer.Extensions; | |
using Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.ApplyRedirect; | |
using System; | |
using System.Collections.Specialized; | |
using System.Web; | |
namespace Identity.Pipelines.CookieAuthentication.ApplyRedirect | |
{ | |
public class CustomGoToLoginPage : GoToLoginPage | |
{ | |
BaseSettings Settings { get; } | |
public CustomGoToLoginPage(BaseSettings settings) | |
{ | |
Settings = settings; | |
} | |
public override void Process(ApplyRedirectArgs args) | |
{ | |
Assert.ArgumentNotNull(args, nameof(args)); | |
string callbackAuthority = Settings.IdentityServer().CallbackAuthority; | |
Uri baseUrl = args.Context.Request.Uri; | |
if (!string.IsNullOrEmpty(callbackAuthority)) | |
Uri.TryCreate(callbackAuthority, UriKind.Absolute, out baseUrl); | |
Uri uri = new Uri(baseUrl, new Uri(args.Context.RedirectUri, UriKind.RelativeOrAbsolute)); | |
if (!string.Equals(args.Context.Options.LoginPath.Value, uri.LocalPath, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(args.Site?.LoginPage)) | |
return; | |
NameValueCollection queryString = HttpUtility.ParseQueryString(uri.Query); | |
queryString[args.Context.Options.ReturnUrlParameter] = HttpContext.Current.Request.RawUrl; | |
UriBuilder uriBuilder = new UriBuilder(uri) | |
{ | |
Path = args.Site.LoginPage, | |
Query = queryString.ToString() | |
}; | |
args.Context.RedirectUri = uriBuilder.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment