一步一步学习IdentityServer3 (10)
在某些服务器环境下 identityserver3 会闹情绪, 比如在google浏览器下授权失败(陷入死循环)
查了很多资料好像然并卵
Microsoft.Owin.Security.Notifications.AuthenticationFailedNotification`2[Microsoft.IdentityModel.Protocols.OpenIdConnectMessage,Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions]
监控错误 Owin中间件cookies丢失导致授权失败
UseKentorOwinCookieSaver 用这个修复了一下 还是不行 ,解决方案在进一步研究中
找到几中方案 先足个试试
方案一 由于Google浏览器下关闭浏览器没有清除cookies,重写中间件处理
public static class OpenIdConnectAuthenticationPatchedMiddlewareExtension
{
public static Owin.IAppBuilder UseOpenIdConnectAuthenticationPatched(this Owin.IAppBuilder app, Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions openIdConnectOptions)
{
if (app == null)
{
throw new System.ArgumentNullException("app");
}
if (openIdConnectOptions == null)
{
throw new System.ArgumentNullException("openIdConnectOptions");
}
System.Type type = typeof(OpenIdConnectAuthenticationPatchedMiddleware);
object[] objArray = new object[] { app, openIdConnectOptions };
return app.Use(type, objArray);
}
} public class OpenIdConnectAuthenticationPatchedMiddleware : OpenIdConnectAuthenticationMiddleware
{
private readonly Microsoft.Owin.Logging.ILogger _logger; public OpenIdConnectAuthenticationPatchedMiddleware(Microsoft.Owin.OwinMiddleware next, Owin.IAppBuilder app, Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions options)
: base(next, app, options)
{
this._logger = Microsoft.Owin.Logging.AppBuilderLoggerExtensions.CreateLogger<OpenIdConnectAuthenticationPatchedMiddleware>(app);
} protected override Microsoft.Owin.Security.Infrastructure.AuthenticationHandler<OpenIdConnectAuthenticationOptions> CreateHandler()
{
return new SawtoothOpenIdConnectAuthenticationHandler(_logger);
} }
public class SawtoothOpenIdConnectAuthenticationHandler : OpenIdConnectAuthenticationHandler
{
public SawtoothOpenIdConnectAuthenticationHandler(Microsoft.Owin.Logging.ILogger logger)
: base(logger) { } protected override void RememberNonce(OpenIdConnectMessage message, string nonce)
{
var oldNonces = Request.Cookies.Where(kvp => kvp.Key.StartsWith(OpenIdConnectAuthenticationDefaults.CookiePrefix + "nonce"));
if (oldNonces.Any())
{
Microsoft.Owin.CookieOptions cookieOptions = new Microsoft.Owin.CookieOptions
{
HttpOnly = true,
Secure = Request.IsSecure
};
foreach (KeyValuePair<string, string> oldNonce in oldNonces)
{
Response.Cookies.Delete(oldNonce.Key, cookieOptions);
}
}
base.RememberNonce(message, nonce);
}
}
app.UseOpenIdConnectAuthenticationPatched 重写不行 Pass掉了
方案二 说是 Microsoft.Owin.Security.OpenIdConnect 版本问题 我现在用的 3.1.0 降级版本 ,但是这样原有高版本修复的问题就会出现 先试试 降级到3.0.0 相关dll 全部降级到3.0.0
发现没毛病,我的授权站点是与系统业务站点分离开的,所以这里其实只需要 业务站点中的OpenId版本降级就可以了,预编译发布可能会有问题 直接发布ok 完美解决 (只是有些服务器环境下用此方案) 毕竟3.1.0 修复了一些bug
方案三 说是 授权必须与业务站点一起,这个肯定不用测试了 我的就是分开的
方案四 Kentor.OwinCookieSaver 中间件修复 也是不行的
综上此坑:
降级是Ok的~~~~~~~ 亲身经历
一步一步学习IdentityServer3 (10)的更多相关文章
- 一步一步学习IdentityServer3 (1)
学习之初: IdentityServer3我自己最开始了解到的就是做一个SSO单点登录,后面发现还有单独的认证服务功能,其实它还可以做APIs的访问控制,资源授权,另外还可以为提供第三方登录,其他的自 ...
- 一步一步学习IdentityServer3 (2)
下面就来做一个例子:IdentityServer3服务端的配置 VS2015创建一个MVC项目 IdrOAuth 用来授权的认证的站点
- 一步一步学习IdentityServer3 (4)
其实上述例子 很多都很找到 但是在实际生态环境中给例子有很多不一样的地方 比如自定已登录界面怎么做? 怎么访问自己的用户数据库实现登录? 怎么在接口中使用,在接口中又怎么实现与Idr3结合授权? 等等 ...
- 一步一步学习SignalR进行实时通信_4_Hub
原文:一步一步学习SignalR进行实时通信_4_Hub 一步一步学习SignalR进行实时通信\_4_Hub SignalR 一步一步学习SignalR进行实时通信_4_Hub 前言 创建Hub 配 ...
- 一步一步学习SignalR进行实时通信_3_通过CORS解决跨域
原文:一步一步学习SignalR进行实时通信_3_通过CORS解决跨域 一步一步学习SignalR进行实时通信\_3_通过CORS解决跨域 SignalR 一步一步学习SignalR进行实时通信_3_ ...
- 一步一步学习SignalR进行实时通信_2_Persistent Connections
原文:一步一步学习SignalR进行实时通信_2_Persistent Connections 一步一步学习SignalR进行实时通信\_2_Persistent Connections Signal ...
- 一步一步学习Vim 全图解释
转载:http://linux.chinaunix.net/techdoc/desktop/2009/01/03/1056322.shtml 一步一步学习Vim 全图解释 以下注释,根据图示和自己实践 ...
- 一步一步学习JNI
本文来自网易云社区 作者:孙有军 前言 本篇的主要目的就是JNI开发入门,使大家对JNI开发流程有一个大致的了解,后续再进行深入学习. JNI不是Android特有的,JNI是Java Native ...
- 一步一步学习GTK
完成课设,偶然碰到GTK,索性学习一遍 转载自ikoDotA の BLOG (一).一步一步学GTK+之开篇 一.什么是GTK+ GTK+ 是一种函数库是用来帮助制作图形交互界面的.整个函数库都是由C ...
随机推荐
- 【题解】Catering World Finals 2015 上下界费用流
Prelude 传送到Codeforces:0.0 Solution 板子题,在这里贴个板子. 这题面是smg?题面中有说每个点只能经过一次吗?是我瞎了吗? 因为这WA on test 27一个小时, ...
- img、列表和table标签
一.img图片 <body> <a href="https://www.fmtxt.com"> <img src="images/1.jpg ...
- Windows 下安装和配置 MongoDB(二)
因为电脑重新安装了系统,所以要重新安装开发环境,按照之前写过的一篇博客介绍的步骤进行安装,发现报了一些错误,下面是遇到的问题和解决方法: 首先下载安装就不多说了,下载地址:https://www.mo ...
- Linux启动的流程
2017年1月10日, 星期二 Linux启动的流程 null
- Centos7系统中安装Nginx1.8.0
Nginx的安装 tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure make make install /usr/local/nginx/ ...
- [转载]asp.net mvc: why is Html.CheckBox generating an additional hidden input
http://stackoverflow.com/questions/2697299/asp-net-mvc-why-is-html-checkbox-generating-an-additional ...
- 实验一 《网络对抗技术》逆向及Bof技术
- 《C语言程序设计基础I》秋季学习总结
希望下学期比这学期轻松,学习能力上升,只是越发丰富. 一步一步的走踏实了
- 回顾一些较简单的dp题
1.导弹拦截 (+贪心) 两问:一个导弹拦截系统最多能拦多少导弹 要拦截所有导弹至少需要多少拦截系统 第一问感觉是一个比较巧妙的方法: 维护一个单调递减的序列 length[] 记录的是拦截导弹的高 ...
- Linux IO调度算法
Linux IO调度算法 操作系统的调度 CPU调度 CPU scheduler IO调度 IO scheduler IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移 ...