#pragma warning disable 1998 //Should only be hit in active mode. protected override async Task ApplyResponseChallengeAsync() { if (Response.StatusCode != (int)HttpStatusCode.Unauthorized || !Options.LoginPath.HasValue) { return; } var challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode); if (challenge == null) { return; } //TODO: Change to Uri objects? var baseUri = Request.Scheme + Uri.SchemeDelimiter + Request.Host + Request.PathBase; var currentUri = //baseUri + Request.Path + Request.QueryString; var loginUri = baseUri + Options.LoginPath;// + //new QueryString(Options.ReturnUrlParameter, currentUri); var redirectUri = Options.RedirectPath.HasValue ? baseUri + Options.RedirectPath + new QueryString(Options.ReturnUrlParameter, currentUri) : currentUri; // Save the original challenge URI so we can redirect back to it when we're done. var properties = challenge.Properties; if (String.IsNullOrEmpty(properties.RedirectUri)) { properties.RedirectUri = redirectUri; } //Stick ReturnUrl into the dictionary? //properties.Dictionary["ReturnUrl"] = currentUri; var authenticationEndpoint = loginUri; if (Options.UseStateCookie) { Context.Response.Cookies.Append(Options.StateKey, Options.StateDataFormat.Protect(properties), new CookieOptions { HttpOnly = true, Secure = Request.IsSecure }); } else { authenticationEndpoint = WebUtilities.AddQueryString(loginUri, Options.StateKey, Options.StateDataFormat.Protect(properties)); } var redirectContext = new LDAPApplyRedirectContext(Context, Options, properties, new Uri(authenticationEndpoint)); Options.Provider.ApplyRedirect(redirectContext); }
/// <summary> /// Called when a Challenge causes a redirect to authorize endpoint in the LDAP middleware /// </summary> /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param> public virtual void ApplyRedirect(LDAPApplyRedirectContext context) { OnApplyRedirect(context); }