Class JWT (7.7.0)

Inheritance

AuthClient > OAuth2Client > JWT

Package

google-auth-library!

Constructors

(constructor)(options)

  constructor 
 ( 
 options 
 : 
  
 JWTOptions 
 ); 
 

JWT service account credentials.

Retrieve access token using gtoken.

Parameter
Name Description
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
Name Description
email string
keyFile string
key string
scopes string | string[]
subject string
keyId string

Properties

additionalClaims

  additionalClaims 
 ?: 
  
 {}; 
 
Property Value
Type Description
{}

defaultScopes

  defaultScopes 
 ?: 
  
 string 
  
 | 
  
 string 
 []; 
 
Property Value
Type Description
string | string[]

defaultServicePath

  defaultServicePath 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

email

  email 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

gtoken

  gtoken 
 ?: 
  
 GoogleToken 
 ; 
 
Property Value
Type Description
GoogleToken

key

  key 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

keyFile

  keyFile 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

keyId

  keyId 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

scope

  scope 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

scopes

  scopes 
 ?: 
  
 string 
  
 | 
  
 string 
 []; 
 
Property Value
Type Description
string | string[]

subject

  subject 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

useJWTAccessWithScope

  useJWTAccessWithScope 
 ?: 
  
 boolean 
 ; 
 
Property Value
Type Description
boolean

Methods

authorize()

  authorize 
 () 
 : 
  
 Promise<Credentials> 
 ; 
 

Get the initial access token using gToken.

Returns
Type Description
Promise < Credentials >

Promise that resolves with credentials

authorize(callback)

  authorize 
 ( 
 callback 
 : 
  
 ( 
 err 
 : 
  
 Error 
  
 | 
  
 null 
 , 
  
 result 
 ?: 
  
 Credentials 
 ) 
  
 = 
>  
 void 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name Description
callback (err: Error | null, result?: Credentials ) => void
Returns
Type Description
void

createScoped(scopes)

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

Creates a copy of the credential with the specified scopes.

Parameter
Name Description
scopes string | string[]

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

Returns
Type Description
JWT

fetchIdToken(targetAudience)

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

Fetches an ID token.

Parameter
Name Description
targetAudience string

the audience for the fetched ID token.

Returns
Type Description
Promise <string>

fromAPIKey(apiKey)

  fromAPIKey 
 ( 
 apiKey 
 : 
  
 string 
 ) 
 : 
  
 void 
 ; 
 

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

Parameter
Name Description
apiKey string

The API Key in string form.

Returns
Type Description
void

fromJSON(json)

  fromJSON 
 ( 
 json 
 : 
  
 JWTInput 
 ) 
 : 
  
 void 
 ; 
 

Create a JWT credentials instance using the given input options.

Parameter
Name Description
json JWTInput

The input object.

Returns
Type Description
void

fromStream(inputStream)

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

Create a JWT credentials instance using the given input stream.

Parameter
Name Description
inputStream stream.Readable

The input stream.

Returns
Type Description
Promise <void>

fromStream(inputStream, callback)

  fromStream 
 ( 
 inputStream 
 : 
  
 stream 
 . 
 Readable 
 , 
  
 callback 
 : 
  
 ( 
 err 
 ?: 
  
 Error 
  
 | 
  
 null 
 ) 
  
 = 
>  
 void 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
inputStream stream.Readable
callback (err?: Error | null) => void
Returns
Type Description
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
Type Description
Promise < CredentialBody >

getRequestMetadataAsync(url)

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

Obtains the metadata to be sent with the request.

Parameter
Name Description
url string | null

the URI being authorized.

Returns
Type Description
Promise < RequestMetadataResponse >

refreshTokenNoCache(refreshToken)

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

Refreshes the access token.

Parameter
Name Description
refreshToken string | null

ignored

Returns
Type Description
Promise < GetTokenResponse >
Create a Mobile Website
View Site in Mobile | Classic
Share by: