本頁說明如何以程式輔助方式建立 OAuth 用戶端,以便搭配 IAP 使用,讓您以程式輔助方式為內部應用程式設定端對端 IAP。
已知限制
透過這個 API 以程式輔助方式建立的 OAuth 用戶端有幾項限制:
- 透過 API 建立的 OAuth 用戶端只能使用 API 進行修改。如果 OAuth 用戶端是透過 API 建立,您就無法透過 Google Cloud 控制台修改。
- API 建立的 OAuth 用戶端僅供 IAP 使用,因此 API 不允許更新重新導向 URI 或其他屬性。
- 這個 API 無法處理使用 Google Cloud 控制台建立的 OAuth 用戶端。
- 使用 API 時,每項專案最多只能有 500 個 OAuth 用戶端。
- 透過 API 建立的 OAuth 同意畫面品牌有特定限制。詳情請參閱下文。
瞭解品牌和品牌狀態
OAuth 同意畫面含有使用者品牌資訊,又稱為品牌。品牌可限定內部或公開使用者。內部品牌可讓與專案屬於相同 Google Workspace 機構的使用者存取 OAuth 流程。公開品牌可讓網際網路上的任何人使用 OAuth 流程。
品牌可透過 API 手動或以程式輔助方式建立。透過 API 建立的品牌會自動設定不同的設定:
- 這些設定預設為內部,如要設為公開,請手動變更
- 設為「未審查」狀態,且必須觸發品牌審查
如要手動將內部品牌設為公開,請按照下列步驟操作:
- 開啟 OAuth 同意畫面。
- 從下拉式選單中選取所需專案。
- 在「OAuth 同意畫面」頁面中,請注意「使用者類型」會自動設為「內部」。如要設為「公開」,請按一下「編輯應用程式」,即可使用更多設定選項。
- 在「應用程式類型」下方,按一下「公開」。
如要為未審查的 API 建立品牌觸發品牌審查,請按照下列步驟操作:
- 開啟 OAuth 同意畫面。
- 從下拉式選單中選取所需專案。
- 在「OAuth 同意畫面」頁面中輸入所有必要資訊,然後按一下「提交以供驗證」。
驗證程序可能需要數週的時間才能完成。在此期間,我們會透過電子郵件傳送最新消息給您。如要進一步瞭解驗證程序,請參閱這篇文章。驗證程序進行期間,您仍可在 Google Workspace 機構內使用應用程式。進一步瞭解應用程式通過驗證前會出現哪些行為。
事前準備
建立用戶端前,請先確認呼叫端已獲授下列權限:
clientauthconfig.brands.listclientauthconfig.brands.createclientauthconfig.brands.getclientauthconfig.clients.createclientauthconfig.clients.listWithSecrets(僅在列出含有密鑰的 OAuth 用戶端時需要)。clientauthconfig.clients.getWithSecretclientauthconfig.clients.deleteclientauthconfig.clients.update
「編輯者」roles/editor和「擁有者」roles/owner基本角色都具備這些權限,但建議您建立包含這些權限的自訂角色,並將該角色授予呼叫端。
設定 IAP 的 OAuth
下列步驟說明如何設定同意畫面,以及為 IAP 建立 OAuth 用戶端。
Configuring consent screen
Check if you already have an existing brand by using the list command. You may only have one brand per project.
gcloud iap oauth-brands list
The following is an example gcloud response, if the brand exists:
name: projects/[PROJECT_NUMBER]/brands/[BRAND_ID] applicationTitle: [APPLICATION_TITLE] supportEmail: [SUPPORT_EMAIL] orgInternalOnly: trueIf no brand exists, use the create command:
gcloud iap oauth-brands create --application_title=APPLICATION_TITLE --support_email=SUPPORT_EMAIL
The above fields are required when calling this API:
supportEmail: The support email displayed on the OAuth consent screen. This email address can either be a user's address or a Google Groups alias. While service accounts also have an email address, they are not actual valid email addresses, and cannot be used when creating a brand. However, a service account can be the owner of a Google Group. Either create a new Google Group or configure an existing group and set the desired service account as an owner of the group.applicationTitle: The application name displayed on OAuth consent screen.
The response contains the following fields:
name: projects/[PROJECT_NUMBER]/brands/[BRAND_ID] applicationTitle: [APPLICATION_TITLE] supportEmail: [SUPPORT_EMAIL] orgInternalOnly: true
Creating an IAP OAuth Client
Use the create command to create a client. Use the brand
namefrom previous step.gcloud iap oauth-clients create projects/PROJECT_NUMBER/brands/BRAND-ID --display_name=NAME
The response contains the following fields:
name: projects/[PROJECT_NUMBER]/brands/[BRAND_NAME]/identityAwareProxyClients/[CLIENT_ID] secret: [CLIENT_SECRET] displayName: [NAME]
使用用戶端 ID (上例中的 client_id) 和 secret 啟用 IAP。如要進一步瞭解如何使用剛才建立的憑證啟用 IAP,請參閱下列主題: