Try   HackMD
tags: jubo tutorials web security oauth2

OAuth2 Explained

回顧陽春版驗證:User 與資源伺服器直接互動

  • 使用者在 first-party app 上,使用自己的帳號登入、並且存取自己在該 server 上儲存的內容
  • 此 first-party app 本身就是擁有資源的伺服器 (Resource server),通常也是授權伺服器 (Authz server)
ServerWebServerWeb使用者在 Web 上操作執行驗證 (authn)/授權 (authz)User使用者透過帳密登入Set-Cookie 等方式回傳驗證後資訊User
  • Resource/Authz server 是否分別為不同的 running instance (i.e. different servers),端看實作方如何實作

OAuth2.0 (3-legged):有 3-party app 想要存取 User 的資源

  • 在此介紹一個 OAuth2.0 最普遍的應用情境:Web Server Apps
  • 有個 3-party app 開發了有趣的服務,但需要 User 在資源/授權伺服器裡的資料,才能夠提供更完整的服務
    • 在此我們將 3-party app 定義為 "client" (呼應 resource/authz "server")
  • 在一切開始前,3-party app 需要拿著 Redirect URI基本資訊 (e.g. app name),先向資源伺服器方註冊一組 client_idclient_secret
Resource/Authz ServerClient (3-party app)Resource/Authz ServerClient (3-party app)註冊 (Redirect URI, app name, etc.)回傳 client_id, client_secret
  • 其中
    • client_id 為 public information
    • client_secret 為 private credential
  • 接著,直接來看一個完整 User flow
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 其中
    • (3.) 中的 scope 是 Resource/Authz server 事先告訴你可以選擇的資源項目,依照業務需求而定

See also