How to get google client id & client secret
取得 Google OAuth 2.0 的 Client ID 和 Client Secret,你需要到 Google Cloud Console 進行申請
1. 建立專案
-
如果你還沒有專案,點擊左上角的專案選擇器,選擇 「新專案」 (New Project),輸入專案名稱(例如
My-Microservice-App)並建立。
2. 設定 OAuth 同意畫面 (Consent Screen)
在拿到金鑰前,Google 要求你必須先設定「使用者會看到什麼」。
-
在左側選單點擊 「API 和服務」 > 「OAuth 同意畫面」。
-
選擇 「外部」 (External) 並點擊建立。
-
填寫基本資訊:
-
App name: 你的 App 名稱(例如
Order System)。 -
User support email: 你的信箱。
-
Developer contact information: 你的信箱。
-
-
後面的「範圍 (Scopes)」和「測試使用者」可以先按 Save and Continue 跳過,直到回到儀表板。
3. 建立憑證 (Credentials) 取得金鑰
-
點擊左側選單的 「憑證」 (Credentials)。
-
點擊上方的 「+ 建立憑證」 > 「OAuth 用戶端 ID」。
-
應用程式類型選擇:「網頁應用程式」 (Web application)。
-
名稱:隨意填寫(例如
Gateway-Client)。 -
已授權的重新導向 URI (Authorized redirect URIs):
-
這是最重要的設定!Spring Security 預設的 OAuth 回調路徑是:
-
http://localhost:8080/login/oauth2/code/google -
(註:8080 是你 Gateway 的埠號,請根據實際情況修改)
-
-
點擊 「建立」。