API Authorization
簡介
FedEx 應用程式開發介面 (API) 支援 OAuth 2.0 (持有人權杖) 驗證方法,以使用 FedEx 資源授權您的應用程式 API 要求。此 OAuth 存取權杖需要每 60 分鐘重新產生一次,並隨每個應用程式開發介面 (API) 交易一起提供,以驗證並授權您對 FedEx 資源的存取。
授權應用程式開發介面 (API) 詳細資料
此 API 讓您可以授權 API 請求,而且必須藉此驗證 FedEx 資源。下節說明 API 的先決條件:
當您註冊 FedEx Developer Portal時,FedEx 會提供一組用戶端識別碼 (API 金鑰) 和用戶端密碼 (秘密金鑰) 組合,以驗證與您專案相關聯的 API 請求。您組織中的每個專案都會與一組用戶端識別碼和用戶端密碼相關聯,稱作 API 認證。
備註:客戶 (內部、兼容、專屬主客戶和子客戶,以及整合者) 可以聯絡 FedEx 業務代表以取得應用程式開發介面 (API) 金鑰和祕密金鑰。
為提供多一層安全保護,FedEx® 客戶 (內部、兼容、專屬主客戶和子客戶,以及整合者) 除了能夠傳送應用程式開發介面 (API) 金鑰和祕密金鑰,也可以傳送子金鑰 (客戶祕密金鑰) 和子密碼 (客戶密碼),以建立 OAuth 權杖。此權杖會用於每一個應用程式開發介面 (API) 要求中以進行驗證。
您可以從 FedEx Developer Portal上的「專案」頁面,重新建立忘記的秘密金鑰。
備註:建立新金鑰會導致您應用程式中的代碼變更。
本文件的重要資訊:
- 用戶端金鑰作為 API 金鑰
- 用戶端密碼作為秘密金鑰
- 子金鑰作為客戶金鑰
- 子密碼作為客戶密碼
API 認證用於下列用途:
- 識別呼叫應用程式開發介面 (API) 的專案。
- 授權存取在專案下啟用的應用程式開發介面 (API)。
取得應用程式開發介面 (API) 認證
認證是根據 FedEx Developer Portal 中輸入的內容來建立:
- 客戶端 ID – 在 FedEx Developer Portal 上建立專案時即建立應用程式開發介面 (API) 金鑰 (客戶端ID)。您也可以在「專案總覽」頁面中檢視與專案相關聯的應用程式開發介面 (API) 金鑰。
- 客戶端密碼 – 在 FedEx Developer Portal 上建立專案後,即可在確認頁面查看祕密金鑰 (客戶端密碼)。如有需要,您也可以在「專案總覽」頁面中重新產生祕密金鑰。
注意:FedEx® 客戶 (內部、兼容、專屬主客戶和子客戶,以及整合者) 除了傳送應用程式開發介面 (API) 金鑰和祕密金鑰,也需要傳送子金鑰 (客戶祕密金鑰) 和子密碼 (客戶密碼),以建立 OAuth 權杖。請參閱認證註冊應用程式開發介面 (API),瞭解如何取得子金鑰和子密碼。
授權應用程式開發介面 (API) 的運作方式
應用程式開發介面 (API) 授權
在 FedEx Developer Portal 取得應用程式開發介面 (API) 認證後,請使用 OAuth 端點取得存取權杖,並將其當作所有 API 交易的認證。
以下項目與 OAuth 要求相關聯,必須輸入:
- grant_type – 客戶類型 (有效值:client_credentials、csp_credentials、client_pc_credentials)。
- client_id – 即專案 API 金鑰。
- client_secret – 即專案 API 秘密金鑰。
若為 FedEx® 內部、兼容、專屬主客戶和子客戶,以及整合者客戶,則需要傳送以下的額外輸入內容:
- child_id – 透過認證註冊 API 請求傳回的客戶金鑰。
- child_secret – 透過認證註冊 API 請求傳回的客戶密碼。
此請求應傳回以下結果:
- access_token – 需用於 API 交易的加密 OAuth 權杖。
- token_type – 權杖類型。在此情況下,即是持有人驗證。
- expires_in – 此為權杖過期時間,以毫秒為單位。標準權杖過期時間為一小時。
- Scope – 提供給客戶的授權範圍。
範例
請求:
POST /oauth/token HTTP/1.1
grant_type= client_credentials&client_id=your client ID&client_secret=Your secret
回應:
{ ″access_token″: ″eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……..″,
″token_type″: ″bearer″,
″expires_in″: 3600,
″scope″: ″CXS″
}
FedEx® 內部、兼容或整合者客戶請求:
POST /oauth/token HTTP/1.1
grant_type= csp_credentials&client_id=Client ID&client_secret= Client secret&child_key=Child key&child_secret=Child Secret
回應:
{ ″access_token″: ″eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……..″,
″token_type″: ″bearer″,
″expires_in″: 3600,
″scope″: ″CXS″
}
FedEx® 專屬主客戶和子客戶的要求:
POST /oauth/token HTTP/1.1
grant_type= client_pc_credentials&client_id=Client ID&client_secret= Client secret&child_key=Child key&child_secret=Child Secret
回應:
{ ″access_token″: ″eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……..″,
″token_type″: ″bearer″,
″expires_in″: 3600,
″scope″: ″CXS″
}
備註:存取權杖將在一小時後過期,透過對 OAuth/權杖端點提出 POST 要求,可以重新產生存取權杖。
API Authorization (1.0)
API Authorization
Use this endpoint to request the OAuth token (bearer token) to authorize your application to access FedEx resources. You can pass this bearer token in your subsequent individual FedEx API endpoint requests.
Note: FedEx APIs do not support Cross-Origin Resource Sharing (CORS) mechanism.
header Parameters
content-type required | string Example: application/x-www-form-urlencoded This is used to indicate the media type of the resource. The media type is a string sent along with the file indicating format of the file. |
Request Body schema: application/x-www-form-urlencoded
grant_type required | string Specify Type of customer requesting the Oauth token. |
client_id required | string Specify the Client ID also known as API Key received during FedEx Developer portal registration. |
client_secret required | string Specify the Client secret also known as Secret Key received during FedEx Developer portal registration. |
child_Key | string Specify the Client ID also known as Customer Key. This element is used as a login credential for an Integrator customer, Compatible customer or a Proprietary Parent Child customer to access the application on behalf of their customer. |
child_secret | string Specify the Client secret also known as Customer Secret. This element is used as a login credential for an Integrator customer, Compatible customer or a Proprietary Parent Child customer to access the application on behalf of their customer. |
Responses
Success
Unauthorized
Failure
Service Unavailable
Sandbox Server
Production Server
Request samples
- Payload
- C#
- JAVA
- JAVASCRIPT
- PHP
- PYTHON
- RUST
- SWIFT
grant_type=client_credentials&client_id=Your_client_ID&client_secret=Your_secret
Response samples
- 200
- 401
- 500
- 503
- "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……",
- "token_type": "bearer",
- "expires_in": 3600,
- "scope": "CXS"
Response