前面我们认识了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的更多相关文章

  1. 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...

  2. Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)

    写在前面 本文地址:http://www.cnblogs.com/yilezhu/p/9315644.html 作者:yilezhu 上一篇关于Asp.Net Core Web Api图片上传的文章使 ...

  3. IdentityServer4服务器配置

    Session认证和JWT(Json Web Token) Token认证就是基于JWT 1.Session认证 1. 用户输入其登录信息 2. 服务器验证信息是否正确,并创建一个session,然后 ...

  4. 08.IdentityServer4登录中心

    08.IdentityServer4登录中心 IdentityServer就是一套Framework,实现了OAuth的授权 理解OAuth流程,学会怎么使用他 http://ruanyifeng.c ...

  5. Core篇——初探IdentityServer4(客户端模式,密码模式)

    Core篇——初探IdentityServer4(客户端模式,密码模式) 目录 1.Oatuth2协议的客户端模式介绍2.IdentityServer4客户端模式实现3.Oatuth2协议的密码模式介 ...

  6. 从Client应用场景介绍IdentityServer4(三)

    原文:从Client应用场景介绍IdentityServer4(三) 在学习其他应用场景前,需要了解几个客户端的授权模式.首先了解下本节使用的几个名词 Resource Owner:资源拥有者,文中称 ...

  7. asp.net core IdentityServer4 实现 implicit(隐式许可)实现第三方登录

    前言 OAuth 2.0默认四种授权模式(GrantType) 授权码模式(authorization_code) 简化模式(implicit) 密码模式(resource owner passwor ...

  8. IdentityServer4 手动验签及日志记录

    IdentityServer4的基础知识和使用方式网上有很多特别优秀的文章,如果有对其不了解的推荐阅读一下下面的两篇文章 http://www.ruanyifeng.com/blog/2014/05/ ...

  9. 【总】IdentityServer4 32篇汇总

    随笔分类 - IdentityServer4 IdentityServer4 常见问题 - 用户拒绝授权后报错 摘要: 1.问题说明 在 IdentityServer4 Web 授权中,一般会有一个显 ...

  10. Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(四)

    在上一讲中,我们已经完成了一个完整的案例,在这个案例中,我们可以通过Angular单页面应用(SPA)进行登录,然后通过后端的Ocelot API网关整合IdentityServer4完成身份认证.在 ...

随机推荐

  1. docker 镜像配置

    Ubuntu14.04.Debian7Wheezy 对于使用 upstart 的系统而言,编辑 /etc/default/docker 文件,在其中的 DOCKER_OPTS 中配置加速器地址: DO ...

  2. 【spring 注解驱动开发】spring对象的生命周期

    尚学堂spring 注解驱动开发学习笔记之 - 生命周期 生命周期 1.生命周期-@Bean指定初始化和销毁方法 2.生命周期-InitializingBean和DisposableBean 3.生命 ...

  3. ArcGIS:从DEM数据提取对应点的高程

    通过Extract Value to Points从DEM数据中提取所需点的高程. 方法/步骤 将DEM数据文件和一个shapefile点文件(分别命名为"DEM"和"P ...

  4. Scrapy启动spider出错

    python 3.7 里,async变成了关键字,所以报错. 解决方法:1回退python3.6版本. 2找到报错的那个py文件,比如manhole.py,将函数参数async改个名字(比如改成asy ...

  5. linux修改源镜像地址

    1.1 CentOS修改yum源镜像地址为:mirrors.163.com (也可以改为阿里云镜像) 1.首先备份系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.re ...

  6. indexedDB数据库完整创建流程

    1.打开数据库 使用 IndexedDB 的第一步是打开数据库,使用indexedDB.open()方法 var request = window.indexedDB.open(databaseNam ...

  7. mysql switch语句

    SELECT CASE the_order_status WHEN 4 THEN '待收货' WHEN 5 THEN '已收货' ELSE '其他' END AS statuss ,order_id ...

  8. Asp.NetCore ResposeCache 缓存的使用

    先小结一下: 缓存策略: [ResponseCache(CacheProfileName ="default30")] 直接使用缓存,30秒过期: [ResponseCache(D ...

  9. JavaWeb_MVC 设计模式

    Servlet缺点:(1)用servlet进行显示(out)会很麻烦,因为servlet是一个类,托福ibt并不擅长做显示:(2)servlet直接访问数据表的话,servlet内的访问和操作数据表的 ...

  10. 板子题 Sol

    RT Cyber_Tree 出了一道板子题... 这题乍看之下貌似还不戳,但如果您做过类似的题,那么这就是一道板子题.... 首先明确要求的是什么,如果我们只考虑权值最大而不考虑最小距离,那么要求的显 ...