Class JWT (9.0.0)
Stay organized with collections
Save and categorize content based on your preferences.
Package
google-auth-library
Constructors
(constructor)(options)
constructor
(
options
:
JWTOptions
);
JWT service account credentials.
Retrieve access token using gtoken.
(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
Properties
additionalClaims
defaultScopes
defaultScopes
?:
string
|
string
[];
defaultServicePath
defaultServicePath
?:
string
;
email
gtoken
key
keyFile
keyId
scope
scopes
scopes
?:
string
|
string
[];
subject
useJWTAccessWithScope
useJWTAccessWithScope
?:
boolean
;
Methods
authorize()
authorize
()
:
Promise<Credentials>
;
Get the initial access token using gToken.
Promise that resolves with credentials
authorize(callback)
authorize
(
callback
:
(
err
:
Error
|
null
,
result
?:
Credentials
)
=
>
void
)
:
void
;
createScoped(scopes)
createScoped
(
scopes
?:
string
|
string
[])
:
JWT
;
Creates a copy of the credential with the specified scopes.
scopes
string | string[]
List of requested scopes or a single scope. The cloned instance.
fetchIdToken(targetAudience)
fetchIdToken
(
targetAudience
:
string
)
:
Promise<string>
;
targetAudience
string
the audience for the fetched ID token.
fromAPIKey(apiKey)
fromAPIKey
(
apiKey
:
string
)
:
void
;
Creates a JWT credentials instance using an API Key for authentication.
apiKey
string
The API Key in string form.
fromJSON(json)
fromJSON
(
json
:
JWTInput
)
:
void
;
Create a JWT credentials instance using the given input options.
fromStream(inputStream)
fromStream
(
inputStream
:
stream
.
Readable
)
:
Promise<void>
;
Create a JWT credentials instance using the given input stream.
inputStream
stream.Readable
The input stream.
fromStream(inputStream, callback)
fromStream
(
inputStream
:
stream
.
Readable
,
callback
:
(
err
?:
Error
|
null
)
=
>
void
)
:
void
;
inputStream
stream.Readable
callback
(err?: Error
| null) => 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.
protected
getRequestMetadataAsync
(
url
?:
string
|
null
)
:
Promise<RequestMetadataResponse>
;
Obtains the metadata to be sent with the request.
url
string | null
the URI being authorized.
Promise
< RequestMetadataResponse
>
refreshTokenNoCache(refreshToken)
protected
refreshTokenNoCache
(
refreshToken
?:
string
|
null
)
:
Promise<GetTokenResponse>
;
Refreshes the access token.
Promise
< GetTokenResponse
>
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-09-04 UTC.
[[["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-09-04 UTC."],[],[],null,["# Class JWT (9.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [9.0.0 (latest)](/nodejs/docs/reference/google-auth-library/latest/google-auth-library/jwt)\n- [8.7.0](/nodejs/docs/reference/google-auth-library/8.7.0/google-auth-library/jwt)\n- [8.6.0](/nodejs/docs/reference/google-auth-library/8.6.0/google-auth-library/jwt)\n- [8.5.2](/nodejs/docs/reference/google-auth-library/8.5.2/google-auth-library/jwt)\n- [8.3.0](/nodejs/docs/reference/google-auth-library/8.3.0/google-auth-library/jwt)\n- [8.2.0](/nodejs/docs/reference/google-auth-library/8.2.0/google-auth-library/jwt)\n- [8.1.1](/nodejs/docs/reference/google-auth-library/8.1.1/google-auth-library/jwt)\n- [7.14.1](/nodejs/docs/reference/google-auth-library/7.14.1/google-auth-library/jwt)\n- [7.13.0](/nodejs/docs/reference/google-auth-library/7.13.0/google-auth-library/jwt)\n- [7.12.0](/nodejs/docs/reference/google-auth-library/7.12.0/google-auth-library/jwt)\n- [7.10.4](/nodejs/docs/reference/google-auth-library/7.10.4/google-auth-library/jwt)\n- [7.9.1](/nodejs/docs/reference/google-auth-library/7.9.1/google-auth-library/jwt)\n- [7.8.0](/nodejs/docs/reference/google-auth-library/7.8.0/google-auth-library/jwt)\n- [7.7.0](/nodejs/docs/reference/google-auth-library/7.7.0/google-auth-library/jwt)\n- [7.6.2](/nodejs/docs/reference/google-auth-library/7.6.2/google-auth-library/jwt)\n- [7.5.0](/nodejs/docs/reference/google-auth-library/7.5.0/google-auth-library/jwt)\n- [7.4.1](/nodejs/docs/reference/google-auth-library/7.4.1/google-auth-library/jwt)\n- [7.3.0](/nodejs/docs/reference/google-auth-library/7.3.0/google-auth-library/jwt)\n- [7.2.0](/nodejs/docs/reference/google-auth-library/7.2.0/google-auth-library/jwt)\n- [7.1.2](/nodejs/docs/reference/google-auth-library/7.1.2/google-auth-library/jwt) \n\nInheritance\n-----------\n\nAuthClient \\\u003e [OAuth2Client](/nodejs/docs/reference/google-auth-library/latest/google-auth-library/oauth2client) \\\u003e JWT\n\nPackage\n-------\n\n[google-auth-library](../overview.html)\n\nConstructors\n------------\n\n### (constructor)(options)\n\n constructor(options: JWTOptions);\n\nJWT service account credentials.\n\nRetrieve access token using gtoken.\n\n### (constructor)(email, keyFile, key, scopes, subject, keyId)\n\n constructor(email?: string, keyFile?: string, key?: string, scopes?: string | string[], subject?: string, keyId?: string);\n\nConstructs a new instance of the `JWT` class\n\nProperties\n----------\n\n### additionalClaims\n\n additionalClaims?: {};\n\n### defaultScopes\n\n defaultScopes?: string | string[];\n\n### defaultServicePath\n\n defaultServicePath?: string;\n\n### email\n\n email?: string;\n\n### gtoken\n\n gtoken?: GoogleToken;\n\n### key\n\n key?: string;\n\n### keyFile\n\n keyFile?: string;\n\n### keyId\n\n keyId?: string;\n\n### scope\n\n scope?: string;\n\n### scopes\n\n scopes?: string | string[];\n\n### subject\n\n subject?: string;\n\n### useJWTAccessWithScope\n\n useJWTAccessWithScope?: boolean;\n\nMethods\n-------\n\n### authorize()\n\n authorize(): Promise\u003cCredentials\u003e;\n\nGet the initial access token using gToken.\n\n### authorize(callback)\n\n authorize(callback: (err: Error | null, result?: Credentials) =\u003e void): void;\n\n### createScoped(scopes)\n\n createScoped(scopes?: string | string[]): JWT;\n\nCreates a copy of the credential with the specified scopes.\n\n### fetchIdToken(targetAudience)\n\n fetchIdToken(targetAudience: string): Promise\u003cstring\u003e;\n\nFetches an ID token.\n\n### fromAPIKey(apiKey)\n\n fromAPIKey(apiKey: string): void;\n\nCreates a JWT credentials instance using an API Key for authentication.\n\n### fromJSON(json)\n\n fromJSON(json: JWTInput): void;\n\nCreate a JWT credentials instance using the given input options.\n\n### fromStream(inputStream)\n\n fromStream(inputStream: stream.Readable): Promise\u003cvoid\u003e;\n\nCreate a JWT credentials instance using the given input stream.\n\n### fromStream(inputStream, callback)\n\n fromStream(inputStream: stream.Readable, callback: (err?: Error | null) =\u003e void): void;\n\n### getCredentials()\n\n getCredentials(): Promise\u003cCredentialBody\u003e;\n\nUsing the key or keyFile on the JWT client, obtain an object that contains the key and the client email.\n\n### getRequestMetadataAsync(url)\n\n protected getRequestMetadataAsync(url?: string | null): Promise\u003cRequestMetadataResponse\u003e;\n\nObtains the metadata to be sent with the request.\n\n### refreshTokenNoCache(refreshToken)\n\n protected refreshTokenNoCache(refreshToken?: string | null): Promise\u003cGetTokenResponse\u003e;\n\nRefreshes the access token."]]