node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



This is a auth api wrapper (we use gapitoken module) and add a request method for api call. It use service account for authenticate, and persistance the key in cache and file.

We still not implement the refresh token, will be implement next release.


npm install google-api-utility

Apply service account

Follow the doc:

Convert p12 key

From admin console, create a service account, save the client_secrets.json and it's key ex: Translate p12 to pem

openssl pkcs12 -in privatekey.p12 -out privatekey.pem -nocerts
openssl rsa -in privatekey.pem -out key.pem
openssl pkcs12 -in privatekey.p12 -nodes -nocerts > key.pem

Use for Google API request

You need to initial with auth.init() to put the scope, client_secret, privatekey_pem, key_pem parameters. These are we describe before. And we must to specify the scope for our query api, too.

var auth = require('google-api-utility')
  , request = auth.request
  , util = require('util')
  , project = 'your-project-id';
  scope: '',
  client_secret: '/path-to-client_secret.json',
  key_pem: '/path-to-key.pem'
var bqurl = '';
    url: util.format(bqurl, project),
    method: 'GET'
}, function(err, req, doc){
  if(err) console.log(err);

About 2015Q1 end, google start to deprecate the client_secret file download. You can change the init method like this:

  scope: '',
  client_email: '',
  key_pem: '/path-to-key.pem'

The client_email can be find in project credential page. (Page url like:[YOUR-PROJECT-ID]/apiui/credential)

Now support json secret file setting

Because GCP currently have json secret file. We currently support to initial it using json file:

  scope: '',
  json_file: '/path/to/your-file.json'

Request timeout setting

Use timeout parameter in init function, and will be set in request timeout.

  timeout: 1000


The module bellow are my implements use this lib.