Skip to main content

Shell Authentication 1.0.1

This API enables an application to authenticate with a time-sensitive access token as part of the OAuth Authorisation flow.

取得此 API 的狀態變更、維護及版本更新。

Shell 驗證快速入門

簡介

Shell 驗證 API 可讓合作夥伴應用程式透過 OAuth 2.0 客戶端憑證流程,向 API Gateway 進行驗證。 此 API 提供具有時效性的存取憑證,用以授權對 Shell API 的請求,確保您的應用程式與 Shell 服務之間的安全通訊。

優勢 說明
安全存取 採用 OAuth 2.0 標準並提供限時存取憑證
簡易整合 單一端點用於產生存取憑證
靈活的環境 同時支援測試與生產環境

驗證

遷移說明

此 API 同時提供 OAuth 存取憑證端點的 v1 與 v2 版本。 第 1 版已停用,並將於下一次變更週期中移除。新整合應使用 v2,現有使用者應盡快遷移至 v2。 主要差異在於回應格式:v2 使用標準 OAuth 欄位名稱(expires_in 取代 expires_in(seconds),以及 Bearer 取代 BearerToken)。

授權流程

  1. 申請客戶端 ID 與密鑰

請聯絡 Shell API 團隊以申請 OAuth 驗證權限。Shell API 團隊將提供客戶端 ID 與密鑰。

  1. 申請 Bearer 憑證

取得憑證後,請使用您的憑證向 Shell 驗證 API 的 OAuth 憑證端點 發出請求,並附上您的憑證。

請求範例:

curl --location --request POST 'https://api-test.shell.com/v2/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=**************' \
--data-urlencode 'client_secret=**************' \
--data-urlencode 'grant_type=client_credentials'

您將在回應中收到一個 Bearer 憑證:

{
   "access_token": "**************",
   "expires_in": "899",
   "token_type": "Bearer"
}

注意:Bearer 憑證的過期時間以秒為單位。

  1. 授權 API 請求

呼叫 Shell API 時,請在請求的標頭中包含以下內容。

Authorization: Bearer access_token

基礎 URL

環境 URL
測試 https://api-test.shell.com
生產環境 https://api.shell.com

核心整合

1. 產生 OAuth 存取憑證

說明: 使用您的客戶端憑證請求 OAuth 存取憑證。API 會傳回一個有效期有限的 Bearer 憑證,此憑證必須包含在所有後續 API 請求的 Authorization 標頭中。基於安全考量,採用 POST 方法取代 GET 方法,以防止快取。

路徑: POST /v2/oauth/token

請求範例

curl --location --request POST 'https://api-test.shell.com/v2/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=twuwywTYUHAH6AHHJ' \
--data-urlencode 'client_secret=yuahaYThdvdowoUUU7wjsjMM' \
--data-urlencode 'grant_type=client_credentials'

請求參數

參數 類型 必填 說明
client_id 字串 由 Shell 提供的客戶端 ID
client_secret 字串 由 Shell 提供的客戶端密鑰
grant_type 字串 存取授權類型值(請使用 "client_credentials")

回應範例

{
  "access_token": "NiE3gzPNVFpwYYMyyWu6mGFYtKN5",
  "expires_in": "899",
  "token_type": "Bearer"
}

回應參數

參數 類型 說明
access_token 字串 用於 API 請求的生成存取憑證
expires_in 字串 到期時間(以秒為單位)
token_type 字串 憑證類型 (Bearer)

錯誤處理

此 API 使用標準的 HTTP 狀態碼。若發生錯誤,回應正文中將提供進一步的詳細資訊。

錯誤代碼 說明 解決方案
400 請求無效 - 請求包含語法錯誤或無法處理 請確認已包含所有必填參數且格式正確
401 無效的 Client ID - 缺少授權標頭或憑證無效 請確認您的 client_id 和 client_secret 是否正確且編碼無誤
403 禁止存取 - 客戶端無存取權限 請聯絡 Shell API 團隊以驗證您的存取權限
404 未找到 - 無法識別所請求 URL 的代理伺服器 請確認端點 URL 是否符合您的環境
405 方法不允許 - 此資源不支援該 HTTP 方法 請確保您對 token 端點使用 POST 方法
500 內部伺服器錯誤 - 伺服器端執行失敗 請重新嘗試此請求;若問題持續,請聯絡 Shell 技術支援

關於我們

殼牌開發者入口網站協助合作夥伴接入殼牌 API,並將構想轉化為可投入生產的解決方案。

殼牌標誌

聯絡人

登入您的帳戶

向 AI 助理諮詢有關 Shell API 及 API 產品的資訊