Class JWT (8.6.0)

Inheritance

EventEmitter > AuthClient > OAuth2Client > JWT

Package

google-auth-library

Constructors

(constructor)(options)

constructor(options: JWTOptions);

JWT service account credentials.

Retrieve access token using gtoken.

Parameter
NameDescription
options JWTOptions

(constructor)(email, keyFile, key, scopes, subject, keyId)

constructor(email?: string, keyFile?: string, key?: string, scopes?: string | string[], subject?: string, keyId?: string);

Constructs a new instance of the JWT class

Parameters
NameDescription
email string
keyFile string
key string
scopes string | string[]
subject string
keyId string

Properties

additionalClaims

additionalClaims?: {};

defaultScopes

defaultScopes?: string | string[];

defaultServicePath

defaultServicePath?: string;

email

email?: string;

gtoken

gtoken?: GoogleToken;

key

key?: string;

keyFile

keyFile?: string;

keyId

keyId?: string;

scope

scope?: string;

scopes

scopes?: string | string[];

subject

subject?: string;

useJWTAccessWithScope

useJWTAccessWithScope?: boolean;

Methods

authorize()

authorize(): Promise<Credentials>;

Get the initial access token using gToken.

Returns
TypeDescription
Promise<Credentials>

Promise that resolves with credentials

authorize(callback)

authorize(callback: (err: Error | null, result?: Credentials) => void): void;
Parameter
NameDescription
callback (err: Error | null, result?: Credentials) => void
Returns
TypeDescription
void

createScoped(scopes)

createScoped(scopes?: string | string[]): JWT;

Creates a copy of the credential with the specified scopes.

Parameter
NameDescription
scopes string | string[]

List of requested scopes or a single scope. The cloned instance.

Returns
TypeDescription
JWT

fetchIdToken(targetAudience)

fetchIdToken(targetAudience: string): Promise<string>;

Fetches an ID token.

Parameter
NameDescription
targetAudience string

the audience for the fetched ID token.

Returns
TypeDescription
Promise<string>

fromAPIKey(apiKey)

fromAPIKey(apiKey: string): void;

Creates a JWT credentials instance using an API Key for authentication.

Parameter
NameDescription
apiKey string

The API Key in string form.

Returns
TypeDescription
void

fromJSON(json)

fromJSON(json: JWTInput): void;

Create a JWT credentials instance using the given input options.

Parameter
NameDescription
json JWTInput

The input object.

Returns
TypeDescription
void

fromStream(inputStream)

fromStream(inputStream: stream.Readable): Promise<void>;

Create a JWT credentials instance using the given input stream.

Parameter
NameDescription
inputStream stream.Readable

The input stream.

Returns
TypeDescription
Promise<void>

fromStream(inputStream, callback)

fromStream(inputStream: stream.Readable, callback: (err?: Error | null) => void): void;
Parameters
NameDescription
inputStream stream.Readable
callback (err?: Error | null) => void
Returns
TypeDescription
void

getCredentials()

getCredentials(): Promise<CredentialBody>;

Using the key or keyFile on the JWT client, obtain an object that contains the key and the client email.

Returns
TypeDescription
Promise<CredentialBody>

getRequestMetadataAsync(url)

protected getRequestMetadataAsync(url?: string | null): Promise<RequestMetadataResponse>;

Obtains the metadata to be sent with the request.

Parameter
NameDescription
url string | null

the URI being authorized.

Returns
TypeDescription
Promise<RequestMetadataResponse>

refreshTokenNoCache(refreshToken)

protected refreshTokenNoCache(refreshToken?: string | null): Promise<GetTokenResponse>;

Refreshes the access token.

Parameter
NameDescription
refreshToken string | null

ignored

Returns
TypeDescription
Promise<GetTokenResponse>