Geet Pithadia
Geet Pithadia

Reputation: 13

Authorizing REST API calls to GCP

I am totally new to GCP products. I am trying to create and manage the resources i.e. Virtual Machines using the REST API's provided in the documentation. One of the endpoints which I am trying is

GET https://compute.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances?key={API_KEY}

Though to make authorized calls to the platform I need to configure the OAuth 2.0 authentication for which I created the relevant service account. I am not sure how to further use it to authorize the requests. Any leads on this would be greatly helpful. Thanks!

Edit: I intend to call the REST APIs from Python. Not sure if that's the right way.

Upvotes: 0

Views: 500

Answers (1)

Geet Pithadia
Geet Pithadia

Reputation: 13

I was finally able to authorize the API calls to GCP by creating JWT, serializing it to UTF-8 representation (UTF-8 is important), signing it using the google client library google.auth and finally making a request to https://oauth2.googleapis.com/token having passed POST parameters grant_type = urn:ietf:params:oauth:grant-type:jwt-bearer and assertion whose value is the signed jwt for the token using the signed JWT token.

Reference: https://developers.google.com/identity/protocols/oauth2

Upvotes: 1

Related Questions