Anda harus memberikan autentikasi akun layanan sebagai token pembawa. Jika
memanggil SAS Portal API secara langsung, misalnya dengan membuat permintaan
HTTP dengan curl, Anda akan meneruskan autentikasi sebagai token pembawa di
header Authorization.
Untuk mendapatkan token pembawa dengan akun layanan Anda, ikuti langkah-langkah berikut:
Ganti ${KEY_FILE} dengan jalur ke file kunci akun layanan Anda.
Gunakan akun layanan Anda untuk mendapatkan token otorisasi:
gcloud auth print-access-token
Perintah ini menampilkan nilai token akses.
Saat Anda menggunakan API, teruskan nilai token sebagai token pembawa di header Authorization. Contoh kode berikut menunjukkan cara meneruskan nilai token sebagai token pembawa:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]