Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Authorization token is required for Google Cloud Storage JSON API?

I am learning Google Cloud Storage, the JSON api, simple upload:

https://cloud.google.com/storage/docs/json_api/v1/how-tos/simple-upload

The example says to send a post looking like this:

POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=media&name=myObject HTTP/1.1
Content-Type: image/jpeg
Content-Length: [NUMBER_OF_BYTES_IN_FILE]
Authorization: Bearer [YOUR_AUTH_TOKEN]

[JPEG_DATA]

And then I created a "Service accounts" API.

But how do I figure out the [YOUR_AUTH_TOKEN] to use from my newly created Service account?

like image 636
corgrath Avatar asked Jan 14 '17 08:01

corgrath


People also ask

How do I authenticate with Google Cloud Storage?

API authenticationIn the OAuth 2.0 Playground, click Cloud Storage API v1, and then select an access level for your application ( full_control , read_only , or read_write ). Click Authorize APIs. Sign in to your Google account when prompted. In the dialogue that appears, click Allow.

How do I authenticate Google Cloud API?

With a user account, you can authenticate to Google APIs and services in the following ways: Use the gcloud CLI to set up Application Default Credentials (ADC). Use the gcloud CLI to generate access tokens. Use your user credentials to impersonate a service account.

How do I get access token for Google REST API?

Obtain an access token manually You will need to create a JSON Web Token (JWT) and sign it with the private key, then construct an access token request in the appropriate format. After that, your application sends the token request to the Google OAuth 2.0 Authorization Server and an access token gets returned.


1 Answers

Google Cloud uses OAuth 2.0 to handle authentication. There are a variety of techniques for generating a token depending on your needs. If you're writing a program using one of Google's client libraries, the details are mostly taken care of for you. Google has a lengthy guide on the nitty-gritty: https://developers.google.com/identity/protocols/OAuth2

You are looking to authenticate as a service account. Service accounts generally authenticate by creating a token request document called a JWT, signing it with a private key associated with the service account, then exchanging the JWT with Google for a token. This process is described over here: https://developers.google.com/identity/protocols/OAuth2#serviceaccount

From your desktop, if you want to auth as a service account, one easy way is to use gcloud to authenticate as a service account and then ask it for a token:

$> gcloud auth activate-service-account [email protected] --key-file=creds.json
$> gcloud auth print-access-token
like image 92
Brandon Yarbrough Avatar answered Sep 20 '22 16:09

Brandon Yarbrough