0%

Third party login with Google - Application (postman)

從申請 Google OAuth2.0 憑證到應用 - OAuth介紹與應用

OAuth 介紹 [1]

  • 授權標準協議
  • 讓第三方應用程式可以存取使用者的資源
  • 根據不同grant types分為四個流程 - authorization code, implicit, resource owner password credentials, and client credentials.

角色

  • Client (Your application)
  • Resource owner (End user)
  • Resource server (like Google)
  • Authorization server (like Google)

基本流程圖

以下為基本架構,實際會根據不同的grant types分為四種流程

四種流程差異

在 (C) 步驟有所差別

  • authorization code: 遵循基本流程圖 (最安全)
  • implicit: 在 Authorization server 提供的 login page 登入成功後,核發 access token
  • resource owner password credentials: 以使用者帳號/密碼換取 access token
  • client credentials: 以 clientID, clientSecret 換取 access token

應用 (以Google為例)

前提:要有架好的server去接收grant code (Google 使用的為 Authorization code flow)
以下會以 flow + postman 搭配來說明

1. 由使用者透過應用程式選擇Google登入,發送request到google server

發送參數為之前介紹提到之下載的憑證資訊

2. google server返回常見的登入畫面,使用者進行登入

3. 登入成功後,網頁將會導向當初設定的redirect URL,並附帶code參數值

4. 將code和其他參數對google發出第二次request,此步驟為向google server要求access token (通常在後端進行)

5. 在google server驗證完其身分成功後,回傳access token給應用程式

6. 最後,便可於呼叫google api時,在header附帶此access token,獲取當前使用者的資訊或相關權限的行為


關於OAuth的簡單介紹就到這邊,有問題都可以底下討論 🦦