service-account-token-requestor

1.1.4 • Public • Published

GCP Service Account Token Requestor

Requests an access token from the Google OAuth 2.0 Authorization Server. This probably isn't necessary if using Google Compute Engine or Google App Engine.

Example

First, acquire a Service Account json file. Then provide the path to getToken.

const tokenRequestor = require("service-account-token-requestor");
const path_to_service_account_file = "/home/user/private-keys/service-account.json";
 
//returns a promise if no callback is provided
tokenRequestor.getToken(path_to_service_account_file)
.then(useTheToken);
 
//callback
tokenRequestor.getToken(path_to_service_account_file, (token, error)=>{
  if (error) { return handleError(error); }
  useTheToken(token);
});

Test

Provide path to service account json file in SERVICE_ACCT_FILE environment variable.

SERVICE_ACCT_FILE="../private-keys/service-account.json" npm test

Package Sidebar

Install

npm i service-account-token-requestor

Weekly Downloads

0

Version

1.1.4

License

ISC

Unpacked Size

6.08 kB

Total Files

6

Last publish

Collaborators

  • tejohnso