1.asp.net core 是基於管道模式IdentityServer會在注冊一個管道處理程序
IdentityServerMiddleware 類專門處理登錄驗證的邏輯,本次主要講的是access_token 的獲取
2.首先我們看下token獲取的處理流程

在上圖中我們看到這個在IdentityServerMiddleware 中invoke 根據請求類型找到EndPoint 處理節點,Token類型的請求就是找TokenEndPpint節點,然后根據EndPoint執行拿到EndPointResult 處理結果最后執行輸出結果。這個是統一的執行流程不管是什么驗證類型。
3.Token令牌的獲取主要邏輯在TokenEndPoint 類的ProcessTokenRequestAsync 方法中
1).驗證客戶信息是哪一類的ClientSecretValidator 驗證客戶類型,驗證客戶是否存在,並通過SecretValidator驗證客戶是否合法
2).TokenRequestValidator 驗證token請求是否合法
3).TokenResponseGearanter 通過客戶信息生成token並生成返回對象TokenResponseResult並最終得到Token