前面我们认识了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. C++进阶—>带你理解多字节编码与Unicode码

    参考网址:https://blog.csdn.net/u011028345/article/details/78516320 多字节字符与宽字节字符 char与wchar_t 我们知道C++基本数据类 ...

  2. CPU 进程 线程 关系与区别

  3. 【springcloud】springcloud与springboot的版本对应关系

    官方网址:https://start.spring.io/actuator/info 更新时间:2019-12-01 spring-cloud: "Finchley.M2": &q ...

  4. C++继承体系中的内存对齐

    本篇随笔讨论一个比较冷门的知识,继承结构中内存对齐的问题,如今内存越来越大也越来越便宜,大部分人都已经不再关注内存对齐的问题了.但是作为一个有追求的技术人员,实现功能永远都是最基本的要求,把代码优化到 ...

  5. 嵌入式Linux的启动过程

    1.了解 Linux 最初是由瑞典赫尔辛基大学的学生 Linus Torvalds在1991 年开发出来的,之后在 GNU的支持下,Linux 获得了巨大的发展.虽然 Linux 在桌面 PC 机上的 ...

  6. 深入Pulsar Consumer的使用方式&源码分析

    原文链接 1.使用前准备 引入依赖: <dependency> <groupId>org.apache.pulsar</groupId> <artifactI ...

  7. Golang gomail 发送邮件 --初使用

    gomail是一个第三方库,可以发送邮件 安装:go get -u github.com/go-gomail/gomail 使用示例: m := gomail.NewMessage() m.SetHe ...

  8. android kotlin determine file type from bytes 根据文件内容识别文件类型,类似python的filetype

    尝试了 URLConnection.guessContentTypeFromStream(ByteArrayInputStream(bytes)) 和 Tika().detect(bytes) 一个识 ...

  9. AWS扩容EC2实例根空间

    文章原文 aws 端操作 先在EC2 实例中选中磁盘 然后打开跟设备 修改大小后保存 ec2 端操作 lsblk 查看当前设备的磁盘编号 df -T -H 查看扩容前的空间大小并确定磁盘格式 grow ...

  10. Redis详解(二)——

    https://www.cnblogs.com/yeya/p/14274948.html https://www.cnblogs.com/liang24/tag/redis/