Updating NPM dependencies
This commit is contained in:
103
node_modules/google-auth-library/build/src/auth/jwtclient.js
generated
vendored
103
node_modules/google-auth-library/build/src/auth/jwtclient.js
generated
vendored
@@ -1,22 +1,20 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2013 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JWT = void 0;
|
||||
const gtoken_1 = require("gtoken");
|
||||
const messages = require("../messages");
|
||||
const jwtaccess_1 = require("./jwtaccess");
|
||||
const oauth2client_1 = require("./oauth2client");
|
||||
class JWT extends oauth2client_1.OAuth2Client {
|
||||
@@ -59,49 +57,75 @@ class JWT extends oauth2client_1.OAuth2Client {
|
||||
* @param url the URI being authorized.
|
||||
*/
|
||||
async getRequestMetadataAsync(url) {
|
||||
if (!this.apiKey && !this.hasScopes() && url) {
|
||||
if (!this.apiKey && !this.hasUserScopes() && url) {
|
||||
if (this.additionalClaims &&
|
||||
this.additionalClaims.target_audience) {
|
||||
const { tokens } = await this.refreshToken();
|
||||
return { headers: { Authorization: `Bearer ${tokens.id_token}` } };
|
||||
return {
|
||||
headers: this.addSharedMetadataHeaders({
|
||||
Authorization: `Bearer ${tokens.id_token}`,
|
||||
}),
|
||||
};
|
||||
}
|
||||
else {
|
||||
// no scopes have been set, but a uri has been provided. Use JWTAccess
|
||||
// credentials.
|
||||
if (!this.access) {
|
||||
this.access = new jwtaccess_1.JWTAccess(this.email, this.key, this.keyId);
|
||||
this.access = new jwtaccess_1.JWTAccess(this.email, this.key, this.keyId, this.eagerRefreshThresholdMillis);
|
||||
}
|
||||
const headers = await this.access.getRequestHeaders(url, this.additionalClaims);
|
||||
return { headers };
|
||||
return { headers: this.addSharedMetadataHeaders(headers) };
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (this.hasAnyScopes() || this.apiKey) {
|
||||
return super.getRequestMetadataAsync(url);
|
||||
}
|
||||
else {
|
||||
// If no audience, apiKey, or scopes are provided, we should not attempt
|
||||
// to populate any headers:
|
||||
return { headers: {} };
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Indicates whether the credential requires scopes to be created by calling
|
||||
* createScoped before use.
|
||||
* @deprecated
|
||||
* @return false if createScoped does not need to be called.
|
||||
* Fetches an ID token.
|
||||
* @param targetAudience the audience for the fetched ID token.
|
||||
*/
|
||||
createScopedRequired() {
|
||||
messages.warn(messages.JWT_CREATE_SCOPED_DEPRECATED);
|
||||
return !this.hasScopes();
|
||||
async fetchIdToken(targetAudience) {
|
||||
// Create a new gToken for fetching an ID token
|
||||
const gtoken = new gtoken_1.GoogleToken({
|
||||
iss: this.email,
|
||||
sub: this.subject,
|
||||
scope: this.scopes || this.defaultScopes,
|
||||
keyFile: this.keyFile,
|
||||
key: this.key,
|
||||
additionalClaims: { target_audience: targetAudience },
|
||||
});
|
||||
await gtoken.getToken({
|
||||
forceRefresh: true,
|
||||
});
|
||||
if (!gtoken.idToken) {
|
||||
throw new Error('Unknown error: Failed to fetch ID token');
|
||||
}
|
||||
return gtoken.idToken;
|
||||
}
|
||||
/**
|
||||
* Determine if there are currently scopes available.
|
||||
*/
|
||||
hasScopes() {
|
||||
hasUserScopes() {
|
||||
if (!this.scopes) {
|
||||
return false;
|
||||
}
|
||||
// For arrays, check the array length.
|
||||
if (this.scopes instanceof Array) {
|
||||
return this.scopes.length > 0;
|
||||
}
|
||||
// For others, convert to a string and check the length.
|
||||
return String(this.scopes).length > 0;
|
||||
return this.scopes.length > 0;
|
||||
}
|
||||
/**
|
||||
* Are there any default or user scopes defined.
|
||||
*/
|
||||
hasAnyScopes() {
|
||||
if (this.scopes && this.scopes.length > 0)
|
||||
return true;
|
||||
if (this.defaultScopes && this.defaultScopes.length > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
authorize(callback) {
|
||||
if (callback) {
|
||||
@@ -127,7 +151,9 @@ class JWT extends oauth2client_1.OAuth2Client {
|
||||
* @param refreshToken ignored
|
||||
* @private
|
||||
*/
|
||||
async refreshTokenNoCache(refreshToken) {
|
||||
async refreshTokenNoCache(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
refreshToken) {
|
||||
const gtoken = this.createGToken();
|
||||
const token = await gtoken.getToken({
|
||||
forceRefresh: this.isTokenExpiring(),
|
||||
@@ -149,7 +175,7 @@ class JWT extends oauth2client_1.OAuth2Client {
|
||||
this.gtoken = new gtoken_1.GoogleToken({
|
||||
iss: this.email,
|
||||
sub: this.subject,
|
||||
scope: this.scopes,
|
||||
scope: this.scopes || this.defaultScopes,
|
||||
keyFile: this.keyFile,
|
||||
key: this.key,
|
||||
additionalClaims: this.additionalClaims,
|
||||
@@ -176,10 +202,11 @@ class JWT extends oauth2client_1.OAuth2Client {
|
||||
this.key = json.private_key;
|
||||
this.keyId = json.private_key_id;
|
||||
this.projectId = json.project_id;
|
||||
this.quotaProjectId = json.quota_project_id;
|
||||
}
|
||||
fromStream(inputStream, callback) {
|
||||
if (callback) {
|
||||
this.fromStreamAsync(inputStream).then(r => callback(), callback);
|
||||
this.fromStreamAsync(inputStream).then(() => callback(), callback);
|
||||
}
|
||||
else {
|
||||
return this.fromStreamAsync(inputStream);
|
||||
|
||||
Reference in New Issue
Block a user