05-IdentityServer4
前面我们认识了jwt的token颁发模式,其中的应用场景和部分缺陷已经很是了解了。有些场合并不适合jwt,特别是针对第三方进行使用时,比如我们使用qq或者微信登陆博客园或其他第三方应用时。
Ids4的token颁发可以简单的概述为4中场景,客户端模式,密码模式,简化模式,授权码模式。还有一个混合模式。这些都是针对Ids4颁发的模式进行区分的,至于接口验证环节,是一样的。
1)控制器或者Action增加特性标签,
2)增加中间件app.UseAuthentication();//注意添加这一句,启用验证,解析信息--就是读取token,解密token
3)在ConfigureServices增加AddAuthentication方法,设置授权模式,可以采用Ids4,也可以是jwt或者是cookie等
4)可以扩展自定义的policy模式进行权限验证。
这里我们重点描述Ids4的4中常用认证模式,也就是说4种token颁发模式。
token颁发模式的实现
1)添加UseIdentityServer()中间件
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
#region 添加IdentityServer中间件
app.UseIdentityServer();//拦截部分请求
#endregion
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
2)在services中添加AddIdentityServer()
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
#region 客户端
services.AddIdentityServer()//怎么处理
.AddDeveloperSigningCredential()//默认的开发者证书--临时证书--生产环境为了保证token不失效,证书是不变的
.AddInMemoryClients(ClientInitConfig.GetClients())//InMemory 内存模式
.AddInMemoryApiResources(ClientInitConfig.GetApiResources());//能访问啥资源
#endregion
#region 密码模式
//services.AddIdentityServer()
// .AddDeveloperSigningCredential()//默认的开发者证书
// .AddInMemoryApiResources(PasswordInitConfig.GetApiResources())//API访问授权资源
// .AddInMemoryClients(PasswordInitConfig.GetClients()) //客户端
// .AddTestUsers(PasswordInitConfig.GetUsers());//添加用户
#endregion
#region 简化模式
//services.AddIdentityServer()
// .AddDeveloperSigningCredential()//默认的开发者证书
// .AddInMemoryApiResources(ImplicitInitConfig.GetApiResources()) //API访问授权资源
// .AddInMemoryClients(ImplicitInitConfig.GetClients())//客户端
// .AddTestUsers(ImplicitInitConfig.GetUsers()); //添加用户
#endregion
#region Code模式
//services.AddIdentityServer()
// .AddDeveloperSigningCredential()//默认的开发者证书
// .AddInMemoryApiResources(CodeInitConfig.GetApiResources()) //API访问授权资源
// .AddInMemoryClients(CodeInitConfig.GetClients())//客户端
// .AddTestUsers(CodeInitConfig.GetUsers()); //添加用户
#endregion
#region Hybrid模式
//services.AddIdentityServer()
// .AddDeveloperSigningCredential()//默认的开发者证书
// .AddInMemoryIdentityResources(HybridInitConfig.GetIdentityResources())//身份信息授权资源
// .AddInMemoryApiResources(HybridInitConfig.GetApiResources()) //API访问授权资源
// .AddInMemoryClients(HybridInitConfig.GetClients())//客户端
// .AddTestUsers(HybridInitConfig.GetUsers()); //添加用户
#endregion
}
关于Ids4的4种模式,我们在之前的博客中已经进行了详细的描述,
根据我的项目经验,我们使用最多的是客户端模式和密码模式,很少使用另外的模式,另外的模式只是作为客户端来访问其他第三方的授权中心(比如qq,微信等),我们自己的授权中心作为其他的第三方登录情况极少。
05-IdentityServer4的更多相关文章
- 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...
- Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)
写在前面 本文地址:http://www.cnblogs.com/yilezhu/p/9315644.html 作者:yilezhu 上一篇关于Asp.Net Core Web Api图片上传的文章使 ...
- IdentityServer4服务器配置
Session认证和JWT(Json Web Token) Token认证就是基于JWT 1.Session认证 1. 用户输入其登录信息 2. 服务器验证信息是否正确,并创建一个session,然后 ...
- 08.IdentityServer4登录中心
08.IdentityServer4登录中心 IdentityServer就是一套Framework,实现了OAuth的授权 理解OAuth流程,学会怎么使用他 http://ruanyifeng.c ...
- Core篇——初探IdentityServer4(客户端模式,密码模式)
Core篇——初探IdentityServer4(客户端模式,密码模式) 目录 1.Oatuth2协议的客户端模式介绍2.IdentityServer4客户端模式实现3.Oatuth2协议的密码模式介 ...
- 从Client应用场景介绍IdentityServer4(三)
原文:从Client应用场景介绍IdentityServer4(三) 在学习其他应用场景前,需要了解几个客户端的授权模式.首先了解下本节使用的几个名词 Resource Owner:资源拥有者,文中称 ...
- asp.net core IdentityServer4 实现 implicit(隐式许可)实现第三方登录
前言 OAuth 2.0默认四种授权模式(GrantType) 授权码模式(authorization_code) 简化模式(implicit) 密码模式(resource owner passwor ...
- IdentityServer4 手动验签及日志记录
IdentityServer4的基础知识和使用方式网上有很多特别优秀的文章,如果有对其不了解的推荐阅读一下下面的两篇文章 http://www.ruanyifeng.com/blog/2014/05/ ...
- 【总】IdentityServer4 32篇汇总
随笔分类 - IdentityServer4 IdentityServer4 常见问题 - 用户拒绝授权后报错 摘要: 1.问题说明 在 IdentityServer4 Web 授权中,一般会有一个显 ...
- Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(四)
在上一讲中,我们已经完成了一个完整的案例,在这个案例中,我们可以通过Angular单页面应用(SPA)进行登录,然后通过后端的Ocelot API网关整合IdentityServer4完成身份认证.在 ...
随机推荐
- C# KeyValuePair<TKey,TValue> 与 Dictionary<TKey,TValue> 区别
KeyValuePair<TKey,TValue> 可以设置.查询的一对键值 是struct Dictionary<TKey,TValue> 可以设置.查询的多对键值的集合 总 ...
- Python也可以拥有延迟函数
延迟函数defer 我们知道在Golang中有一个关键字defer,用它来声明在函数调用前,会让函数*延迟**到外部函数退出时再执行,注意,这里的退出含义:函数return返回或者函数panic退出 ...
- Git配置多账户
一般情况下,公司代码company_repos/会存放在公司内部的gitlab上,个人代码privacy_repos/会放在github上.因此我们会有两个git账户:公司账号zioyi@campan ...
- rabbitMq可靠性投递之配置(消息至交换机,至队列不通的回调)
@Bean public RabbitTemplate rabbitTemplate(CachingConnectionFactory factory) { //若使用confirm-callback ...
- centos6.10下安装mysql8.0.16root密码修改的坑
上图截取别人的自己懒得弄,检查自己的linux是否有安装就按上图做就行了 接下来是我的干货 mysql8.0安群策略对密码设置很严格规则:大小写加数字和特殊字符串 使用yum安装mysql 后 my. ...
- pixhawk入门
PX4 是软件名称,代码约30万行 Pixhawk是硬件名称 MissionPlanner是地面站名称 常见术语: WP:Way Point 航电 geofence:地理围栏 Rally Point: ...
- python 文件批量改名重命名 rename
path = '/Volumes/Seagate/dev/imgs/' os.chdir(path) print('cwd: ', os.getcwd()) for f in os.listdir(' ...
- Spring Security进阶
Spring Security进阶 1.连接数据库进行数据的验证 Spring Security进行身份验证或者权限控制时,用户名和密码应该要和数据库的进行比较才行,用户的各种信息我们从数据库中去获取 ...
- RabbitMQ详解(一)——
RabbitMQ详解(一)-- https://www.cnblogs.com/liuwenwu9527/p/11989216.html https://www.cnblogs.com/ideal-2 ...
- Codeforces 1365D Solve The Maze
### 题目大意: 在一个 $n * m$ 的矩阵中,有空地.坏人.好人和墙.你可以将空地变成墙来堵住坏人.$(n, m)$为出口,是否存在一个方案使得矩阵中所有好人能够走到出口,而所有坏人不能通过出 ...