.net 4.0+ 应用接入openid Server步骤
.net 4.0+ 应用接入openid Server步骤:
Requirements:Microsoft.AspNet.Mvc 5.2.4+
1 确认应用是否是katana启动(项目引用了owin,根目录下有startup.cs)。
如果不是katatna启动:
1.1 加入以下nuget包:
// 依赖众多
Microsoft.Owin.Security.OpenIdConnect
// 关键
Identitymodel
Microsoft.Owin.Security.Cookies
//iis用于owin startup 启动
Microsoft.Owin.Host.SystemWeb
Kentor.OwinCookieSaver
1.2 项目根目录下添加startup.cs。
如果Global.asax.cs项里有webapi配置,移动到startup.cs里的Configuration方法内:
[assembly: OwinStartup(typeof($yournamespace.Startup))]
namespace $yournamespace
{
public class Startup
{
/// <summary>
/// hack
/// </summary>
public static HttpConfiguration HttpConfiguration { get; private set; }
public void Configuration(IAppBuilder app)
{
}
}
}
1.3. 启动项目,确认katana正确启动。
- 在Startup.cs的Configuration方法加入openid设置:(见附件)
修改配置项
var ApplicationUrl = "http://localhost/SampleMvc4.x/";//你的应用的外服访问地址
var IdentityUrl = "http://localhost:5000/";//idsvr地址
var ClientId = "mvc5.owin";//你应用的clientid,找管理员注册
var ClientSecret = "secret";//你应用的clientSecret,找管理员注册
IdentityUrl配置项为oauthserver的endpoint地址,确保服务器能访问endpoint,否则应用无法启动。
- 在需要登录的action或controller上加入[Authorize]属性。

此时未带有authcookie的请求会被转向至openidserver 登录界面
- 获取当前用户信息:
Cnbauth在签出的token内自带用户信息。当授权用户访问时,controller作用域的User属性的Claims会被赋值。附帮助类:

在action内使用方式如下:

退出登录
public ActionResult Logout()
{
Request.GetOwinContext().Authentication.SignOut();
return Redirect("/");
}
.net 4.0+ 应用接入openid Server步骤的更多相关文章
- OpenID 配置步骤
允许客户端基于授权服务器执行的身份验证来验证最终用户的身份,以及以可互操作和类似REST的方式获取关于最终用户的基本配置文件信息. 创建一个MVC客户端 1.新建一个ASP.NET Core MVC应 ...
- 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)
从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...
- 从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)
从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...
- 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)
从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...
- 从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点)
从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...
- (转) 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)
原文地址: http://www.cnblogs.com/lyhabc/p/4682986.html 这一篇是从0开始搭建SQL Server AlwaysOn 的第三篇,这一篇才真正开始搭建Alwa ...
- (转)从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)
原文地址: http://www.cnblogs.com/lyhabc/p/4682028.html 这一篇是从0开始搭建SQL Server AlwaysOn 的第二篇,主要讲述如何搭建故障转移集 ...
- Rails 之微信开发 : OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
微信公众平台,使用Ruby On Rails + Win7 在取得OpenID时,如果简单的使用http.get方法,会出现如下 SSL_connect returned=1 errno=0 stat ...
- 安装Cloudera manager Server步骤详解
安装Cloudera manager Server步骤详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客主要是针对:https://www.cnblogs.com/yin ...
随机推荐
- docker网络之(三)
docker4种网络 基于docker run创建容器时,可以使用--net选项指定容器的网络模式:Docker默认有以下4种网络模式: host模式,使用--net=host指定 container ...
- 计算机体系结构:量化研究方法(中文第五版)_扫描版_23.5M.pdf
- aliyun-oss 通过redis来实现跨域上传图片到阿里 OSS并回显进度条
public class PutObjectProgressListener implements ProgressListener { private long bytesWritte ...
- 使用Python写yaml用例
1.打开cmd,进入本机安装python的目录,执行 pip install pyyaml ,安装pyyaml第三方包. 2.在Pycharm中新建一个项目(已有的话就不需要啦) 新建yaml文件 ...
- HikariCP连接池
1.HikariCP连接池是什么? HikariCP是数据库连接池,而且是号称史上最快的,而且目前来看确实是这样的,SpringBoot2.0也已经采用HikariCP作为默认连接池配置. githu ...
- QAxBase: Error calling IDispatch member LineStyle: Unknown error
word/Excel版本2007.2010. wps也适用. //borders->dynamicCall("SetLineStyle(int,int,int)", 0, ...
- tsar使用说明
常用命令 tsar --nginx --live -i 1 查询1秒的状态每秒采样一次 系统模块 cpu 字段含义 user: 表示CPU执行用户进程的时间,通常期望用户空间CPU越高越好. ...
- multer 文件后缀名
我的代码是这样写的. var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uplo ...
- C++:Copy & Reference Count
浅拷贝.深拷贝 通常,我们会按如下方式书写拷贝构造函数: class LiF { public: LiF(int _lif = 0) : lif(_lif) {} // 默认构造函数 LiF(cons ...
- 如何自动生成 Entity Framework 的 Mapping 文件?
Program.cs using System; using System.IO; using System.Text; using System.Text.RegularExpressions; n ...