Skip to content

Instantly share code, notes, and snippets.

@erikeldridge
Last active February 12, 2018 22:56
Show Gist options
  • Save erikeldridge/62ed08f70db05d6764d7da1bd3081ab2 to your computer and use it in GitHub Desktop.
Save erikeldridge/62ed08f70db05d6764d7da1bd3081ab2 to your computer and use it in GitHub Desktop.
Utils for working with GCloud service accounts

Setup

  1. Install and activate virtualenv (to avoid conflicts)
  2. Install google-oauth2l

Generate token

  1. Create a service account: https://console.cloud.google.com/iam-admin/serviceaccounts/project

  2. Download the private key, eg my-project-123asd.json

  3. Fetch token:

     $ oauth2l fetch --json ~/Downloads/my-project-123asd.json <scope>
    

Use token

    $ curl -H "authorization: bearer <token>" https://<service>.googleapis.com

Or

    $ curl https://<service>.googleapis.com?access_token=<token>

Inspect token

    $ curl https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=<token>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment