google-auth-library
Advanced tools
Comparing version
@@ -6,13 +6,2 @@ import { EventEmitter } from 'events'; | ||
/** | ||
* An interface for enforcing `fetch`-type compliance. | ||
* | ||
* @remarks | ||
* | ||
* This provides type guarantees during build-time, ensuring the `fetch` method is 1:1 | ||
* compatible with the `Gaxios#fetch` API. | ||
*/ | ||
interface GaxiosFetchCompliance { | ||
fetch: typeof fetch | Gaxios['fetch']; | ||
} | ||
/** | ||
* Easy access to symbol-indexed strings on config objects. | ||
@@ -171,3 +160,3 @@ */ | ||
*/ | ||
export declare abstract class AuthClient extends EventEmitter implements CredentialsClient, GaxiosFetchCompliance { | ||
export declare abstract class AuthClient extends EventEmitter implements CredentialsClient { | ||
apiKey?: string; | ||
@@ -197,27 +186,4 @@ projectId?: string | null; | ||
/** | ||
* A {@link fetch `fetch`} compliant API for {@link AuthClient}. | ||
* | ||
* @see {@link AuthClient.request} for the classic method. | ||
* | ||
* @remarks | ||
* | ||
* This is useful as a drop-in replacement for `fetch` API usage. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const authClient = new AuthClient(); | ||
* const fetchWithAuthClient: typeof fetch = (...args) => authClient.fetch(...args); | ||
* await fetchWithAuthClient('https://example.com'); | ||
* ``` | ||
* | ||
* @param args `fetch` API or {@link Gaxios.fetch `Gaxios#fetch`} parameters | ||
* @returns the {@link GaxiosResponse} with Gaxios-added properties | ||
*/ | ||
fetch<T>(...args: Parameters<Gaxios['fetch']>): GaxiosPromise<T>; | ||
/** | ||
* The public request API in which credentials may be added to the request. | ||
* | ||
* @see {@link AuthClient.fetch} for the modern method. | ||
* | ||
* @param options options for `gaxios` | ||
@@ -224,0 +190,0 @@ */ |
@@ -79,55 +79,2 @@ "use strict"; | ||
/** | ||
* A {@link fetch `fetch`} compliant API for {@link AuthClient}. | ||
* | ||
* @see {@link AuthClient.request} for the classic method. | ||
* | ||
* @remarks | ||
* | ||
* This is useful as a drop-in replacement for `fetch` API usage. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const authClient = new AuthClient(); | ||
* const fetchWithAuthClient: typeof fetch = (...args) => authClient.fetch(...args); | ||
* await fetchWithAuthClient('https://example.com'); | ||
* ``` | ||
* | ||
* @param args `fetch` API or {@link Gaxios.fetch `Gaxios#fetch`} parameters | ||
* @returns the {@link GaxiosResponse} with Gaxios-added properties | ||
*/ | ||
fetch(...args) { | ||
// Up to 2 parameters in either overload | ||
const input = args[0]; | ||
const init = args[1]; | ||
let url = undefined; | ||
const headers = new Headers(); | ||
// prepare URL | ||
if (typeof input === 'string') { | ||
url = new URL(input); | ||
} | ||
else if (input instanceof URL) { | ||
url = input; | ||
} | ||
else if (input && input.url) { | ||
url = new URL(input.url); | ||
} | ||
// prepare headers | ||
if (input && typeof input === 'object' && 'headers' in input) { | ||
gaxios_1.Gaxios.mergeHeaders(headers, input.headers); | ||
} | ||
if (init) { | ||
gaxios_1.Gaxios.mergeHeaders(headers, new Headers(init.headers)); | ||
} | ||
// prepare request | ||
if (typeof input === 'object' && !(input instanceof URL)) { | ||
// input must have been a non-URL object | ||
return this.request({ ...init, ...input, headers, url }); | ||
} | ||
else { | ||
// input must have been a string or URL | ||
return this.request({ ...init, headers, url }); | ||
} | ||
} | ||
/** | ||
* Sets the auth credentials. | ||
@@ -134,0 +81,0 @@ */ |
@@ -6,5 +6,6 @@ import { GaxiosOptions, GaxiosResponse } from 'gaxios'; | ||
import { GCPEnv } from './envDetect'; | ||
import { JWT } from './jwtclient'; | ||
import { UserRefreshClient } from './refreshclient'; | ||
import { Impersonated } from './impersonated'; | ||
import { JWT, JWTOptions } from './jwtclient'; | ||
import { OAuth2ClientOptions } from './oauth2client'; | ||
import { UserRefreshClient, UserRefreshClientOptions } from './refreshclient'; | ||
import { Impersonated, ImpersonatedOptions } from './impersonated'; | ||
import { ExternalAccountClientOptions } from './externalclient'; | ||
@@ -14,3 +15,3 @@ import { BaseExternalAccountClient } from './baseexternalclient'; | ||
import { ExternalAccountAuthorizedUserClient } from './externalAccountAuthorizedUserClient'; | ||
import { AnyAuthClient, AnyAuthClientConstructor } from '..'; | ||
import { AnyAuthClient } from '..'; | ||
/** | ||
@@ -34,3 +35,3 @@ * Defines all types of explicit clients that are determined via ADC JSON | ||
} | ||
export interface GoogleAuthOptions<T extends AuthClient = AnyAuthClient> { | ||
export interface GoogleAuthOptions<T extends AuthClient = JSONClient> { | ||
/** | ||
@@ -63,5 +64,5 @@ * An API key to use, optional. Cannot be used with {@link GoogleAuthOptions.credentials `credentials`}. | ||
/** | ||
* `AuthClientOptions` object passed to the constructor of the client | ||
* Options object passed to the constructor of the client | ||
*/ | ||
clientOptions?: Extract<ConstructorParameters<AnyAuthClientConstructor>[0], AuthClientOptions>; | ||
clientOptions?: JWTOptions | OAuth2ClientOptions | UserRefreshClientOptions | ImpersonatedOptions; | ||
/** | ||
@@ -90,3 +91,3 @@ * Required scopes for the desired API request | ||
}; | ||
export declare class GoogleAuth<T extends AuthClient = AuthClient> { | ||
export declare class GoogleAuth<T extends AuthClient = JSONClient> { | ||
#private; | ||
@@ -336,30 +337,6 @@ /** | ||
*/ | ||
authorizeRequest(opts?: Pick<GaxiosOptions, 'url' | 'headers'>): Promise<Pick<GaxiosOptions, "url" | "headers">>; | ||
authorizeRequest(opts?: Pick<GaxiosOptions, 'url' | 'headers'>): Promise<Pick<GaxiosOptions, "headers" | "url">>; | ||
/** | ||
* A {@link fetch `fetch`} compliant API for {@link GoogleAuth}. | ||
* | ||
* @see {@link GoogleAuth.request} for the classic method. | ||
* | ||
* @remarks | ||
* | ||
* This is useful as a drop-in replacement for `fetch` API usage. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const auth = new GoogleAuth(); | ||
* const fetchWithAuth: typeof fetch = (...args) => auth.fetch(...args); | ||
* await fetchWithAuth('https://example.com'); | ||
* ``` | ||
* | ||
* @param args `fetch` API or {@link Gaxios.fetch `Gaxios#fetch`} parameters | ||
* @returns the {@link GaxiosResponse} with Gaxios-added properties | ||
*/ | ||
fetch<T>(...args: Parameters<AuthClient['fetch']>): Promise<GaxiosResponse<T>>; | ||
/** | ||
* Automatically obtain application default credentials, and make an | ||
* HTTP request using the given options. | ||
* | ||
* @see {@link GoogleAuth.fetch} for the modern method. | ||
* | ||
* @param opts Axios request options for the HTTP request. | ||
@@ -366,0 +343,0 @@ */ |
@@ -777,31 +777,4 @@ "use strict"; | ||
/** | ||
* A {@link fetch `fetch`} compliant API for {@link GoogleAuth}. | ||
* | ||
* @see {@link GoogleAuth.request} for the classic method. | ||
* | ||
* @remarks | ||
* | ||
* This is useful as a drop-in replacement for `fetch` API usage. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const auth = new GoogleAuth(); | ||
* const fetchWithAuth: typeof fetch = (...args) => auth.fetch(...args); | ||
* await fetchWithAuth('https://example.com'); | ||
* ``` | ||
* | ||
* @param args `fetch` API or {@link Gaxios.fetch `Gaxios#fetch`} parameters | ||
* @returns the {@link GaxiosResponse} with Gaxios-added properties | ||
*/ | ||
async fetch(...args) { | ||
const client = await this.getClient(); | ||
return client.fetch(...args); | ||
} | ||
/** | ||
* Automatically obtain application default credentials, and make an | ||
* HTTP request using the given options. | ||
* | ||
* @see {@link GoogleAuth.fetch} for the modern method. | ||
* | ||
* @param opts Axios request options for the HTTP request. | ||
@@ -808,0 +781,0 @@ */ |
@@ -21,2 +21,3 @@ "use strict"; | ||
const formatEcdsa = require("ecdsa-sig-formatter"); | ||
const util_1 = require("../util"); | ||
const crypto_1 = require("../crypto/crypto"); | ||
@@ -201,3 +202,3 @@ const authclient_1 = require("./authclient"); | ||
url, | ||
data: new URLSearchParams(values), | ||
data: new URLSearchParams((0, util_1.removeUndefinedValuesInObject)(values)), | ||
headers, | ||
@@ -256,3 +257,3 @@ }; | ||
url, | ||
data: new URLSearchParams(data), | ||
data: new URLSearchParams((0, util_1.removeUndefinedValuesInObject)(data)), | ||
}; | ||
@@ -259,0 +260,0 @@ authclient_1.AuthClient.setMethodName(opts, 'refreshTokenNoCache'); |
@@ -20,2 +20,3 @@ "use strict"; | ||
const oauth2common_1 = require("./oauth2common"); | ||
const util_1 = require("../util"); | ||
/** | ||
@@ -76,9 +77,2 @@ * Implements the OAuth 2.0 token exchange based on | ||
}; | ||
// Keep defined fields. | ||
const payload = {}; | ||
Object.entries(values).forEach(([key, value]) => { | ||
if (value !== undefined) { | ||
payload[key] = value; | ||
} | ||
}); | ||
const opts = { | ||
@@ -89,3 +83,3 @@ ...StsCredentials.RETRY_CONFIG, | ||
headers, | ||
data: new URLSearchParams(payload), | ||
data: new URLSearchParams((0, util_1.removeUndefinedValuesInObject)(values)), | ||
}; | ||
@@ -92,0 +86,0 @@ authclient_1.AuthClient.setMethodName(opts, 'exchangeToken'); |
@@ -28,10 +28,6 @@ import { GoogleAuth } from './auth/googleauth'; | ||
/** | ||
* A union type for all {@link AuthClient `AuthClient`} constructors. | ||
*/ | ||
export type AnyAuthClientConstructor = Extract<ALL_EXPORTS, typeof AuthClient>; | ||
/** | ||
* A union type for all {@link AuthClient `AuthClient`}s. | ||
*/ | ||
export type AnyAuthClient = InstanceType<AnyAuthClientConstructor>; | ||
declare const auth: GoogleAuth<AuthClient>; | ||
export type AnyAuthClient = InstanceType<Extract<ALL_EXPORTS, typeof AuthClient>>; | ||
declare const auth: GoogleAuth<import("./auth/googleauth").JSONClient>; | ||
export { auth, GoogleAuth }; |
@@ -143,1 +143,6 @@ /** | ||
} | ||
export declare function removeUndefinedValuesInObject(object: { | ||
[key: string]: any; | ||
}): { | ||
[key: string]: any; | ||
}; |
@@ -19,2 +19,3 @@ "use strict"; | ||
exports.originalOrCamelOptions = originalOrCamelOptions; | ||
exports.removeUndefinedValuesInObject = removeUndefinedValuesInObject; | ||
/** | ||
@@ -128,2 +129,11 @@ * Returns the camel case of a provided string. | ||
exports.LRUCache = LRUCache; | ||
// Given and object remove fields where value is undefined. | ||
function removeUndefinedValuesInObject(object) { | ||
Object.entries(object).forEach(([key, value]) => { | ||
if (value === undefined || value === 'undefined') { | ||
delete object[key]; | ||
} | ||
}); | ||
return object; | ||
} | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "google-auth-library", | ||
"version": "10.0.0-rc.3", | ||
"version": "10.0.0", | ||
"author": "Google Inc.", | ||
@@ -22,6 +22,6 @@ "description": "Google APIs Authentication Client Library for Node.js", | ||
"ecdsa-sig-formatter": "^1.0.11", | ||
"gaxios": "^7.0.0-rc.4", | ||
"gcp-metadata": "^7.0.0-rc.1", | ||
"gaxios": "^7.0.0", | ||
"gcp-metadata": "^7.0.0", | ||
"google-logging-utils": "^1.0.0", | ||
"gtoken": "^8.0.0-rc.1", | ||
"gtoken": "^8.0.0", | ||
"jws": "^4.0.0" | ||
@@ -74,3 +74,3 @@ }, | ||
"prepare": "npm run compile", | ||
"lint": "gts check", | ||
"lint": "gts check --no-inline-config", | ||
"compile": "tsc -p .", | ||
@@ -77,0 +77,0 @@ "fix": "gts fix", |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1
-50%1463
1.88%517030
-0.68%10226
-1.26%Updated
Updated
Updated