[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-01。"],[],[],null,["# Set up authorization and authentication\n\nWe recommend that you use a service account for authentication when you\nintegrate with the Google Spectrum Access System (SAS) Portal API.\n\nSet up a service account\n------------------------\n\nTo use a service account for authentication, complete the following steps:\n\n1. [Create a service account](/iam/docs/creating-managing-service-accounts#creating_a_service_account).\n2. [Create your service account key](/iam/docs/creating-managing-service-account-keys#creating_service_account_keys)\n and select **JSON** as your key type.\n\n After you complete this step, your service account key is downloaded to your browser's default location.\n3. [Grant the **Project Owner** role](/iam/docs/granting-changing-revoking-access) to the service account.\n\nObtain a bearer token\n---------------------\n\nYou need to provide your service account authentication as a bearer token. If\nyou call the SAS Portal API directly, such as by making an HTTP\nrequest with `curl`, you pass your authentication as a bearer token in the\n`Authorization` header.\n\nTo obtain a bearer token with your service account, follow these steps:\n\n1. [Install the Google Cloud CLI](/sdk/install).\n\n2. In the gcloud CLI, authenticate to your service account:\n\n ```\n gcloud auth activate-service-account --key-file ${KEY_FILE}\n ```\n\n Replace \u003cvar translate=\"no\"\u003e${KEY_FILE}\u003c/var\u003e with the path to your service account key file.\n3. Use your service account to obtain an authorization token:\n\n ```\n gcloud auth print-access-token\n ```\n\n The command returns an access token value.\n4. When you use the API, pass the token value as a bearer token in an\n `Authorization` header. The following code sample shows how to pass the token\n value as a bearer token:\n\n ```\n curl -X GET -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer ${TOKEN}\" \\\n \"https://sasportal.googleapis.com/v1alpha1/customers\"\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003e${CLIENT_PROJECT}\u003c/var\u003e: the [ID of the Google Cloud project](/resource-manager/docs/creating-managing-projects) from which you make the requests\n - \u003cvar translate=\"no\"\u003e${TOKEN}\u003c/var\u003e: the authorization token\n\nWhat's next\n-----------\n\n- To get an overview of the SAS Portal API, see [Google SAS Portal API overview](/spectrum-access-system/docs/overview-api).\n- For information about each API, see the [Customers](/spectrum-access-system/docs/customers-api) and [Device Manager](/spectrum-access-system/docs/device-manager-api) API pages.\n- For examples of how to use the API, see [API code samples](/spectrum-access-system/docs/samples).\n- For reference documentation, see [APIs and reference](/spectrum-access-system/docs/apis)."]]