Você precisa fornecer a autenticação da conta de serviço como um token do portador. Se
você chamar a API SAS Portal diretamente, por exemplo, com uma solicitação
HTTP com curl, a autenticação será transmitida como um token do portador no
cabeçalho Authorization.
Para receber um token do portador com sua conta de serviço, siga estas etapas:
Substitua ${KEY_FILE} pelo caminho para o arquivo de chave da conta de serviço.
Use sua conta de serviço para receber um token de autorização:
gcloud auth print-access-token
O comando retorna um valor de token de acesso.
Ao usar a API, transmita o valor do token como um token do portador em um
cabeçalho Authorization. O exemplo de código abaixo mostra como transmitir o valor do token
como um token de portador:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],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)."]]