###### tags: `jubo` `tutorials` `web security` `oauth2` [TOC] # OAuth2 Explained ## 回顧陽春版驗證:User 與資源伺服器直接互動 - 使用者在 first-party app 上,使用自己的帳號登入、並且存取自己在該 server 上儲存的內容 - 此 first-party app 本身就是擁有資源的伺服器 (Resource server),通常也是授權伺服器 (Authz server) ```mermaid sequenceDiagram actor u as User participant w as Web participant s as Server Note over u, w: 使用者在 Web 上操作 w->>s: 使用者透過帳密登入 Note over s: 執行驗證 (authn)/授權 (authz) s->>w: Set-Cookie 等方式回傳驗證後資訊 ``` - Resource/Authz server 是否分別為不同的 running instance (i.e. different servers),端看實作方如何實作 ## OAuth2.0 (3-legged):有 3-party app 想要存取 User 的資源 - 在此介紹一個 OAuth2.0 最普遍的應用情境:**[Web Server Apps](https://aaronparecki.com/oauth-2-simplified/#web-server-apps)** - 有個 3-party app 開發了有趣的服務,但需要 User 在資源/授權伺服器裡的資料,才能夠提供更完整的服務 - 在此我們將 3-party app 定義為 "**client**" (呼應 resource/authz "**server**") - 在一切開始前,3-party app 需要拿著 **Redirect URI** 及**基本資訊 (e.g. app name)**,先向資源伺服器方註冊一組 **client_id** 與 **client_secret** ```mermaid sequenceDiagram participant c as Client (3-party app) participant s as Resource/Authz Server c->>s: 註冊 (Redirect URI, app name, etc.) s->>c: 回傳 client_id, client_secret ``` - 其中 - client_id 為 public information - client_secret 為 **private credential** - 接著,直接來看一個完整 User flow  - 其中 - (3.) 中的 **scope** 是 Resource/Authz server 事先告訴你可以選擇的資源項目,依照業務需求而定 # See also - https://aaronparecki.com/oauth-2-simplified/ - [[筆記] 認識 OAuth 2.0:一次了解各角色、各類型流程的差異](https://medium.com/%E9%BA%A5%E5%85%8B%E7%9A%84%E5%8D%8A%E8%B7%AF%E5%87%BA%E5%AE%B6%E7%AD%86%E8%A8%98/%E7%AD%86%E8%A8%98-%E8%AA%8D%E8%AD%98-oauth-2-0-%E4%B8%80%E6%AC%A1%E4%BA%86%E8%A7%A3%E5%90%84%E8%A7%92%E8%89%B2-%E5%90%84%E9%A1%9E%E5%9E%8B%E6%B5%81%E7%A8%8B%E7%9A%84%E5%B7%AE%E7%95%B0-c42da83a6015)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up