Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Te recomendamos que utilices una cuenta de servicio para la autenticación cuando integres la API del portal del sistema de acceso al espectro (SAS) de Google.
Configurar una cuenta de servicio
Para usar una cuenta de servicio en la autenticación, sigue estos pasos:
Debes proporcionar la autenticación de tu cuenta de servicio como token de portador. Si llamas directamente a la API del portal de SAS, por ejemplo, al hacer una solicitud HTTP con curl, debes enviar tu autenticación como token de portador en el encabezado Authorization.
Para obtener un token de portador con tu cuenta de servicio, sigue estos pasos:
Sustituye ${KEY_FILE} por la ruta al archivo de clave de tu cuenta de servicio.
Usa tu cuenta de servicio para obtener un token de autorización:
gcloud auth print-access-token
El comando devuelve un valor de token de acceso.
Cuando uses la API, envía el valor del token como token de portador en un encabezado Authorization. En el siguiente código de ejemplo se muestra cómo transferir el valor del token como token de portador:
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-10 (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)."]]