indetityserver4-implicit-grant-types-请求流程叙述-下篇
上一篇将请求流程描述一遍,这篇将描述一下相关的源码。
1 访问客户端受保护的资源
GET /Home/Secure HTTP/1.1HTTP/1.1 302 Found
Date: Tue, 23 Oct 2018 09:02:40 GMT
Location: http://127.0.0.1:5000/connect/authorize?client_id=mvc&redirect_uri=http://127.0.0.1:5002/signin-oidc&response_type=id_token&scope=openid profile&response_mode=form_post&nonce=636758。。。&state=CfD。。。ZLI0fuVlCMPs&x-client-SKU=ID_NET&x-client-ver=2.1.4.0
Secure action 代码如下:
[Authorize]
public IActionResult Secure()
{
ViewData["Message"] = "Secure page."; return View();
}
1.1 authorizationPolicy
不同点在用 Authorize 修饰了 action,中间有些曲折,最终其相当于在 ActionContext 的属性 FilterDescriptors 添加了一个 AuthorizerFilte,这个过滤器的 Policy 是 DenyAnonymousAuthorizationRequirement,就是拒绝匿名用户访问,同 [Authorize] 定义相符。

MVC 过滤器的解释及相关可以参考官方文档,个人认为主要是实践 AOP 想法。
1.2 Challenged
过滤器被执行的结果是

项目的地址在这里。dotnet core 授权和认证的原理主要是5个扩展方法,相关的代码是在 HttpAbstractions 这个项目中。
1.3 生成 redirect

MvcClient 中配置 oidc 的 options 会赋给 OpenIDConnectMessage 对象,并最终拼接中 RedirectUrl:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(); JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies"; options.Authority = "http://127.0.0.1:5000";
options.RequireHttpsMetadata = false; options.ClientId = "mvc";
options.SaveTokens = true;
});
}
1.4 OpenIDConnectOptions

这个地方就可以看到 oidc 许多默认设置,比如当 Scope 没有设置时,默认会请求“openid”和“profile”
2 重定向到:请求identity Service 授权
GET /connect/authorize?client_id=mvc&redirect_uri=http%3A%2F%2F127.0.0.1%3A5002%2Fsignin-oidc&response_type=id_tok
HTTP/1.1 302 Found
Location: http://127.0.0.1:5000/account/login?returnUrl=%2Fconnect%2Fauthorize%2Fca。。。%26x-client-ver%3D2.1.4.0
2.1 IdentityServerMiddleware
项目地址在这里
在 IdentityServer 的 Starup中
app.UseIdentityServer();
主要是将 IdentityServerMiddleware 中间件提交 app 管道中,

2.2 endpoint
个人认为 identityServer 的实现时各种 endpoint,并将 endpoint 与路径挂钩,
public static class ProtocolRoutePaths
{
public const string Authorize = "connect/authorize";
public const string AuthorizeCallback = Authorize + "/callback";
public const string DiscoveryConfiguration = ".well-known/openid-configuration";
public const string DiscoveryWebKeys = DiscoveryConfiguration + "/jwks";
public const string Token = "connect/token";
public const string Revocation = "connect/revocation";
public const string UserInfo = "connect/userinfo";
public const string Introspection = "connect/introspect";
public const string EndSession = "connect/endsession";
public const string EndSessionCallback = EndSession + "/callback";
public const string CheckSession = "connect/checksession"; public static readonly string[] CorsPaths =
{
DiscoveryConfiguration,
DiscoveryWebKeys,
Token,
UserInfo,
Revocation
};
比如请求的地址为:/connect/authorize?,它获得的就是 AuthorizeEndpoint

2.3 LoginPageResult
var result = endpoint.ProcessAsync(context);
endpoint 处理后就是 result 对象,

同 endpoint 类似, IdentityServer 实现了各种 result

而 LoginPageResult 这是讲请求 redirect 到 /account/login?,这与抓包的流程3描述一致。
而后续在 IdentityServer 中跳转流程可通过了类似方式查看源代码,就不再一一描述。
-------感觉写代码现在变成了体力活,无任何技术可言。
indetityserver4-implicit-grant-types-请求流程叙述-下篇的更多相关文章
- indetityserver4-implicit-grant-types-请求流程叙述-上篇
说明:使用项目代码是这个,做了一点体力活:将 implicit grant types(简化授权类型)的页面跳转流程抓了个包. QuickstartIdentityServer 项目的发布地址:127 ...
- OAuth2.0学习(1-5)授权方式2-简化模式(implicit grant type)
授权方式2-简化模式(implicit grant type) 简化模式(implicit grant type)不通过第三方应用程序的服务器,直接在浏览器中向认证服务器申请令牌,跳过了"授 ...
- OAuth2.0和企业内部统一登录,token验证方式,OAuth2.0的 Authorization code grant 和 Implicit grant区别
统一登录是个很多应用系统都要考虑的问题,多个项目的话最好前期进行统一设计,否则后面改造兼容很麻烦: cas认证的方式:新公司都是老项目,用的是cas认证的方式,比较重而且依赖较多,winform的项目 ...
- 配置Postman通过OAuth 2 implicit grant获取Dynamics 365 CE Online实例的Access Token
微软动态CRM专家罗勇 ,回复335或者20190516可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me. 对于测试Web API, Get 类型,不需要设定特别reque ...
- zookeeper源码分析之五服务端(集群leader)处理请求流程
leader的实现类为LeaderZooKeeperServer,它间接继承自标准ZookeeperServer.它规定了请求到达leader时需要经历的路径: PrepRequestProcesso ...
- ASP.NET MVC学前篇之请求流程
ASP.NET MVC学前篇之请求流程 请求流程描述 对于请求的流程,文章的重点是讲HttpApplication和HttpModule之间的关系,以及一个简单的示例实现.(HttpModule又是M ...
- MVC视图请求流程视图
/* *视图请求流程 *当接受到home/index请求时 *先去找viewstart.cshtml视图,再去加载index.cshtml视图 ...
- HTTP请求流程(一)----流程简介
最近一直在研究如何让asp.net实现上传大文件的功能,所以都没怎么写技术类的文章了.可惜的是至今还没研究出来,惭愧~~~.不过因为这样,也了解了一下http消息请求的大致过程.我就先简单介绍下,然后 ...
- [转】:HTTP请求流程(一)----流程简介
http://www.cnblogs.com/stg609/archive/2008/07/06/1236966.html HTTP请求流程(一)----流程简介 最近一直在研究如何让asp.net实 ...
随机推荐
- 数学--数论--POJ1365——Prime Land
Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...
- 06 __init__ 和 __new__的关系和不同
一. 双下new 和 双下init 关系 首先从__new__(cls,a,b,c)的参数说说起,__new__方法的第一个参数是这个类,而其余的参数会在调用成功后全部传递给__init__方法初始化 ...
- http抓包—Content-Type讲解
1.Content-Type的定义 Content-Type(MediaType),即是Internet Media Type,互联网媒体类型,也叫做MIME类型.在互联网中有成百上千中不同的数据类型 ...
- Automatic Reference Counting
NSObject简化版alloc: struct obj_layout { NSUInteger retained; }; + (id)alloc { int size = sizeof(struct ...
- 创造DotNet Core轻量级框架【一】
前言 net core 已经出了很久了,网上的各种框架也很多了,但是没看到一个很小很轻的框架,基本都是那种啥功能都有,但是我需要的功能只占他们框架的百分之几,很少很少,所以自己创造一个框架. 因为之前 ...
- HTML往div中赋值
HTML中往div赋值 <div id="mazey">content</div> 使用JavaScript: var mazey=document.get ...
- Spring Cloud学习 之 Spring Cloud Ribbon(执行流程源码分析)
Spring Boot版本:2.1.4.RELEASE Spring Cloud版本:Greenwich.SR1 文章目录 分析: 总结: 分析: 在上篇文章中,我们着重分析了RestTempla ...
- 【不断更新】mysql经典50道题自我练习
mysql经典50道题自我练习 测试数据和练习题均转载自CSDN博主@启明星的指引的文章sql语句练习50题(Mysql版),用于mysql的每日自我练习 表名和字段 –1.学生表 Student(s ...
- Day_09【常用API】扩展案例7_验证QQ号是否正确
需求说明 请用户输入一个"QQ号码",我们来判断这个QQ号码是否正确 要求:使用方法来完成判断功能 验证规则: 1)必须是5-12位数字: 2)首位不能是0: package co ...
- Linux内核驱动学习(八)GPIO驱动模拟输出PWM
文章目录 前言 原理图 IO模拟输出PWM 设备树 驱动端 调试信息 实验结果 附录 前言 上一篇的学习中介绍了如何在用户空间直接操作GPIO,并写了一个脚本可以产生PWM.本篇的学习会将写一个驱动操 ...