什么会导致Internet Explorer替换HTTP标头
Authorization : Bearer <server-provided-token>
同
Authorization : Negotiate <some token>
在发出AJAX请求时?
细节
在Internet Explorer中,Authorization: Bearer ...Internet Explorer使用标头发送一些配置为包含标头的AJAX请求Authorization: Negotiate ....
例如,Fiddler显示三个请求中的前两个包含Authorization : Bearer...标题,而第三个请求突然包含Authorization : Negotiate...标题.前两个请求成功,第三个请求失败,因为无法正确验证请求.
所有请求都是使用相同的客户端代码构建的,并且是一个接一个地进行的(在一秒的范围内).我已经验证了Authorization标头Bearer在所有三种情况下都正确包含令牌,直到请求提供给浏览器为止.
另外,我在Chrome中看不到相同的行为; 它只发生在IE中.
要求1
GET http://localhost/myapp/api/User HTTP/1.1 Accept: application/json, text/plain, */* Authorization: Bearer oEXS5IBu9huepzW6jfh-POMA18AUA8yWZsPfBPZuFf_JJxq-DKIt0JDyPXSiGpmV_cpT8FlL3D1DN-Tv5ZbT73MTuBOd5y75-bsx9fZvOeJgg04JcO0cUajdCH2h5QlMP8TNwgTpHg-TR9FxyPk3Kw6bQ6tQCOkOwIG_FmEJpP89yrOsoYJoCfrAoZ7M4PVcik9F9qtPgXmWwXB2eHDtkls44wITF_yM_rPm5C47OPCvMVTPz30KwoEPi6fHUcL3qHauP-v9uypv2e48TyPHUwLYmNFxyafMhBx4TkovnRcsdLHZiHmSjMq0V9a2Vw70 Referer: http://localhost/client/login.html Accept-Language: en-US Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko Host: localhost DNT: 1 Connection: Keep-Alive
要求2
POST http://localhost/myapp/api/Permissions HTTP/1.1 Referer: …
我正在尝试将我的web api 2项目移动到ASP.NET 5.但是我有许多不再存在的元素.
例如IHttpActionResult或Ok(), NotFound()方法.或者RoutePrefix[]
我应该改变每一个IHttpActionResult用IActionResult?改变Ok()用new ObjectResult?(它是一样的吗?)
那怎么样HttpConfiguration似乎在startup.cs中不存在?
我试图了解MVC 5中单页应用程序模板中新的OWIN Bearer Token身份验证过程.如果我错了请更正我,对于OAuth密码客户端身份验证流程,承载令牌身份验证通过检查http授权请求标头来工作对于承载访问令牌代码,以查看请求是否经过身份验证,它不依赖cookie来检查特定请求是否经过身份验证.
根据这篇文章:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
using (IdentityManager identityManager = _identityManagerFactory.CreateStoreManager())
{
if (!await identityManager.Passwords.CheckPasswordAsync(context.UserName, context.Password))
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
string userId = await identityManager.Logins.GetUserIdForLocalLoginAsync(context.UserName);
IEnumerable<Claim> claims = await GetClaimsAsync(identityManager, userId);
ClaimsIdentity oAuthIdentity = CreateIdentity(identityManager, claims,
context.Options.AuthenticationType);
ClaimsIdentity cookiesIdentity = CreateIdentity(identityManager, claims,
_cookieOptions.AuthenticationType);
AuthenticationProperties properties = await CreatePropertiesAsync(identityManager, userId);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
}
}
Run Code Online (Sandbox Code Playgroud)
GrantReourceOwnerCredentials函数不仅使用以下行构成票证:context.Validated(ticket); 但它也组成了一个cookie标识,并使用以下行将其设置为cookie:context.Request.Context.Authentication.SignIn(cookiesIdentity);
所以我的问题是,这个函数中cookie的确切目的是什么?AuthenticationTicket不应该足够用于身份验证吗?
我是ASP.NET MVC 5的新手,所以我试图尽可能地通过练习来学习它.
所以我正在考虑使用ASP.NET MVC的新OWIN实现来实现我的项目的身份验证和授权.也就是说,我正在以一种可以与各种类型的数据库一起工作的方式构建项目.
到目前为止,我使用了通用的ADO.NET元素(例如DbDataReaderetc),我拒绝使用任何ORM.所以我想知道我是否可以继续使用ASP.NET的新身份系统,或者如果我这样做,我将被绑定到Entity Framework和SQL Server吗?
Startup.cs是一种初始化应用程序而不是Application_StartGlobal.asax 的新方法,它很好.但是有没有地方放置我的拆解逻辑,例如:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_End()
{
// Release you ServiceBroker listener
SqlDependency.Stop(connString);
}
}
Run Code Online (Sandbox Code Playgroud)
在Microsoft.Owin命名空间中查找,但它似乎只有OwinStartupAttribute.这是否意味着应用程序生命周期事件仍由System.Web.HttpApplication实例处理,并且OWIN规范不支持?
在Katana(OWIN)实现中实现全局异常捕获器处理程序的正确方法是什么?
在作为Azure云服务(工作者角色)运行的自托管OWIN/Katana实现中,我将此代码放在中间件中:
throw new Exception("pooo");
Run Code Online (Sandbox Code Playgroud)
然后我将此代码放在Startup类Configuration方法中,在事件处理程序中设置断点:
AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledExceptionEventHandler;
Run Code Online (Sandbox Code Playgroud)
和同一个类中的事件处理程序(在第一行设置断点):
private static void CurrentDomain_UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
{
var exception = (Exception)e.ExceptionObject;
Trace.WriteLine(exception.Message);
Trace.WriteLine(exception.StackTrace);
Trace.WriteLine(exception.InnerException.Message);
}
Run Code Online (Sandbox Code Playgroud)
代码运行时,不会触发断点.Visual Studio输出窗口确实包括此:
A first chance exception of type 'System.Exception' occurred in redacted.dll
A first chance exception of type 'System.Exception' occurred in mscorlib.dll
Run Code Online (Sandbox Code Playgroud)
我也尝试将连接和处理程序移动到Worker Role OnStart方法,但仍然没有命中断点.
我根本没有使用WebAPI,但确实查看过那里做的帖子,但我没有发现任何明确的内容,所以我在这里.
在.NET Framework 4.5.2,VS 2013上运行.
所有想法都赞赏.谢谢.
我似乎不清楚如何IsPersistent在OWIN cookie身份验证中工作,下面的代码是使用IsPersistent:
var context = Request.GetOwinContext();
var authManager = context.Authentication;
var properties = new AuthenticationProperties { IsPersistent = isPersistence };
authManager.SignIn(properties, identity);
Run Code Online (Sandbox Code Playgroud)
当用户检查/取消选中Remember me(IsPersistent后面使用)时,我没有看到区别,因为如果我关闭Chrome浏览器并再次打开它以与网站一起使用,则cookie .AspNet.ApplicationCookie仍然存在,即使我检查或取消选中它也可以让我进入Remember me.
我已检查链接IsPersistent上的定义:
获取或设置是否跨多个请求持久保存身份验证会话.
但是,因为我看到它仍然有效,所以不要太了解.
设置OWIN cookie身份验证的代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = ApplicationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromMinutes(30),
LoginPath = new PathString("/Account/LogOn")
});
Run Code Online (Sandbox Code Playgroud) 我最近开始研究新的ASP.Net Identity框架和Katana中间件,那里有大量的代码和文档,但我看到的是很多相互矛盾的信息,我想这是一个代码更新频率增加的结果.
我期待使用WsFederation认证与内部ADFS分2次服,但方式OWIN认证管道工程有我有点困惑,我希望有人能提供一些确切的信息.
具体来说,我感兴趣的是应该连接中间件的顺序以及在各种场景中需要哪些模块,我想摆脱任何不需要的东西,同时确保过程尽可能安全.
例如,它似乎UseWsFederationAuthentication应该与之结合使用UseCookieAuthentication,但我不确定正确的AuthenticationType是什么(这篇帖子暗示它只是一个标识符字符串,但它的值是否显着?)或者即使我们仍然需要用SetDefaultSignInAsAuthenticationType.
我还注意到Katana项目讨论板上的这个帖子,Tratcher在那里提到了一个常见的错误,但是对于哪部分代码出错是不是很具体.
就个人而言,我现在使用以下(使用自定义SAML令牌处理程序将令牌字符串读入有效的XML文档),它对我有用,但它是否最佳?
var appURI = ConfigurationManager.AppSettings["app:URI"];
var fedPassiveTokenEndpoint = ConfigurationManager.AppSettings["wsFederation:PassiveTokenEndpoint"];
var fedIssuerURI = ConfigurationManager.AppSettings["wsFederation:IssuerURI"];
var fedCertificateThumbprint = ConfigurationManager.AppSettings["wsFederation:CertificateThumbprint"];
var audienceRestriction = new AudienceRestriction(AudienceUriMode.Always);
audienceRestriction.AllowedAudienceUris.Add(new Uri(appURI));
var issuerRegistry = new ConfigurationBasedIssuerNameRegistry();
issuerRegistry.AddTrustedIssuer(fedCertificateThumbprint, fedIssuerURI);
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType // "Federation"
}
);
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = appURI,
SignOutWreply = appURI,
Configuration = new WsFederationConfiguration
{
TokenEndpoint = fedPassiveTokenEndpoint …Run Code Online (Sandbox Code Playgroud) 我的OWIN Web服务在Visual Studio 2013中运行得很漂亮,但是当我将它发布到真正的IIS站点时,它就好像启动类中的Configuration方法还没有运行一样.我可以做"正常"的事情,比如浏览应用程序并查看目录结构,但是假设用IAppBuilder建立的任何东西都不起作用.例如,当我浏览到在Startup中设置的URL以发出OAuth2承载令牌时,我收到404.0错误.好像Startup.Configuration(IAppBuilder应用程序)从未运行过.
我正在使用该[assembly: OwinStartup(typeof(MyNamespacedStartupClass))]属性来指定启动类.
我已经使用NuGet按照我看过的说明同时获得了Microsoft.Owin.Host.SystemWeb和Microsoft.Owin.Diagnostics,但这并没有什么区别.
我还需要做什么?
我在OWIN Cookie身份验证方面遇到了一些问题.我有一个.Net站点,其中有一些MVC页面使用cookie身份验证和受承载令牌保护的WebAPI资源.
当我退出时,我删除了客户端上的访问令牌,因此后续的API请求将不会在标头中包含令牌,因此将无法通过身份验证.这部分很好.
以同样的方式,我也希望注销以删除MVC页面使用的cookie.我在服务器上执行了以下操作:
[Route("Logout")]
public IHttpActionResult Logout()
{
var ctx = Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignOut();
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
但是,在调用Logout之后,我仍然可以访问受保护的MVC页面,即使这个cookie本应被Logout调用删除了.
看起来很简单,所以我可能错过了一些东西.
谢谢,
owin ×10
c# ×4
katana ×4
asp.net-mvc ×2
.net ×1
adfs ×1
angularjs ×1
asp.net ×1
asp.net-core ×1
cookies ×1
iis ×1
sql-server ×1