.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 ...
随机推荐
- BASIC合集
握手包 给你握手包,flag是Flag_is_here这个AP的密码,自己看着办吧. 提交格式:flag{WIFI密码} 破解wifi密码 丢到kali,用aircrack-ng kali有一个包含常 ...
- LeetCode 62. Unique Paths不同路径 (C++/Java)
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- Forethought Future Cup - Elimination Round C 二分 + 交互(求树的直径)
https://codeforces.com/contest/1146/problem/C 题意 一颗大小为n的树,每次可以询问两个集合,返回两个集合中的点的最大距离,9次询问之内得出树的直径 题解 ...
- JavaScript查找两个数组的相同元素和相差元素
let intersection = a.filter(v => b.includes(v)) 返回交集数组 let difference = a.concat(b).filter(v => ...
- 使用nexus搭建maven仓库(maven 本地私服)
我们在使用maven的时候,对于项目所依赖的jar包,maven默认会在中央仓库下载jar包,到本地的磁盘目录(如果没有配置则是用户目录下/.m2/repository文件夹下).如果公司内部搭了一个 ...
- mysql8
解决navicat不能连接问题: grant all privileges on *.* to ‘root’@’%’;ALTER USER 'root'@'localhost' IDENTIFIED ...
- 应用层内存溢出/越界/重复释放等问题检查工具(ASan)
https://github.com/google/sanitizers/wiki https://github.com/google/sanitizers/wiki/AddressSanitizer ...
- TiDB 压力测试报告
(转载自公众号DBATech) 一.测试环境 1.tidb 集群架构: 测试使用最基本的TiDB架构.即 3个tidb-server节点+ 3个tikv节点 + 3个pd节点. 2.tidb集群的部署 ...
- 通过Filebeat把日志传入到Elasticsearch
学习的地方:配置文件中预先处理字段数据的用法 通过Filebeat把日志传入到Elasticsearch Elastic Stack被称之为ELK (Elasticsearch,Logstash an ...
- [CrackMe]160个CrackMe之002
吾爱破解专题汇总:[反汇编练习]160个CrackME索引目录1~160建议收藏备用 一.逆向分析之暴力破解 暴力破解,对于这种具有提示框的,很好定位. 定位好之后,爆破其跳转语句,就能达到破解目的. ...