Package
google-auth-library
Constructors
(constructor)(opts)
constructor(opts?: GoogleAuthOptions<T>);
Constructs a new instance of the GoogleAuth
class
Properties
cachedCredential
cachedCredential: JSONClient | Impersonated | Compute | T | null;
defaultScopes
defaultScopes?: string | string[];
Scopes populated by the client library by default. We differentiate between these and user defined scopes when deciding whether to use a self-signed JWT.
defaultServicePath
defaultServicePath?: string;
DefaultTransporter
static DefaultTransporter: typeof DefaultTransporter;
Export DefaultTransporter as a static property of the class.
isGCE
get isGCE(): boolean | undefined;
jsonContent
jsonContent: JWTInput | ExternalAccountClientOptions | null;
transporter
transporter?: Transporter;
useJWTAccessWithScope
useJWTAccessWithScope?: boolean;
Methods
_checkIsGCE()
_checkIsGCE(): Promise<boolean>;
Determines whether the auth layer is running on Google Compute Engine.
Returns |
---|
Type | Description |
Promise<boolean> | A promise that resolves with the boolean. private
|
_getApplicationCredentialsFromFilePath(filePath, options)
_getApplicationCredentialsFromFilePath(filePath: string, options?: RefreshOptions): Promise<JSONClient>;
Attempts to load default credentials from a file at the given path..
Parameters |
---|
Name | Description |
filePath |
string
The path to the file to read.
|
options |
RefreshOptions
|
Returns |
---|
Type | Description |
Promise<JSONClient> | Promise that resolves with the OAuth2Client private
|
_tryGetApplicationCredentialsFromEnvironmentVariable(options)
_tryGetApplicationCredentialsFromEnvironmentVariable(options?: RefreshOptions): Promise<JSONClient | null>;
Attempts to load default credentials from the environment variable path..
Returns |
---|
Type | Description |
Promise<JSONClient | null> | Promise that resolves with the OAuth2Client or null. private
|
_tryGetApplicationCredentialsFromWellKnownFile(options)
_tryGetApplicationCredentialsFromWellKnownFile(options?: RefreshOptions): Promise<JSONClient | null>;
Attempts to load default credentials from a well-known file location Promise that resolves with the OAuth2Client or null. private
Returns |
---|
Type | Description |
Promise<JSONClient | null> | |
authorizeRequest(opts)
authorizeRequest(opts: {
url?: string;
uri?: string;
headers?: Headers;
}): Promise<{
url?: string | undefined;
uri?: string | undefined;
headers?: Headers | undefined;
}>;
Obtain credentials for a request, then attach the appropriate headers to the request options.
Parameter |
---|
Name | Description |
opts |
{
url?: string;
uri?: string;
headers?: Headers;
}
Axios or Request options on which to attach the headers
|
Returns |
---|
Type | Description |
Promise<{
url?: string | undefined;
uri?: string | undefined;
headers?: Headers | undefined;
}> | |
fromAPIKey(apiKey, options)
fromAPIKey(apiKey: string, options?: RefreshOptions): JWT;
Create a credentials instance using the given API key string.
Parameters |
---|
Name | Description |
apiKey |
string
The API key string
|
options |
RefreshOptions
An optional options object.
|
Returns |
---|
Type | Description |
JWT | A JWT loaded from the key
|
fromImpersonatedJSON(json)
fromImpersonatedJSON(json: ImpersonatedJWTInput): Impersonated;
Create a credentials instance using a given impersonated input options.
Parameter |
---|
Name | Description |
json |
ImpersonatedJWTInput
The impersonated input object.
|
Returns |
---|
Type | Description |
Impersonated | JWT or UserRefresh Client with data
|
fromJSON(json, options)
fromJSON(json: JWTInput | ImpersonatedJWTInput, options?: RefreshOptions): JSONClient;
Create a credentials instance using the given input options.
Parameters |
---|
Name | Description |
json |
JWTInput | ImpersonatedJWTInput
The input object.
|
options |
RefreshOptions
The JWT or UserRefresh options for the client
|
Returns |
---|
Type | Description |
JSONClient | JWT or UserRefresh Client with data
|
fromStream(inputStream)
fromStream(inputStream: stream.Readable): Promise<JSONClient>;
Create a credentials instance using the given input stream.
Parameter |
---|
Name | Description |
inputStream |
stream.Readable
The input stream.
|
Returns |
---|
Type | Description |
Promise<JSONClient> | |
fromStream(inputStream, callback)
fromStream(inputStream: stream.Readable, callback: CredentialCallback): void;
Parameters |
---|
Name | Description |
inputStream |
stream.Readable
|
callback |
CredentialCallback
|
Returns |
---|
Type | Description |
void | |
fromStream(inputStream, options)
fromStream(inputStream: stream.Readable, options: RefreshOptions): Promise<JSONClient>;
Parameters |
---|
Name | Description |
inputStream |
stream.Readable
|
options |
RefreshOptions
|
Returns |
---|
Type | Description |
Promise<JSONClient> | |
fromStream(inputStream, options, callback)
fromStream(inputStream: stream.Readable, options: RefreshOptions, callback: CredentialCallback): void;
Parameters |
---|
Name | Description |
inputStream |
stream.Readable
|
options |
RefreshOptions
|
callback |
CredentialCallback
|
Returns |
---|
Type | Description |
void | |
getAccessToken()
getAccessToken(): Promise<string | null | undefined>;
Automatically obtain application default credentials, and return an access token for making requests.
Returns |
---|
Type | Description |
Promise<string | null | undefined> | |
getApplicationDefault()
getApplicationDefault(): Promise<ADCResponse>;
Obtains the default service-level credentials for the application.
Returns |
---|
Type | Description |
Promise<ADCResponse> | Promise that resolves with the ADCResponse (if no callback was passed).
|
getApplicationDefault(callback)
getApplicationDefault(callback: ADCCallback): void;
Parameter |
---|
Name | Description |
callback |
ADCCallback
|
Returns |
---|
Type | Description |
void | |
getApplicationDefault(options)
getApplicationDefault(options: RefreshOptions): Promise<ADCResponse>;
Returns |
---|
Type | Description |
Promise<ADCResponse> | |
getApplicationDefault(options, callback)
getApplicationDefault(options: RefreshOptions, callback: ADCCallback): void;
Returns |
---|
Type | Description |
void | |
getClient()
getClient(): Promise<Compute | JSONClient | T>;
Automatically obtain a client based on the provided configuration. If no options were passed, use Application Default Credentials.
Returns |
---|
Type | Description |
Promise<Compute | JSONClient | T> | |
getCredentials()
getCredentials(): Promise<CredentialBody>;
The callback function handles a credential object that contains the client_email and private_key (if exists). getCredentials first checks if the client is using an external account and uses the service account email in place of client_email. If that doesn't exist, it checks for these values from the user JSON. If the user JSON doesn't exist, and the environment is on GCE, it gets the client_email from the cloud metadata server.
getCredentials(callback)
getCredentials(callback: (err: Error | null, credentials?: CredentialBody) => void): void;
Parameter |
---|
Name | Description |
callback |
(err: Error | null, credentials?: CredentialBody) => void
|
Returns |
---|
Type | Description |
void | |
getEnv()
getEnv(): Promise<GCPEnv>;
Determine the compute environment in which the code is running.
Returns |
---|
Type | Description |
Promise<GCPEnv> | |
getIdTokenClient(targetAudience)
getIdTokenClient(targetAudience: string): Promise<IdTokenClient>;
Creates a client which will fetch an ID token for authorization.
Parameter |
---|
Name | Description |
targetAudience |
string
the audience for the fetched ID token.
|
Returns |
---|
Type | Description |
Promise<IdTokenClient> | IdTokenClient for making HTTP calls authenticated with ID tokens.
|
getProjectId()
getProjectId(): Promise<string>;
Obtains the default project ID for the application.
Returns |
---|
Type | Description |
Promise<string> | Promise that resolves with project Id (if used without callback)
|
getProjectId(callback)
getProjectId(callback: ProjectIdCallback): void;
Returns |
---|
Type | Description |
void | |
getRequestHeaders(url?: string): Promise<Headers>;
Obtain the HTTP headers that will provide authorization for a given request.
Parameter |
---|
Name | Description |
url |
string
|
Returns |
---|
Type | Description |
Promise<Headers> | |
request(opts)
request<T = any>(opts: GaxiosOptions): Promise<GaxiosResponse<T>>;
Automatically obtain application default credentials, and make an HTTP request using the given options.
Parameter |
---|
Name | Description |
opts |
GaxiosOptions
Axios request options for the HTTP request.
|
Returns |
---|
Type | Description |
Promise<GaxiosResponse<T>> | |
Type Parameter |
---|
Name | Description |
T | |
setGapicJWTValues(client)
setGapicJWTValues(client: JWT): void;
Parameter |
---|
Name | Description |
client |
JWT
|
Returns |
---|
Type | Description |
void | |
sign(data)
sign(data: string): Promise<string>;
Sign the given data with the current private key, or go out to the IAM API to sign it.
Parameter |
---|
Name | Description |
data |
string
The data to be signed.
|
Returns |
---|
Type | Description |
Promise<string> | |