前面我们认识了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. 2018秋招C/C++面试题总结

    一.C和C++的区别是什么? C是面向过程的语言,C++是在C语言的基础上开发的一种面向对象编程语言,应用广泛.C中函数不能进行重载,C++函数可以重载C++在C的基础上增添类,C是一个结构化语言,它 ...

  2. uwp 之吐司 toast

    Toast -------------------------------------------------------------- var t = Windows.UI.Notification ...

  3. AOP的底层实现-CGLIB动态代理和JDK动态代理

    AOP是目前Spring框架中的核心之一,在应用中具有非常重要的作用,也是Spring其他组件的基础.它是一种面向切面编程的思想.关于AOP的基础知识,相信多数童鞋都已经了如指掌,我们就略过这部分,来 ...

  4. Spring第一课:核心API(三)

    以上是Spring的核心部分,其中需要了解的是:BeanFactory.ApplicationContext[FileSystemXmlApplicationContext.ClassPathXmlA ...

  5. jQuery中的基本选择器(四、一):* 、 . 、element(直接标签名)、 或者用逗号隔开跟多个

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 由struts2中配置使用servlet引发的思考和复习

    Struts2拦截器到底拦截了什么? 关于struts2中的拦截器,首先再次理解其实只能过滤其中访问的action的映射!再者,因为struts中的action其实就是起到替代servlet作用的,所 ...

  7. Alibaba cloud 3 安装docker

    最近因为公司买阿里服务器装的 Alibaba cloud Linux 系统,在部署环境的时候也是遇到各种坑,网上教程大多都是其他系统的,今天就来分享一下自己安装Docker的步骤,同时也是给自己记录一 ...

  8. 跨域@RequestBody@RequestParam 和JSON.stringify

  9. ubuntu开机自启设置 Ubuntu16.04下测试OK

    在~/.config/autostart/目录下,添加xxx.desktop文件,内容如下: [Desktop Entry] Type=Application Name=start apps NoDi ...

  10. python常用工具库介绍

    Numpy:科学计算 HOME:  http://www.numpy.org/ NumPy is the fundamental package for scientific computing wi ...