Remove special cookie ajax redirect behavior
This commit is contained in:
parent
8d7f052cf4
commit
5065835a05
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
OnResponseSignIn = context => { };
|
OnResponseSignIn = context => { };
|
||||||
OnResponseSignedIn = context => { };
|
OnResponseSignedIn = context => { };
|
||||||
OnResponseSignOut = context => { };
|
OnResponseSignOut = context => { };
|
||||||
OnApplyRedirect = DefaultBehavior.ApplyRedirect;
|
OnApplyRedirect = context => context.Response.Redirect(context.RedirectUri);
|
||||||
OnException = context => { };
|
OnException = context => { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.Cookies
|
|
||||||
{
|
|
||||||
internal static class DefaultBehavior
|
|
||||||
{
|
|
||||||
internal static readonly Action<CookieApplyRedirectContext> ApplyRedirect = context =>
|
|
||||||
{
|
|
||||||
if (IsAjaxRequest(context.Request))
|
|
||||||
{
|
|
||||||
var jsonResponse = JsonConvert.SerializeObject(new
|
|
||||||
{
|
|
||||||
status = context.Response.StatusCode,
|
|
||||||
headers = new
|
|
||||||
{
|
|
||||||
location = context.RedirectUri
|
|
||||||
}
|
|
||||||
}, Formatting.None);
|
|
||||||
|
|
||||||
context.Response.StatusCode = 200;
|
|
||||||
context.Response.Headers.Append("X-Responded-JSON", jsonResponse);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.Redirect(context.RedirectUri);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static bool IsAjaxRequest(HttpRequest request)
|
|
||||||
{
|
|
||||||
var query = request.Query;
|
|
||||||
if (query != null)
|
|
||||||
{
|
|
||||||
if (query["X-Requested-With"] == "XMLHttpRequest")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var headers = request.Headers;
|
|
||||||
if (headers != null)
|
|
||||||
{
|
|
||||||
if (headers["X-Requested-With"] == "XMLHttpRequest")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -533,27 +533,11 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
|
|
||||||
clock.Add(TimeSpan.FromMinutes(4));
|
clock.Add(TimeSpan.FromMinutes(4));
|
||||||
|
|
||||||
Transaction transaction5 = await SendAsync(server, "http://example.com/me/Cookies", transaction4.CookieNameValue);
|
var transaction5 = await SendAsync(server, "http://example.com/me/Cookies", transaction4.CookieNameValue);
|
||||||
transaction5.SetCookie.ShouldBe(null);
|
transaction5.SetCookie.ShouldBe(null);
|
||||||
FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe("Alice");
|
FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe("Alice");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task AjaxRedirectsAsExtraHeaderOnTwoHundred()
|
|
||||||
{
|
|
||||||
var server = CreateServer(options =>
|
|
||||||
{
|
|
||||||
options.LoginPath = new PathString("/login");
|
|
||||||
options.AutomaticAuthentication = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
var transaction = await SendAsync(server, "http://example.com/protected", ajaxRequest: true);
|
|
||||||
transaction.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
|
||||||
var responded = transaction.Response.Headers.GetValues("X-Responded-JSON");
|
|
||||||
responded.Count().ShouldBe(1);
|
|
||||||
responded.Single().ShouldContain("\"location\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CookieUsesPathBaseByDefault()
|
public async Task CookieUsesPathBaseByDefault()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue