Node.js Google Authentication Service Account Tokens
This is a low level utility library used to interact with Google Authentication services. In most cases, you probably want to use the google-auth-library instead.
.pem
or .json
key file:You can also use the async/await style API:
Example :Or use promises:
Example :.json
key file:Various options that can be set when creating initializing the
gtoken
object.
options.email or options.iss
: The service account email address.options.scope
: An array of scope strings or space-delimited string of scopes.options.sub
: The email address of the user requesting delegated access.options.keyFile
: The filename of .json
key or .pem
key.options.key
: The raw RSA private key value, in place of using options.keyFile
.options.additionalClaims
: Additional claims to include in the JWT when requesting a token.options.eagerRefreshThresholdMillis
: How long must a token be valid for in order to return it from the cache. Defaults to 0.Example :Returns the cached tokens or requests a new one and returns it.
Example :Given a keyfile, returns the key and (if available) the client email.
Various properties set on the gtoken object after call to
.getToken()
.
gtoken.idToken
: The OIDC token returned (if any).gtoken.accessToken
: The access token.gtoken.expiresAt
: The expiry date as milliseconds since 1970/01/01gtoken.key
: The raw key value.gtoken.rawToken
: Most recent raw token data received from Google.Example :Returns true if the token has expired, or token does not exist.
Example :Revoke the token if set.
.json
key from Google.json
key and download it into your project..p12
key to a .pem
keyIf you'd like to convert to a .pem
for use later, use OpenSSL if you have it installed.
Don't forget, the passphrase when converting these files is the string 'notasecret'