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完成身份认证.在 ...
 
随机推荐
- spring cloud 知识总结
			
### 单体应用存在的问题 - 随着业务的发展,开发变得越来越复杂.- 修改.新增某个功能,需要对整个系统进行测试.重新部署.- 一个模块出现问题,很可能导致整个系统崩溃.- 多个开发团队同时对数据进 ...
 - WPF日积月累之DataGrid样式以及操作数据模板中的控件
			
一.效果图 二.代码预览 1 <Window x:Class="Test.MainWindow" 2 xmlns="http://schemas.microsoft ...
 - 【转】SpringCloud学习
			
Spring Cloud Alibaba与Spring Boot.Spring Cloud之间不得不说的版本关系 这篇博文是临时增加出来的内容,主要是由于最近连载<Spring Cloud ...
 - Mybatis简单应用
			
Mybatis的核心组件: SqlSeeeionFactoryBuilder (构建器):它会根据配置或者代码来生成SqlSessionFactory,采用的是分布构建的Builder模式: SqlS ...
 - JS方式实现隐藏手机号码中间4位数
			
1.截取 function test (value) { const start = value.slice(0, 3) const end = value.slice(-4) return `${s ...
 - tcmalloc jemalloc glibc内存分配管理模块性能测试对比
			
tcmalloc是谷歌提供的内存分配管理模块 jemalloc是FreeBSD提供的内存分配管理模块 glibc是Linux提供的内存分配管理模块 并发16个线程,分配压测3次,每次压15分钟,可以看 ...
 - Javascirpt 面向对象总结-继承
			
JS继承的实现方式 既然要实现继承,那么首先我们得有一个父类,代码如下: // 定义一个动物类 function Animal (name) { // 公有属性 this.name = name || ...
 - C# ThreadPool 分批处理数据,所有数据执行完再返回
			
这是一个调用翻译数据的功能,所有数据一次性提交会造成后台服务压力大,接口反应时间也长. 所以做了一个分批处理,等待所有批次的数据调用接口都返回后再执行下一步. 1 /// <summary> ...
 - 基于Linux系统Samba服务器的部署
			
1.基础信息 用 Internet 文件系统 CIFS(Common Internet File System)是适用于MicrosoftWindows 服务器和客户端的标准文件和打印机共享系统信息块 ...
 - python 逆序按行读取文件
			
How to read a file in reverse order? import os def readlines_reverse(filename): with open(filename) ...