/
opt
/
canhelp
/
node_modules
/
google-auth-library
/
build
/
src
/
auth
/
/opt/canhelp/node_modules/google-auth-library/build/src/auth
mkdir
upload
Name
Size
Mode
Actions
authclient.d.ts
10764
0644
edit
dl
rm
authclient.js
11247
0644
edit
dl
rm
awsclient.d.ts
5315
0644
edit
dl
rm
awsclient.js
7556
0644
edit
dl
rm
awsrequestsigner.d.ts
1626
0644
edit
dl
rm
awsrequestsigner.js
9442
0644
edit
dl
rm
baseexternalclient.d.ts
13020
0644
edit
dl
rm
baseexternalclient.js
20857
0644
edit
dl
rm
certificatesubjecttokensupplier.d.ts
2202
0644
edit
dl
rm
certificatesubjecttokensupplier.js
10619
0644
edit
dl
rm
computeclient.d.ts
1359
0644
edit
dl
rm
computeclient.js
4497
0644
edit
dl
rm
credentials.d.ts
2359
0644
edit
dl
rm
credentials.js
704
0644
edit
dl
rm
defaultawssecuritycredentialssupplier.d.ts
3795
0644
edit
dl
rm
defaultawssecuritycredentialssupplier.js
9330
0644
edit
dl
rm
downscopedclient.d.ts
6693
0644
edit
dl
rm
downscopedclient.js
12353
0644
edit
dl
rm
envDetect.d.ts
363
0644
edit
dl
rm
envDetect.js
2831
0644
edit
dl
rm
executable-response.d.ts
4489
0644
edit
dl
rm
executable-response.js
7519
0644
edit
dl
rm
externalAccountAuthorizedUserClient.d.ts
3173
0644
edit
dl
rm
externalAccountAuthorizedUserClient.js
10005
0644
edit
dl
rm
externalclient.d.ts
1528
0644
edit
dl
rm
externalclient.js
3048
0644
edit
dl
rm
filesubjecttokensupplier.d.ts
1608
0644
edit
dl
rm
filesubjecttokensupplier.js
3515
0644
edit
dl
rm
googleauth.d.ts
23574
0644
edit
dl
rm
googleauth.js
36374
0644
edit
dl
rm
iam.d.ts
623
0644
edit
dl
rm
iam.js
1373
0644
edit
dl
rm
identitypoolclient.d.ts
5626
0644
edit
dl
rm
identitypoolclient.js
6775
0644
edit
dl
rm
idtokenclient.d.ts
938
0644
edit
dl
rm
idtokenclient.js
2106
0644
edit
dl
rm
impersonated.d.ts
5687
0644
edit
dl
rm
impersonated.js
8654
0644
edit
dl
rm
jwtaccess.d.ts
2336
0644
edit
dl
rm
jwtaccess.js
7213
0644
edit
dl
rm
jwtclient.d.ts
5122
0644
edit
dl
rm
jwtclient.js
11256
0644
edit
dl
rm
loginticket.d.ts
5367
0644
edit
dl
rm
loginticket.js
1795
0644
edit
dl
rm
oauth2client.d.ts
25326
0644
edit
dl
rm
oauth2client.js
33662
0644
edit
dl
rm
oauth2common.d.ts
4094
0644
edit
dl
rm
oauth2common.js
8080
0644
edit
dl
rm
passthrough.d.ts
1097
0644
edit
dl
rm
passthrough.js
1842
0644
edit
dl
rm
pluggable-auth-client.d.ts
5485
0644
edit
dl
rm
pluggable-auth-client.js
10002
0644
edit
dl
rm
pluggable-auth-handler.d.ts
2109
0644
edit
dl
rm
pluggable-auth-handler.js
7260
0644
edit
dl
rm
refreshclient.d.ts
3436
0644
edit
dl
rm
refreshclient.js
6650
0644
edit
dl
rm
stscredentials.d.ts
5261
0644
edit
dl
rm
stscredentials.js
4738
0644
edit
dl
rm
urlsubjecttokensupplier.d.ts
2186
0644
edit
dl
rm
urlsubjecttokensupplier.js
2859
0644
edit
dl
rm
Edit:
/opt/canhelp/node_modules/google-auth-library/build/src/auth/externalAccountAuthorizedUserClient.js
(10005B)
"use strict"; // Copyright 2023 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.ExternalAccountAuthorizedUserClient = exports.EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE = void 0; const authclient_1 = require("./authclient"); const oauth2common_1 = require("./oauth2common"); const gaxios_1 = require("gaxios"); const stream = require("stream"); const baseexternalclient_1 = require("./baseexternalclient"); /** * The credentials JSON file type for external account authorized user clients. */ exports.EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE = 'external_account_authorized_user'; const DEFAULT_TOKEN_URL = 'https://sts.{universeDomain}/v1/oauthtoken'; /** * Handler for token refresh requests sent to the token_url endpoint for external * authorized user credentials. */ class ExternalAccountAuthorizedUserHandler extends oauth2common_1.OAuthClientAuthHandler { #tokenRefreshEndpoint; /** * Initializes an ExternalAccountAuthorizedUserHandler instance. * @param url The URL of the token refresh endpoint. * @param transporter The transporter to use for the refresh request. * @param clientAuthentication The client authentication credentials to use * for the refresh request. */ constructor(options) { super(options); this.#tokenRefreshEndpoint = options.tokenRefreshEndpoint; } /** * Requests a new access token from the token_url endpoint using the provided * refresh token. * @param refreshToken The refresh token to use to generate a new access token. * @param additionalHeaders Optional additional headers to pass along the * request. * @return A promise that resolves with the token refresh response containing * the requested access token and its expiration time. */ async refreshToken(refreshToken, headers) { const opts = { ...ExternalAccountAuthorizedUserHandler.RETRY_CONFIG, url: this.#tokenRefreshEndpoint, method: 'POST', headers, data: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: refreshToken, }), responseType: 'json', }; authclient_1.AuthClient.setMethodName(opts, 'refreshToken'); // Apply OAuth client authentication. this.applyClientAuthenticationOptions(opts); try { const response = await this.transporter.request(opts); // Successful response. const tokenRefreshResponse = response.data; tokenRefreshResponse.res = response; return tokenRefreshResponse; } catch (error) { // Translate error to OAuthError. if (error instanceof gaxios_1.GaxiosError && error.response) { throw (0, oauth2common_1.getErrorFromOAuthErrorResponse)(error.response.data, // Preserve other fields from the original error. error); } // Request could fail before the server responds. throw error; } } } /** * External Account Authorized User Client. This is used for OAuth2 credentials * sourced using external identities through Workforce Identity Federation. * Obtaining the initial access and refresh token can be done through the * Google Cloud CLI. */ class ExternalAccountAuthorizedUserClient extends authclient_1.AuthClient { cachedAccessToken; externalAccountAuthorizedUserHandler; refreshToken; /** * Instantiates an ExternalAccountAuthorizedUserClient instances using the * provided JSON object loaded from a credentials files. * An error is throws if the credential is not valid. * @param options The external account authorized user option object typically * from the external accoutn authorized user JSON credential file. */ constructor(options) { super(options); if (options.universe_domain) { this.universeDomain = options.universe_domain; } this.refreshToken = options.refresh_token; const clientAuthentication = { confidentialClientType: 'basic', clientId: options.client_id, clientSecret: options.client_secret, }; this.externalAccountAuthorizedUserHandler = new ExternalAccountAuthorizedUserHandler({ tokenRefreshEndpoint: options.token_url ?? DEFAULT_TOKEN_URL.replace('{universeDomain}', this.universeDomain), transporter: this.transporter, clientAuthentication, }); this.cachedAccessToken = null; this.quotaProjectId = options.quota_project_id; // As threshold could be zero, // eagerRefreshThresholdMillis || EXPIRATION_TIME_OFFSET will override the // zero value. if (typeof options?.eagerRefreshThresholdMillis !== 'number') { this.eagerRefreshThresholdMillis = baseexternalclient_1.EXPIRATION_TIME_OFFSET; } else { this.eagerRefreshThresholdMillis = options .eagerRefreshThresholdMillis; } this.forceRefreshOnFailure = !!options?.forceRefreshOnFailure; } async getAccessToken() { // If cached access token is unavailable or expired, force refresh. if (!this.cachedAccessToken || this.isExpired(this.cachedAccessToken)) { await this.refreshAccessTokenAsync(); } // Return GCP access token in GetAccessTokenResponse format. return { token: this.cachedAccessToken.access_token, res: this.cachedAccessToken.res, }; } async getRequestHeaders() { const accessTokenResponse = await this.getAccessToken(); const headers = new Headers({ authorization: `Bearer ${accessTokenResponse.token}`, }); return this.addSharedMetadataHeaders(headers); } request(opts, callback) { if (callback) { this.requestAsync(opts).then(r => callback(null, r), e => { return callback(e, e.response); }); } else { return this.requestAsync(opts); } } /** * Authenticates the provided HTTP request, processes it and resolves with the * returned response. * @param opts The HTTP request options. * @param reAuthRetried Whether the current attempt is a retry after a failed attempt due to an auth failure. * @return A promise that resolves with the successful response. */ async requestAsync(opts, reAuthRetried = false) { let response; try { const requestHeaders = await this.getRequestHeaders(); opts.headers = gaxios_1.Gaxios.mergeHeaders(opts.headers); this.addUserProjectAndAuthHeaders(opts.headers, requestHeaders); response = await this.transporter.request(opts); } catch (e) { const res = e.response; if (res) { const statusCode = res.status; // Retry the request for metadata if the following criteria are true: // - We haven't already retried. It only makes sense to retry once. // - The response was a 401 or a 403 // - The request didn't send a readableStream // - forceRefreshOnFailure is true const isReadableStream = res.config.data instanceof stream.Readable; const isAuthErr = statusCode === 401 || statusCode === 403; if (!reAuthRetried && isAuthErr && !isReadableStream && this.forceRefreshOnFailure) { await this.refreshAccessTokenAsync(); return await this.requestAsync(opts, true); } } throw e; } return response; } /** * Forces token refresh, even if unexpired tokens are currently cached. * @return A promise that resolves with the refreshed credential. */ async refreshAccessTokenAsync() { // Refresh the access token using the refresh token. const refreshResponse = await this.externalAccountAuthorizedUserHandler.refreshToken(this.refreshToken); this.cachedAccessToken = { access_token: refreshResponse.access_token, expiry_date: new Date().getTime() + refreshResponse.expires_in * 1000, res: refreshResponse.res, }; if (refreshResponse.refresh_token !== undefined) { this.refreshToken = refreshResponse.refresh_token; } return this.cachedAccessToken; } /** * Returns whether the provided credentials are expired or not. * If there is no expiry time, assumes the token is not expired or expiring. * @param credentials The credentials to check for expiration. * @return Whether the credentials are expired or not. */ isExpired(credentials) { const now = new Date().getTime(); return credentials.expiry_date ? now >= credentials.expiry_date - this.eagerRefreshThresholdMillis : false; } } exports.ExternalAccountAuthorizedUserClient = ExternalAccountAuthorizedUserClient; //# sourceMappingURL=externalAccountAuthorizedUserClient.js.map
Save
cmd:
run