您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。 info
在 Edge API 中使用 SAML 時,從 SAML 判斷提示取得 OAuth2 存取和重新整理權杖的程序稱為「密碼」流程。在密碼流程中,您會使用瀏覽器取得動態密碼,然後使用該密碼取得 OAuth2 權杖。
不過,您的環境可能支援常見開發工作的自動化,例如測試自動化或持續整合/持續部署 (CI/CD)。啟用 SAML 時,如要自動執行這些工作,您需要取得及重新整理 OAuth2 權杖,不必從瀏覽器複製/貼上密碼。
關於電腦使用者
Apigee Edge 支援啟用 SAML 的機構中的機器使用者。機器使用者僅用於自動化動作,不會由真人直接存取。
機器使用者可以取得 OAuth2 權杖,不必指定密碼。也就是說,您可以使用 Edge API,完全自動化取得及更新 OAuth2 權杖的程序。
自動產生權杖的步驟
如要自動產生權杖,請按照下列步驟操作:
| 步驟 | 說明 |
|---|---|
| 1 | 在 SAML 識別資訊區域中建立機器使用者 |
| 2 | 在 Edge 機構中,為機器使用者指派必要角色 |
| 3 | 取得機器使用者的 OAuth2 權杖 |
影片:觀看短片,瞭解如何使用機器使用者憑證,自動存取 Apigee Edge API。
管理 SAML 身分區域的機器使用者
Apigee 提供機器使用者管理指令列介面 (CLI),可建立及管理機器使用者帳戶。 如要瞭解如何使用機器使用者管理 CLI,請參閱下列章節。
使用 CLI
如要使用機器使用者管理 CLI,請先下載並解壓縮下列檔案:
usermgmt.tar.gz(1)
呼叫 CLI 的格式如下:
usermgmt_platform [command] [flags]
下表摘要列出支援的平台,以及呼叫機器使用者管理 CLI 的對應指令。(可執行檔位於 usermgmt 目錄中)。
| 平台 | 32 位元 | 64 位元 |
|---|---|---|
| Linux | usermgmt_linux_386 |
usermgmt_linux_amd64 |
| Mac | usermgmt_darwin_386 |
usermgmt_darwin_amd64 |
| Windows | usermgmt_windows_386 |
usermgmt_windows_amd64 |
下表摘要列出可指定的指令。
| 指令 | 更多資訊 |
|---|---|
create
|
在身分識別區域中建立機器使用者 |
delete
|
刪除身分識別區域中的機器使用者 |
help
|
取得 CLI 使用說明 |
list
|
列出身分識別區域中的所有機器使用者 |
reset
|
重設身分識別區域中機器使用者的密碼 |
(選用) 您可以傳遞下列其中一個旗標,顯示指定指令的說明:-h 或 --help
登入 CLI
首次在 24 小時內執行 CLI 時,系統會提示您輸入 zoneadmin 帳戶憑證。
Enter your Apigee credentials
Username: zoneadmin-username
Password: zoneadmin-password
If your user is opted with MFA, enter MFA code. Otherwise press enter to skip.
MFA: mfa-code_or_enter_to_skip機器使用者管理 CLI 會在本機儲存存取權杖,因此每 24 小時內只需登入一次。
取得 CLI 使用說明
使用 usermgmt_platform help 指令顯示 CLI 用法資訊。如需支援的平台清單,請參閱「使用 CLI」。
usermgmt_platform help
系統會顯示下列說明資訊:
A command-line interface (CLI) to manage machine user accounts to automate
Apigee identity zone management. Use the CLI to create, list, delete,
and reset the password for machine users.
Usage:
usermgmt [flags]
usermgmt [command]
Available Commands:
create Creates a machine users in an identity zone.
delete Deletes a machine users in an identity zone.
help Help about any command
list Lists the machine users in an identity zone.
reset Resets the password for a machine user in an identity zone.
Flags:
-h, --help help for usermgmt
Use "usermgmt [command] --help" for more information about a command.
在指令列中同時傳遞指令和 -h 或 --help 旗標,即可顯示特定指令的說明。
舉例來說,如要取得 list 指令的說明,請輸入:
usermgmt_platform list -h
系統會顯示下列說明資訊:
Lists the machine users in an identity zone.
Usage:
usermgmt list [flags]
Flags:
-h, --help help for list
在身分識別區域中建立機器使用者
使用 usermgmt_platform create 指令,在身分識別區域中建立機器使用者。 如需支援的平台清單,請參閱「使用 CLI」。
- 輸入下列指令:
usermgmt_platform create系統會顯示身分識別區域清單:
myzone1 myzone2 - 在提示中輸入區域名稱:
Enter a zone name: myzone1 - 輸入機器使用者的使用者名稱:
Create a Machine User Username: machineuser1@mycompany.com - 輸入電腦使用者的密碼。出現提示時,請重新輸入密碼。
Password: password Re-enter password: password系統會建立使用者。
Created machine user machineuser1@mycompany.com
列出身分識別區域中的所有機器使用者
使用 usermgmt_platform list 指令,列出身分識別區域中的所有機器使用者。如需支援的平台清單,請參閱「使用 CLI」。
- 輸入下列指令:
系統會顯示身分識別區域清單:usermgmt_platform listmyzone1 myzone2 - 在提示中輸入區域名稱:
Enter a zone name: myzone1系統會顯示身分識別區域中的機器使用者清單:
Machine users in the zone: machineuser1@mycompany.com
重設身分識別區域中機器使用者的密碼
使用 usermgmt_platform reset 指令,重設身分識別區域中機器使用者的密碼。如需支援的平台清單,請參閱「使用 CLI」。
- 輸入下列指令:
usermgmt_platform reset系統會顯示身分識別區域清單:
myzone1 myzone2 - 在提示中輸入區域名稱:
Enter a zone name: myzone1 - 輸入要重設密碼的機器使用者名稱:
Reset User Password Enter the username for the machine user Username: machineuser1@mycompany.com - 輸入電腦使用者的新密碼。出現提示時,請重新輸入密碼。
Enter the new password: password Re-enter password: password密碼已重設。
Reset password for machine user machineuser1@mycompany.com
刪除身分識別區域中的機器使用者
使用 usermgmt_platform delete 指令,刪除身分識別區域中的機器使用者。如需支援的平台清單,請參閱「使用 CLI」。
- 輸入下列指令:
系統會顯示身分識別區域清單:usermgmt_platform deletemyzone1 myzone2 - 在提示中輸入區域名稱:
Enter a zone name: myzone1 - 輸入要刪除的機器使用者名稱:
Delete User Enter the username for the machine user Username: machineuser1@mycompany.com刪除機器使用者。
Deleted user machineuser1@mycompany.com
在 Edge 機構中,為機器使用者指派必要角色
使用 UI 將機器使用者新增至已啟用 SAML 的 Edge 機構,並指派必要角色 (例如機構管理員),如「新增使用者」一文所述。
取得機器使用者的 OAuth2 權杖
如要自動產生權杖並處理機器使用者的權杖快取,請使用 acurl(1) 和 get_token(1) 公用程式,詳情請參閱「
機器使用者的 OAuth2」和「SAML 區域中的機器使用者」。
如要使用 curl 手動取得機器使用者的 OAuth2 權杖,請按照下列步驟操作:
- 使用偏好的網址編碼工具,為電腦使用者的使用者名稱和密碼編碼。
警告:請使用
內部 網址編碼工具,確保機器使用者憑證不會遭到盜用。 - 呼叫 SAML 權杖端點,產生初始存取和更新權杖,如下列範例所示:
curl -H "Content-Type: application/x-www-form-urlencoded;charset=utf-8" \ -H "accept: application/json;charset=utf-8" \ -H "Authorization: Basic ZWRnZWNsaTplZGdlY2xpc2VjcmV0" -X POST \ https://zoneName.login.apigee.com/oauth/token -s \ -d 'grant_type=password&username=machineusername&password=machineuserpassword'
如要授權,請在
Authorization標頭中傳遞保留的 OAuth2 用戶端憑證ZWRnZWNsaTplZGdlY2xpc2VjcmV0。呼叫會將存取和更新權杖列印到stdout。 - 將存取權杖做為 Bearer 標頭,傳送至 Edge 管理 API 呼叫:
curl -H "Authorization: Bearer ACCESS_TOKEN" \ https://api.enterprise.apigee.com/v1/organizations/orgName
- 存取權杖到期時,您可以將更新權杖傳送至 SAML 權杖端點來更新權杖,如下列範例所示:
curl -H "Content-Type:application/x-www-form-urlencoded;charset=utf-8" \ -H "Accept: application/json;charset=utf-8" \ -H "Authorization: Basic ZWRnZWNsaTplZGdlY2xpc2VjcmV0" -X POST \ https://zoneName.login.apigee.com/oauth/token \ -d 'grant_type=refresh_token&refresh_token=REFRESH_TOKEN'
(1) 版權所有 2023 Google LLC
我們提供的 usermgmt、acurl 和 get_token 工具屬於「軟體」,遵循使用 Google Cloud Platform 相關的管理協議,包含以下《服務專屬條款》:https://cloud.google.com/terms/service-terms。