Solar API 支援使用 OAuth 2.0 進行驗證。
Google 支援常見的 OAuth 2.0 使用情境,例如網路伺服器適用的使用情境。
本文件說明如何將 OAuth 權杖傳遞至在
dev 環境。如需在
環境,請參閱
Google 的驗證。
事前準備
開始使用 Solar API 前,您需要具備
專案連結,而且已啟用 Solar API。建議您建立多個
專案擁有者和帳單管理員,因此您隨時都有擔任這些角色的成員
專屬於您的團隊請參閱這篇文章,進一步瞭解如何在 Cloud 控制台中完成相關設定。
關於 OAuth
根據部署作業使用 OAuth 建立及管理存取權杖的方法有很多種
環境。
舉例來說,Google OAuth 2.0 系統支援伺服器對伺服器之間的互動,例如
應用程式與 Google 服務之間的連線您需要具備服務帳戶
是應用程式擁有的帳戶,而非個別使用者的帳戶。您的
應用程式會代表服務帳戶呼叫 Google API,因此使用者並未直接參與。
如要進一步瞭解驗證方法,請參閱:
Google 的驗證。
此外,你也可以在 Android 或 iOS 行動應用程式中使用 Solar API。
如需搭配使用 OAuth 與 Solar API 的一般資訊,包括有關管理方式的資訊
取得不同部署環境的存取權杖,請參閱
使用 OAuth 2.0 存取 Google API。
關於 OAuth 範圍
如要搭配 Solar API 使用 OAuth,您必須將 OAuth 權杖指派給範圍:
https://www.googleapis.com/auth/cloud-platform
範例:在本機開發環境中試用 REST API 呼叫
如果想使用 OAuth 權杖試用 Solar API,但沒有設定環境
以產生符記,您可以按照本節的程序發出呼叫。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-08-21 (世界標準時間)。"],[[["The Solar API utilizes OAuth 2.0 for authentication, and this guide focuses on its implementation in development environments using Application Default Credentials (ADC)."],["To get started, you'll need a Google Cloud project with billing enabled and the Solar API activated, along with the gcloud CLI installed and initialized."],["For local development, generate an OAuth token using `gcloud auth application-default print-access-token` and include it in the `Authorization` header of your API requests."],["Ensure your requests also include the `X-Goog-User-Project` header containing your project ID or number for billing purposes."],["Remember, the method described here is intended for development and testing; refer to Google Cloud's authentication documentation for production environments."]]],["The Solar API utilizes OAuth 2.0 for authentication, supporting various scenarios like server-to-server interactions with service accounts. To use OAuth with the Solar API, the token requires the `https://www.googleapis.com/auth/cloud-platform` scope. In a development environment, the Application Default Credentials (ADC) can provide a temporary OAuth token via the `gcloud auth application-default login` command. Then, make a REST call to the API passing the generated token in the `Authorization` header and the project ID in the `X-Goog-User-Project` header.\n"]]