上一篇将请求流程描述一遍,这篇将描述一下相关的源码。

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-请求流程叙述-下篇的更多相关文章

  1. indetityserver4-implicit-grant-types-请求流程叙述-上篇

    说明:使用项目代码是这个,做了一点体力活:将 implicit grant types(简化授权类型)的页面跳转流程抓了个包. QuickstartIdentityServer 项目的发布地址:127 ...

  2. OAuth2.0学习(1-5)授权方式2-简化模式(implicit grant type)

    授权方式2-简化模式(implicit grant type) 简化模式(implicit grant type)不通过第三方应用程序的服务器,直接在浏览器中向认证服务器申请令牌,跳过了"授 ...

  3. OAuth2.0和企业内部统一登录,token验证方式,OAuth2.0的 Authorization code grant 和 Implicit grant区别

    统一登录是个很多应用系统都要考虑的问题,多个项目的话最好前期进行统一设计,否则后面改造兼容很麻烦: cas认证的方式:新公司都是老项目,用的是cas认证的方式,比较重而且依赖较多,winform的项目 ...

  4. 配置Postman通过OAuth 2 implicit grant获取Dynamics 365 CE Online实例的Access Token

    微软动态CRM专家罗勇 ,回复335或者20190516可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me. 对于测试Web API, Get 类型,不需要设定特别reque ...

  5. zookeeper源码分析之五服务端(集群leader)处理请求流程

    leader的实现类为LeaderZooKeeperServer,它间接继承自标准ZookeeperServer.它规定了请求到达leader时需要经历的路径: PrepRequestProcesso ...

  6. ASP.NET MVC学前篇之请求流程

    ASP.NET MVC学前篇之请求流程 请求流程描述 对于请求的流程,文章的重点是讲HttpApplication和HttpModule之间的关系,以及一个简单的示例实现.(HttpModule又是M ...

  7. MVC视图请求流程视图

    /*         *视图请求流程         *当接受到home/index请求时         *先去找viewstart.cshtml视图,再去加载index.cshtml视图      ...

  8. HTTP请求流程(一)----流程简介

    最近一直在研究如何让asp.net实现上传大文件的功能,所以都没怎么写技术类的文章了.可惜的是至今还没研究出来,惭愧~~~.不过因为这样,也了解了一下http消息请求的大致过程.我就先简单介绍下,然后 ...

  9. [转】:HTTP请求流程(一)----流程简介

    http://www.cnblogs.com/stg609/archive/2008/07/06/1236966.html HTTP请求流程(一)----流程简介 最近一直在研究如何让asp.net实 ...

随机推荐

  1. CentOS 7 网络优化(升级内核、开启 BBR)

    我之前介绍过关于 TCP 一些优化,包括安装使用 TCP 优化软件,这些适用于较低版本的 CentOS 系统,例如 CentOS 6,详细可参考<Linux 下的一些简单的 TCP 优化> ...

  2. andorid jar/库源码解析之Butterknife

    目录:andorid jar/库源码解析 Butterknife: 作用: 用于初始化界面控件,控件方法,通过注释进行绑定控件和控件方法 栗子: public class MainActivity e ...

  3. Phoenix and Distribution(字典序贪心)

    \(给定一串字母,分成k份,使得最大字典序最小.(字母可以任意组合)\) \(------------------------------issue~------------------------\ ...

  4. 聚合类型与POD类型

    Lippman在<深度探索C++对象模型>的前言中写道: I have heard a number of people over the years voice opinions sim ...

  5. mysql优化–explain分析sql语句执行效率

    Explain命令在解决数据库性能上是第一推荐使用命令,大部分的性能问题可以通过此命令来简单的解决,Explain可以用来查看SQL语句的执行效 果,可以帮助选择更好的索引和优化查询语句,写出更好的优 ...

  6. 数组的操作。1,JS数组去重。2,把数组中存在的某个值,全部找出来。3在JS数组指定位置插入元素。。。

    1,数组去重 let arr = [1,2,3,4,5,6,1,2,3,'a','b','a']; let temp = []; // 作为存储新数组使用 for(let i = 0; i < ...

  7. Js调用Android回调处理

    通常在混合app中经常会使用js调用native的方法,一般是: window.nativeApp.call(XXX); 直接调用native方法,对于简单的处理倒是可以,如果需要回调呢?期待的方式是 ...

  8. Git与GitHub常用操作

    --------------------------基本操作--------------------------clone 拷贝远程仓库commit 本地提交push 远程提交pull 更新本地--- ...

  9. 2018-06-25 js表单事件、三个高度和Ajax异步通讯技术

    表单事件: onfocus -> 表单控件得到焦点时触发: obj_ipt.onfocus=function(){}; onblur -> 表单控件失去焦点时: onchange -> ...

  10. IP协议及其它的小弟 ,我保证没人会看的

    IP协议及其它的小弟 IP协议:127.0.0.1就一个32位的标识符.实际上: 类似这样的: 精神小伙慢慢看吧.我赌一包辣条你是不会认真看完的. IP协议的构成 地址解析协议 ARP 前面的叙述中我 ...