Send feedback
Class GoogleAuth (8.2.0)
Stay organized with collections
Save and categorize content based on your preferences.
Version 8.2.0 keyboard_arrow_down
Package
google-auth-library
Constructors
(constructor)(opts)
constructor ( opts ?: GoogleAuthOptions<T> );
Constructs a new instance of the GoogleAuth
class
Parameter
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..
Parameter
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
Parameter
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
fromStream(inputStream, options)
fromStream ( inputStream : stream . Readable , options : RefreshOptions ) : Promise<JSONClient> ;
Parameters
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
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
getApplicationDefault(options)
getApplicationDefault ( options : RefreshOptions ) : Promise<ADCResponse> ;
Parameter
Returns
Type Description Promise <ADCResponse >
getApplicationDefault(options, callback)
getApplicationDefault ( options : RefreshOptions , callback : ADCCallback ) : void ;
Parameters
Returns
getClient()
getClient () : Promise<Compute | JSONClient | NonNullable<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 | NonNullable <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.
Returns
getCredentials(callback)
getCredentials ( callback : ( err : Error | null , credentials ?: CredentialBody ) = > void ) : void ;
Parameter
Name Description callback
(err: Error | null, credentials?: CredentialBody ) => void
Returns
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 ;
Parameter
Returns
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
setGapicJWTValues(client)
setGapicJWTValues ( client : JWT ) : void ;
Parameter
Name Description client
JWT
Returns
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>
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-02-03 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-03 UTC."],[],[]]