成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Spring Cloud :: Security :: OAuth2 - ? OAuth2模型詳述

TIGERB / 983人閱讀

本系列文章

Spring Cloud :: Security :: Oauth2 - ? OAuth2模型詳述
Spring Cloud :: Security :: Oauth2 - ① 待定
...

寫在前面

文中很多專有名詞在初次使用時(shí)我會(huì)標(biāo)注一下中文,但是在后面使用過程中我還是會(huì)使用英文來表示,因?yàn)樗械臉?biāo)準(zhǔn)的出處都是英文,中文的翻譯并沒有標(biāo)準(zhǔn),用英文會(huì)減少歧義通俗易懂。

_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/

背景

最近在做基于Spring Cloud的一系列架構(gòu),在認(rèn)證、權(quán)限這一塊準(zhǔn)備采用OAuth2來做,Spring Cloud本身對(duì)于OAuth2的支持很不錯(cuò),這一塊叫做Spring Cloud Security,默認(rèn)就是使用OAuth2的模型來支持。本文把自己做架構(gòu)過程中積累的技術(shù)以及插圖分享出來。

概述 介紹OAuth2模型

本文主要描述OAuth2的模型以及基本運(yùn)行原理,內(nèi)容略略抽象,盡最大限度用圖來描述,結(jié)合后續(xù)的基于Spring Cloud的代碼和架構(gòu)圖理解會(huì)更為便捷。

正文 OAuth2

我們經(jīng)常所說的OAuth2,顧名思義,就是OAuth模型的第二版。此版本允許第三方應(yīng)用獲取資源訪問權(quán)限,并且在很多大型互聯(lián)網(wǎng)企業(yè)中進(jìn)行使用。

基礎(chǔ)知識(shí) Roles 角色 OAuth2定義的4個(gè)角色

Resource Owner :資源擁有者,電腦前的你。

Resource Server :資源服務(wù)器,托管受保護(hù)的數(shù)據(jù)的服務(wù)器。

Client :客戶端,請(qǐng)求訪問資源服務(wù)器的應(yīng)用??梢允蔷W(wǎng)站,可以是javascript腳本,也可以是任何app等。

Authorization Server :授權(quán)服務(wù)器,向Client(客戶端)發(fā)放token(令牌)的服務(wù)器,token用于Client請(qǐng)求Resource Server。

佛系圖解釋一下(來源于RFC6749)https://tools.ietf.org/html/r...
  +--------+                                           +---------------+
  |        |--(A)------- Authorization Grant --------->|               |
  |        |                                           |               |
  |        |<-(B)----------- Access Token -------------|               |
  |        |                                           |               |
  |        |                                           |               |
  |        |                            +----------+   |               |
  |        |--(C)---- Access Token ---->|          |   |               |
  |        |                            |          |   |               |
  |        |<-(D)- Protected Resource --| Resource |   | Authorization |
  | Client |                            |  Server  |   |     Server    |
  |        |                            |          |   |               |
  |        |                            |          |   |               |
  |        |                            |          |   |               |
  |        |                            +----------+   |               |
  |        |                                           |               |
  |        |                                           |               |
  |        |                                           |               |
  |        |                                           |               |
  +--------+                                           +---------------+
 

(A):授權(quán)

(B):獲得token

(C):使用token訪問Resource Server

(D):獲得受保護(hù)的數(shù)據(jù)

這張圖中沒有Resource Owner出現(xiàn),我們姑且認(rèn)為這個(gè)過程都是系統(tǒng)自動(dòng)的,不需要人的參與。

Token 令牌

Token(令牌)是Authorization Server生成的一段類似于uuid的隨機(jī)字符串,在Client請(qǐng)求的時(shí)候生成并返回。
令牌的類型

Access Token : 訪問令牌。允許第三方應(yīng)用程序使用并訪問用戶的數(shù)據(jù)。此token由Client作為參數(shù)或者請(qǐng)求header發(fā)送到Resource Server,并且應(yīng)具有有限的生命周期,過期時(shí)限由Authorization Server決定。

Refresh Token : 刷新令牌。與access token一并生成,但與access token不同的是,它不會(huì)在每一個(gè)向Resource Server請(qǐng)求數(shù)據(jù)的時(shí)候發(fā)送給服務(wù)器。僅僅用于服務(wù)器過期時(shí)發(fā)送給服務(wù)器來更新access token。

Authorization grant types 授權(quán)類型

OAuth2定義了4種授權(quán)的類型,具體選用哪一種類型取決于不同的場景以及需求。

Authorization Code Grant 授予授權(quán)代碼
何時(shí)使用

如果Client是Web服務(wù)器,那么默認(rèn)應(yīng)該使用這種模式,這也是OAuth2默認(rèn)的方式。這種模式允許Client長期訪問Token,并且刷新Token的續(xù)訂,即使用Refresh Token。

例如

Resource Owner : 你

Resource Server: Google服務(wù)器

Client: Facebook網(wǎng)站

Authorization Server:Google服務(wù)器

場景

網(wǎng)站希望獲得你的Google個(gè)人資料的信息。

你將被Client(網(wǎng)站)重定向到Authorization Server(Google)

如果你授權(quán)訪問,Authorization Server會(huì)在回調(diào)中向Client發(fā)送Authorization Code

使用Authorization Code向Authorization Server申請(qǐng)Access Token

Client可以使用Access Token查詢Resource Server并獲取你的個(gè)人資料信息。

佛系架構(gòu)圖 參考(http://goo.gl/hbl1B)
題外話,http://www.websequencediagram...    真的很棒
『 Legend 』: 
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                                       
┃ >=========> : Http POST request.                                                          ┃        
┃ <~~~~~~~~~< : Response from server.                                                       ┃
┃ >---------> : Forward or redirect to.                                                     ┃ 
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛


『 Sequence Diagram 』: 


           ┏━━━━━━━━━━━━━━━┓   ┏━━━━━━┓                          ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
           ┃Ressource Owner┃   ┃Client┃                          ┃Authorization Server┃            ┃Resource Server ┃       
           ┗━━━━━━━━━━━━━━━┛   ┗━━━━━━┛                          ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃ Authorization Code Request            ┏━┓                              ┃
                   ┃               ┃ >===================================> ┃ ┃                              ┃
                   ┃               ┃                +----------------------------------+                    ┃
                   ┃               ┃                | Needs client_id,redirect_uri,    |                    ┃
                   ┃                                | reponse_type=code[,scope,state]  |                    ┃
                   ┃   Login & Consent              +----------------------------------+                    ┃
                   ┃ >===================================================> ┃ ┃                              ┃
                   ┃               ┃                                       ┃ ┃                              ┃
                   ┃               ┃  Authorization Code Reponse           ┃ ┃                              ┃
                   ┃               ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃                              ┃
                   ┃               ┃                                       ┃ ┃                              ┃
                   ┃               ┃                                       ┗━┛                              ┃ 
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃                                       ┏━┓                              ┃
                   ┃               ┃  Exchange Code For Access Token       ┃ ┃                              ┃
                   ┃               ┃ >===================================> ┃ ┃                              ┃
                   ┃               ┃         +--------------------------------------------+                 ┃
                   ┃               ┃         | Needs client_id,client_secret,redirect_uri |                 ┃
                   ┃               ┃         | grant_type=authorization_code,code         |                 ┃
                   ┃               ┃         +--------------------------------------------+                 ┃
                   ┃               ┃   Access Token [+ Refresh Token]      ┃ ┃                              ┃
                   ┃               ┃  <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┗━┛                              ┃
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃                                        ┃                               ┃
    ┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃loop┃         ┃               ┃                                        ┃                               ┃      ┃
    ┣━━━━╋         ┃               ┃                                        ┃                               ┃      ┃
    ┃              ┃               ┃  Call API with Access Token            ┃                              ┏━┓     ┃
    ┃              ┃               ┃ >===================================================================> ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃                              ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃       Reponse with Data      ┃ ┃     ┃
    ┃              ┃               ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃                              ┗━┛     ┃
    ┃              ┃               ┃                                        ┃                               ┃      ┃
    ┃              ┃               ┃                                        ┃                               ┃      ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃                                        ┃                               ┃
           ┏━━━━━━━━━━━━━━━┓   ┏━━━━━━┓                          ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
           ┃Ressource Owner┃   ┃Client┃                          ┃Authorization Server┃            ┃Resource Server ┃       
           ┗━━━━━━━━━━━━━━━┛   ┗━━━━━━┛                          ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         

Implicit Grant 隱性授權(quán)
何時(shí)使用

與Authorization Code Grant的方式不同的是,Client不是一個(gè)Web Server,而是嵌入在瀏覽器的腳本語言,比如javascript。

例如:

Resource Owner: 你

Resource Server: Google服務(wù)器

Client: 使用Jquery或Angular js的客戶端

Authorization Server: Google服務(wù)器

場景:

Client的js端希望獲得Google的個(gè)人資料信息

你會(huì)被重定向到Google的Authorization Server

如果你授權(quán)使用自己的Google個(gè)人信息資料給Client,則Authorization Server會(huì)把Access Token異步回調(diào)給js的Client

Client可以使用Access Token查詢Resource Server并獲取你的個(gè)人資料信息(通過js的異步調(diào)用)。

佛系架構(gòu)圖
『 Legend 』: 
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                                       
┃ >=========> : Http POST request.                                                          ┃        
┃ <~~~~~~~~~< : Response from server.                                                       ┃
┃ >---------> : Forward or redirect to.                                                     ┃ 
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛


『 Sequence Diagram 』: 


           ┏━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━┓             ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
           ┃Ressource Owner┃ ┃Client(Javascript App)┃             ┃Authorization Server┃            ┃Resource Server ┃       
           ┗━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━┛             ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃ Authorization Token Request           ┏━┓                              ┃
                   ┃               ┃ >===================================> ┃ ┃                              ┃
                   ┃               ┃                +----------------------------------+                    ┃
                   ┃               ┃                | Needs client_id,redirect_uri,    |                    ┃
                   ┃                                | reponse_type=token[,scope,state] |                    ┃
                   ┃   Login & Consent              +----------------------------------+                    ┃
                   ┃ >===================================================> ┃ ┃                              ┃
                   ┃               ┃                                       ┃ ┃                              ┃
                   ┃               ┃                       Access Token    ┃ ┃                              ┃
                   ┃               ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃                              ┃
                   ┃               ┃                                       ┃ ┃                              ┃
                   ┃               ┃                                       ┗━┛                              ┃ 
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃                                       ┏━┓                              ┃
                   ┃               ┃  Access Token Info Request            ┃ ┃                              ┃
                   ┃               ┃ >===================================> ┃ ┃                              ┃
                   ┃               ┃                                       ┃ ┃                              ┃
                   ┃               ┃                Access Token Info      ┃ ┃                              ┃
                   ┃               ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┗━┛                              ┃
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃                                        ┃                               ┃
    ┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃loop┃         ┃               ┃                                        ┃                               ┃      ┃
    ┣━━━━╋         ┃               ┃                                        ┃                               ┃      ┃
    ┃              ┃               ┃  Call API with Access Token            ┃                              ┏━┓     ┃
    ┃              ┃               ┃ >===================================================================> ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃                              ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃      +-----------------------------+ ┃
    ┃              ┃               ┃                                        ┃      | Implement CORS For Cross    | ┃
    ┃              ┃               ┃                                        ┃      | Domain Requests             | ┃
    ┃              ┃               ┃                                        ┃      +-----------------------------+ ┃
    ┃              ┃               ┃                                        ┃                              ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃       Reponse with Data      ┃ ┃     ┃
    ┃              ┃               ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃     ┃
    ┃              ┃               ┃                                        ┃                              ┗━┛     ┃
    ┃              ┃               ┃                                        ┃                               ┃      ┃
    ┃              ┃               ┃                                        ┃                               ┃      ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
                   ┃               ┃                                        ┃                               ┃
                   ┃               ┃                                        ┃                               ┃
           ┏━━━━━━━━━━━━━━━┓   ┏━━━━━━━━━━━━━━━━━━━━━━┓          ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
           ┃Ressource Owner┃   ┃Client(Javascript App)┃          ┃Authorization Server┃            ┃Resource Server ┃       
           ┗━━━━━━━━━━━━━━━┛   ┗━━━━━━━━━━━━━━━━━━━━━━┛          ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         

Resource Owner Password Credentials 授予資源擁有者密碼憑證
何時(shí)使用

利用這種方式,你的憑證,一般來講就是密碼,會(huì)先發(fā)送給Client,然后通過Client發(fā)送給Authorization Server。通過這種方式可以看出,Client與Authorization Server之間應(yīng)該有著絕對(duì)的信任,一般情況下,Client與Authorization Server是同等權(quán)限體系的,換句話說,應(yīng)該是client.example.com與auth.example.com相同網(wǎng)站的不同resource級(jí)別的關(guān)系,由于用戶的密碼都是屬于example.com體系下的,所以在client.example.com或者任何xxx.example.com中輸入密碼,去resource.example.com獲取數(shù)據(jù)都是可以接受的。

例如:

Resource Owner: 你

Resource Server:resource.example.com服務(wù)器

Client: new.example.com的服務(wù)器,需要調(diào)用自己網(wǎng)站的認(rèn)證系統(tǒng)

Authorization Server: auth.example.com服務(wù)器

場景:

example公司開發(fā)了新的new.example.com的子系統(tǒng)

調(diào)用自己公司的auth.example.com認(rèn)證

認(rèn)證成功后從Authorization Server獲取Access Token

利用Access Token去調(diào)用自己的resource.example.com的api獲取相應(yīng)數(shù)據(jù)

佛系架構(gòu)圖
『 Legend 』: 
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                                      
┃ >=========> : Http POST request.                                                          ┃        
┃ <~~~~~~~~~< : Response from server.                                                       ┃
┃ >---------> : Forward or redirect to.                                                     ┃ 
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛


『 Sequence Diagram 』: 


           ┏━━━━━━━━━━━━━━━┓      ┏━━━━━━━┓                          ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
           ┃Ressource Owner┃      ┃Client ┃                          ┃Authorization Server┃            ┃Resource Server ┃       
           ┗━━━━━━━━━━━━━━━┛      ┗━━━━━━━┛                          ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         
                   ┃ Authorization    ┃                                        ┃                               ┃
                   ┃>================>┃                                        ┃                               ┃
                   ┃ with Credentials ┃                                        ┃                               ┃
                   ┃                  ┃ Access Token Request                  ┏━┓                              ┃
                   ┃                  ┃ >===================================> ┃ ┃                              ┃
                   ┃                  ┃                +-------------------------------------+                 ┃
                   ┃                  ┃                | Needs client_id,redirect_uri,       |                 ┃
                   ┃                                   | reponse_type=password[,scope,state] |                 ┃
                   ┃   Login & Consent                 +-------------------------------------+                 ┃
                   ┃ >======================================================> ┃ ┃                              ┃
                   ┃                  ┃                                       ┃ ┃                              ┃
                   ┃                  ┃                       Access Token    ┃ ┃                              ┃
                   ┃                  ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃                              ┃
                   ┃                  ┃                                       ┃ ┃                              ┃
                   ┃                  ┃                                       ┗━┛                              ┃ 
                   ┃                  ┃                                        ┃                               ┃
                   ┃                  ┃                                       ┏━┓                              ┃
                   ┃                  ┃  Access Token Info Request            ┃ ┃                              ┃
                   ┃                  ┃ >===================================> ┃ ┃                              ┃
                   ┃                  ┃                                       ┃ ┃                              ┃
                   ┃                  ┃                Access Token Info      ┃ ┃                              ┃
                   ┃                  ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┗━┛                              ┃
                   ┃                  ┃                                        ┃                               ┃
                   ┃                  ┃                                        ┃                               ┃
    ┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃loop┃         ┃                  ┃                                        ┃                               ┃   ┃
    ┣━━━━╋         ┃                  ┃                                        ┃                               ┃   ┃
    ┃              ┃                  ┃  Call API with Access Token            ┃                              ┏━┓  ┃
    ┃              ┃                  ┃ >===================================================================> ┃ ┃  ┃
    ┃              ┃                  ┃                                        ┃                              ┃ ┃  ┃
    ┃              ┃                  ┃                                        ┃                              ┃ ┃  ┃
    ┃              ┃                  ┃                                        ┃       Reponse with Data      ┃ ┃  ┃
    ┃              ┃                  ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃  ┃
    ┃              ┃                  ┃                                        ┃                              ┗━┛  ┃
    ┃              ┃                  ┃                                        ┃                               ┃   ┃
    ┃              ┃                  ┃                                        ┃                               ┃   ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
                   ┃                  ┃                                        ┃                               ┃   
           ┏━━━━━━━━━━━━━━━┓      ┏━━━━━━━┓                          ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
           ┃Ressource Owner┃      ┃Client ┃                          ┃Authorization Server┃            ┃Resource Server ┃       
           ┗━━━━━━━━━━━━━━━┛      ┗━━━━━━━┛                          ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         

Client Credentials Grant 授權(quán)客戶憑證
何時(shí)使用

當(dāng)Client自身是Resource Owner的場合,這時(shí)只需要認(rèn)證client_id即可,本身不產(chǎn)生其他的授權(quán)認(rèn)證。

例如:

Resource Owner: 任何一家網(wǎng)站

Resource Server:Google服務(wù)器

Client: =Resource Owner

Authorization Server: Google服務(wù)器

場景:

網(wǎng)站A保存自己的所有files在Google的云存儲(chǔ)服務(wù)器

網(wǎng)站A需要通過Google Api進(jìn)行files的操作,操作前必須在Authorization Server中認(rèn)證

一旦認(rèn)證成功,網(wǎng)站A獲取Access Token來訪問Google的Resource Server

Authorization Server不會(huì)授權(quán)其他的權(quán)限給Resource Owner

佛系架構(gòu)圖
『 Legend 』: 
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                                      
┃ >=========> : Http POST request.                                                          ┃        
┃ <~~~~~~~~~< : Response from server.                                                       ┃
┃ >---------> : Forward or redirect to.                                                     ┃ 
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛


『 Sequence Diagram 』: 


       ┏━━━━━━━━━━━━━━━━━━━━━━┓                                      ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
       ┃Client(Resource Owner)┃                                      ┃Authorization Server┃            ┃Resource Server ┃       
       ┗━━━━━━━━━━━━━━━━━━━━━━┛                                      ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         
                   ┃                                                           ┃                               ┃
                   ┃                                                           ┃                               ┃
                   ┃                                                           ┃                               ┃
                   ┃  Access Token Request                                    ┏━┓                              ┃
                   ┃>=======================================================> ┃ ┃                              ┃
                   ┃                                   +-----------------------------------------------+       ┃
                   ┃                                   | Needs client_id,redirect_uri,                 |       ┃
                   ┃                                   | reponse_type=client_credentials[,scope,state] |       ┃
                   ┃                                   +-----------------------------------------------+       ┃
                   ┃                                                          ┃ ┃                              ┃
                   ┃                                                          ┃ ┃                              ┃
                   ┃                                                          ┃ ┃                              ┃
                   ┃  Access Token                                            ┃ ┃                              ┃
                   ┃<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~< ┃ ┃                              ┃
                   ┃                                                          ┗━┛                              ┃ 
                   ┃                                                           ┃                               ┃
                   ┃                                                           ┃                               ┃
                   ┃                                                           ┃                               ┃
    ┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    ┃loop┃         ┃                                                           ┃                               ┃   ┃
    ┣━━━━╋         ┃                                                           ┃                               ┃   ┃
    ┃              ┃    Call API with Access Token                             ┃                              ┏━┓  ┃
    ┃              ┃ >=====================================================================================>  ┃ ┃  ┃
    ┃              ┃                                                           ┃                              ┃ ┃  ┃
    ┃              ┃                                                           ┃                              ┃ ┃  ┃
    ┃              ┃                                                           ┃       Reponse with Data      ┃ ┃  ┃
    ┃              ┃ <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<  ┃ ┃  ┃
    ┃              ┃                                                           ┃                              ┗━┛  ┃
    ┃              ┃                                                           ┃                               ┃   ┃
    ┃              ┃                                                           ┃                               ┃   ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
                   ┃                                                           ┃                               ┃   
       ┏━━━━━━━━━━━━━━━━━━━━━━┓                                      ┏━━━━━━━━━━━━━━━━━━━━┓            ┏━━━━━━━━━━━━━━━━┓
       ┃Client(Resource Owner)┃                                      ┃Authorization Server┃            ┃Resource Server ┃       
       ┗━━━━━━━━━━━━━━━━━━━━━━┛                                      ┗━━━━━━━━━━━━━━━━━━━━┛            ┗━━━━━━━━━━━━━━━━┛                         

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/71604.html

相關(guān)文章

  • Spring Cloud OAuth 微服務(wù)內(nèi)部Token傳遞的源碼實(shí)現(xiàn)解析

    摘要:源碼非常簡單談?wù)剬?shí)現(xiàn)的問題當(dāng)請(qǐng)求上線文沒有如果調(diào)用會(huì)直接,這個(gè)肯定會(huì)報(bào)錯(cuò),因?yàn)樯舷挛氖∪绻O(shè)置線程隔離,這里也會(huì)報(bào)錯(cuò)。導(dǎo)致安全上下問題傳遞不到子線程中。歡迎關(guān)注我們獲得更多的好玩實(shí)踐 背景分析 showImg(https://segmentfault.com/img/remote/1460000018899024?w=494&h=245); 1.客戶端攜帶認(rèn)證中心發(fā)放的token,...

    Michael_Ding 評(píng)論0 收藏0
  • Spring Security OAuth2 優(yōu)雅的集成短信驗(yàn)證碼登錄以及第三方登錄

    摘要:前言基于做微服務(wù)架構(gòu)分布式系統(tǒng)時(shí),作為認(rèn)證的業(yè)內(nèi)標(biāo)準(zhǔn),也提供了全套的解決方案來支持在環(huán)境下使用,提供了開箱即用的組件。 前言 基于SpringCloud做微服務(wù)架構(gòu)分布式系統(tǒng)時(shí),OAuth2.0作為認(rèn)證的業(yè)內(nèi)標(biāo)準(zhǔn),Spring Security OAuth2也提供了全套的解決方案來支持在Spring Cloud/Spring Boot環(huán)境下使用OAuth2.0,提供了開箱即用的組件。但...

    yck 評(píng)論0 收藏0
  • Spring Cloud 上手實(shí)戰(zhàn)-架構(gòu)解析及實(shí)作

    摘要:服務(wù)器將要監(jiān)聽的端口不要使用服務(wù)進(jìn)行注冊(cè)不要在本地緩存注冊(cè)表信息使用一個(gè)新的注解,就可以讓我們的服務(wù)成為一個(gè)服務(wù)服務(wù)發(fā)現(xiàn)客戶端配置以為例需要做件事情成為服務(wù)發(fā)現(xiàn)的客戶端配置對(duì)應(yīng)來說我們只需要配置如下啟動(dòng)運(yùn)行查看。 Spring簡介 為什么要使用微服務(wù) 單體應(yīng)用: 目前為止絕大部分的web應(yīng)用軟件采用單體應(yīng)用,所有的應(yīng)用的用戶UI、業(yè)務(wù)邏輯、數(shù)據(jù)庫訪問都打包在一個(gè)應(yīng)用程序上。 showI...

    Godtoy 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

TIGERB

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<