Comparing version 2.0.2 to 2.1.0
export interface TokenOptions { | ||
keyFile?: string; | ||
key?: string | undefined; | ||
email?: string | undefined; | ||
key?: string; | ||
email?: string; | ||
iss?: string; | ||
sub?: string; | ||
scope?: string | string[]; | ||
additionalClaims?: {}; | ||
} | ||
@@ -12,10 +13,11 @@ export declare class GoogleToken { | ||
expiresAt: number | null; | ||
key: string | undefined; | ||
keyFile: string | undefined; | ||
iss: string | undefined; | ||
sub: string; | ||
scope: string | undefined; | ||
key?: string; | ||
keyFile?: string; | ||
iss?: string; | ||
sub?: string; | ||
scope?: string; | ||
rawToken: string | null; | ||
tokenExpires: number | null; | ||
email: string; | ||
additionalClaims?: {}; | ||
/** | ||
@@ -57,6 +59,4 @@ * Create a GoogleToken. | ||
* Request the token from Google. | ||
* | ||
* @param {Function} callback The callback function. | ||
*/ | ||
private requestToken(); | ||
} |
@@ -56,3 +56,3 @@ "use strict"; | ||
var readFile = pify(fs.readFile); | ||
var GOOGLE_TOKEN_URL = 'https://accounts.google.com/o/oauth2/token'; | ||
var GOOGLE_TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'; | ||
var GOOGLE_REVOKE_TOKEN_URL = 'https://accounts.google.com/o/oauth2/revoke?token='; | ||
@@ -180,3 +180,4 @@ var ErrorWithCode = /** @class */ (function (_super) { | ||
keyFile: _this.keyFile, | ||
scope: _this.scope | ||
scope: _this.scope, | ||
additionalClaims: _this.additionalClaims, | ||
}); | ||
@@ -197,5 +198,4 @@ })]; | ||
this.iss = options.email || options.iss; | ||
if (options.sub) { | ||
this.sub = options.sub; | ||
} | ||
this.sub = options.sub; | ||
this.additionalClaims = options.additionalClaims; | ||
if (typeof options.scope === 'object') { | ||
@@ -210,4 +210,2 @@ this.scope = options.scope.join(' '); | ||
* Request the token from Google. | ||
* | ||
* @param {Function} callback The callback function. | ||
*/ | ||
@@ -217,6 +215,7 @@ GoogleToken.prototype.requestToken = function () { | ||
var _this = this; | ||
var iat, payload, toSign, signedJWT; | ||
var iat, additionalClaims, payload, signedJWT; | ||
return __generator(this, function (_a) { | ||
iat = Math.floor(new Date().getTime() / 1000); | ||
payload = { | ||
additionalClaims = this.additionalClaims || {}; | ||
payload = Object.assign({ | ||
iss: this.iss, | ||
@@ -227,12 +226,5 @@ scope: this.scope, | ||
iat: iat, | ||
}; | ||
if (this.sub) { | ||
payload.sub = this.sub; | ||
} | ||
toSign = { | ||
header: { alg: 'RS256' }, | ||
payload: payload, | ||
secret: this.key | ||
}; | ||
signedJWT = jws.sign(toSign); | ||
sub: this.sub | ||
}, additionalClaims); | ||
signedJWT = jws.sign({ header: { alg: 'RS256' }, payload: payload, secret: this.key }); | ||
return [2 /*return*/, axios_1.default({ | ||
@@ -239,0 +231,0 @@ method: 'post', |
{ | ||
"name": "gtoken", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Node.js Google Authentication Service Account Tokens", | ||
@@ -20,3 +20,4 @@ "main": "./build/src/index.js", | ||
"pretest": "npm run compile", | ||
"posttest": "npm run check" | ||
"posttest": "npm run check && npm run license-check", | ||
"license-check": "jsgl --local ." | ||
}, | ||
@@ -47,8 +48,9 @@ "keywords": [ | ||
"@types/mocha": "^2.2.43", | ||
"@types/nock": "^8.2.1", | ||
"@types/node": "^8.0.47", | ||
"@types/nock": "^9.1.0", | ||
"@types/node": "^9.3.0", | ||
"@types/pify": "^3.0.0", | ||
"codecov": "^3.0.0", | ||
"gts": "^0.5.1", | ||
"mocha": "^4.0.1", | ||
"mocha": "^5.0.0", | ||
"js-green-licenses": "^0.4.0", | ||
"nock": "^9.0.27", | ||
@@ -64,3 +66,8 @@ "nyc": "^11.2.1", | ||
"README.md" | ||
] | ||
], | ||
"nyc": { | ||
"exclude": [ | ||
"build/test" | ||
] | ||
} | ||
} |
# node-gtoken | ||
[![NPM Version][npm-image]][npm-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![CircleCI][circle-image]][circle-url] | ||
[![Dependency Status][david-image]][david-url] | ||
@@ -25,3 +25,3 @@ [![devDependency Status][david-dev-image]][david-dev-url] | ||
``` js | ||
const GoogleToken = require('gtoken'); | ||
const { GoogleToken } = require('gtoken'); | ||
const gtoken = new GoogleToken({ | ||
@@ -62,3 +62,3 @@ keyFile: 'path/to/key.pem', // or path to .p12 key file | ||
``` js | ||
const GoogleToken = require('gtoken'); | ||
const { GoogleToken } = require('gtoken'); | ||
const gtoken = new GoogleToken({ | ||
@@ -82,3 +82,3 @@ keyFile: 'path/to/key.json', | ||
const key = '-----BEGIN RSA PRIVATE KEY-----\nXXXXXXXXXXX...'; | ||
const GoogleToken = require('gtoken'); | ||
const { GoogleToken } = require('gtoken'); | ||
const gtoken = new GoogleToken({ | ||
@@ -179,2 +179,4 @@ email: 'my_service_account_email@developer.gserviceaccount.com', | ||
[circle-image]: https://circleci.com/gh/google/node-gtoken.svg?style=svg | ||
[circle-url]: https://circleci.com/gh/google/node-gtoken | ||
[codecov-image]: https://codecov.io/gh/google/node-gtoken/branch/master/graph/badge.svg | ||
@@ -195,3 +197,1 @@ [codecov-url]: https://codecov.io/gh/google/node-gtoken | ||
[snyk-url]: https://snyk.io/test/github/google/node-gtoken | ||
[travis-image]: https://travis-ci.org/google/node-gtoken.svg?branch=master | ||
[travis-url]: https://travis-ci.org/google/node-gtoken |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
27039
14
316