> For the complete documentation index, see [llms.txt](https://brianwu.gitbook.io/brian/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brianwu.gitbook.io/brian/brians-za-ji/oauth-vs-open-id.md).

# OAuth vs Open ID

<https://hackmd.io/s/ryJJofc0X>

## 客戶端憑據授權

1.OAuth 2.0 客戶端使用其客戶端憑據和授權服務器進行身分驗證，並從令牌端點請求訪問令牌。

2.授權服務器對OAuth 2.0 客戶端進行身分驗證，並驗證客戶端憑據，如果憑據有效，那麼服務器將會頒發一個訪問令牌。

|                 |                        |                      |
| --------------- | :--------------------: | -------------------- |
| OAuth2.0 Client | Client credentials---> | Authorization server |
|                 |    <---Access token    |                      |

客戶端 對令牌端點(授權服務器) 發出請求，採用 application/x-www-form-urlencoded 格式發送以下參數。

grant\_type:必選。必須設置為 client\_credentials。 client\_id:必選。客戶端ID。 client\_secret:必選。客戶端密鑰、密碼。 scope:可選。訪問請求的範圍。

因為客戶端身分驗證被用作授權批准，所以不需要額外的授權，。例如，客戶端利用傳輸層安全性發出下列HTTP請求。

1.客戶端HTTP請求 POST /token HTTP/1.1 Host: server.example.com Authorization:Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW Content-Type: application/x-www-form-urlencoded grant\_type:client\_credentials\&client\_id=myapp\&client\_secret=ab32vr

訪問令牌響應

對應於步驟B的訪問令牌應該如圖1所示。 如果訪問令牌請求是有效的，而且獲得了授權，那麼授權服務器將會返回訪問令牌。

成功的響應如清單2所示。

清單2.訪問令牌響應

HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Cache-Control: no-store Pragma: no-cache { "access\_token":"2YotnFZFEjr1zCsicMWpAA", "token\_type":"example", "expires\_in":"3600", "example\_parameter":"example\_value" }

如果請求無效，或者未經過授權，那麼授權伺服器將會使用代碼返回一個相應的錯誤消息。

## 設置

## Data Flow

<https://drive.google.com/file/d/1AGZZ1Fcm0D_zZH9NTVbrkIndH3lPXjcH/view?usp=sharing>

<https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2>
