取得用戶端憑證

本頁內容適用於 ApigeeApigee Hybrid

查看 Apigee Edge 說明文件。

本主題將說明如何取得用戶端憑證 (也稱為開發人員金鑰),以用於 OAuth 2.0 授權流程。

什麼是用戶端憑證?

如要參與任何 OAuth 2.0 授權流程,所有用戶端應用程式都必須向 Apigee (授權伺服器) 註冊。註冊應用程式時,系統會指派兩項憑證:金鑰和密碼。金鑰是公開金鑰,密碼絕不能公開。Apigee 可透過這些憑證金鑰,明確識別用戶端應用程式。

透過 Apigee UI 取得金鑰和密鑰

請參閱「 查看 API 金鑰和密鑰」。

使用 Apigee API 取得金鑰和密鑰

使用 API 取得貴機構的應用程式清單:

curl "https://apigee.googleapis.com/v1/organizations/$ORG/apps" \
  -H "Authorization: Bearer $TOKEN"

其中 $TOKEN 會設為您的 OAuth 2.0 存取權杖,如「取得 OAuth 2.0 存取權杖」一文所述。如要瞭解本範例使用的 curl 選項,請參閱「使用 curl」。如要瞭解可使用的環境變數,請參閱為 Apigee API 要求設定環境變數

這項呼叫會依應用程式 ID 傳回應用程式清單。

[ "da496fae-2a04-4a5c-b2d0-709278a6f9db", "50e3e831-175b-4a05-8fb6-05a54701af6e" ]

如要擷取應用程式的設定檔,請按照下列步驟操作:

curl "https://apigee.googleapis.com/v1/organizations/$ORG/apps/$APP" \
   -H "Authorization: Bearer $TOKEN"

其中 $TOKEN 會設為您的 OAuth 2.0 存取權杖,如「取得 OAuth 2.0 存取權杖」一文所述。如要瞭解本範例使用的 curl 選項,請參閱「使用 curl」。如要瞭解可使用的環境變數,請參閱為 Apigee API 要求設定環境變數

例如:

$ curl https://apigee.googleapis.com/v1/o/organizations/myorg/apps/da496fae-2a04-4a5c-b2d0-709278a6f9db \
  -H "Authorization: Bearer $TOKEN"

API 會傳回您指定的應用程式設定檔。舉例來說,weatherapp 的應用程式設定檔具有下列 JSON 表示法:

{
  "accessType" : "read",
  "apiProducts" : [ ],
  "appFamily" : "default",
  "appId" : "da496fae-2a04-4a5c-b2d0-70928a6f9db",
  "attributes" : [ ],
  "callbackUrl" : "http://weatherapp.com",
  "createdAt" : 1380290158713,
  "createdBy" : "noreply_admin@apigee.com",
  "credentials" : [ {
    "apiProducts" : [ {
      "apiproduct" : "PremiumWeatherAPI",
      "status" : "approved"
    } ],
    "attributes" : [ ],
    "consumerKey" : "bBGAQrXgivA9lKu7NMPyYpVKNhGar6K",
    "consumerSecret" : "hAr4Gn0gA9vyvI4",
    "expiresAt" : -1,
    "issuedAt" : 1380290161417,
    "scopes" : [ ],
    "status" : "approved"
  } ],
  "developerId" : "5w95xGkpnjzDBT4",
  "lastModifiedAt" : 1380290158713,
  "lastModifiedBy" : "noreply_admin@apigee.com",
  "name" : "weatherapp",
  "scopes" : [ ],
  "status" : "approved"
}

請記下 consumerKeyconsumerSecret 的值。