UNPKG

3.83 kBTypeScriptView Raw
1/// <reference types="node" />
2import { GoogleToken } from 'gtoken';
3import * as stream from 'stream';
4import { CredentialBody, Credentials, JWTInput } from './credentials';
5import { IdTokenProvider } from './idtokenclient';
6import { GetTokenResponse, OAuth2Client, RefreshOptions, RequestMetadataResponse } from './oauth2client';
7export interface JWTOptions extends RefreshOptions {
8 email?: string;
9 keyFile?: string;
10 key?: string;
11 keyId?: string;
12 scopes?: string | string[];
13 subject?: string;
14 additionalClaims?: {};
15}
16export declare class JWT extends OAuth2Client implements IdTokenProvider {
17 email?: string;
18 keyFile?: string;
19 key?: string;
20 keyId?: string;
21 defaultScopes?: string | string[];
22 scopes?: string | string[];
23 scope?: string;
24 subject?: string;
25 gtoken?: GoogleToken;
26 additionalClaims?: {};
27 useJWTAccessWithScope?: boolean;
28 defaultServicePath?: string;
29 private access?;
30 /**
31 * JWT service account credentials.
32 *
33 * Retrieve access token using gtoken.
34 *
35 * @param email service account email address.
36 * @param keyFile path to private key file.
37 * @param key value of key
38 * @param scopes list of requested scopes or a single scope.
39 * @param subject impersonated account's email address.
40 * @param key_id the ID of the key
41 */
42 constructor(options: JWTOptions);
43 constructor(email?: string, keyFile?: string, key?: string, scopes?: string | string[], subject?: string, keyId?: string);
44 /**
45 * Creates a copy of the credential with the specified scopes.
46 * @param scopes List of requested scopes or a single scope.
47 * @return The cloned instance.
48 */
49 createScoped(scopes?: string | string[]): JWT;
50 /**
51 * Obtains the metadata to be sent with the request.
52 *
53 * @param url the URI being authorized.
54 */
55 protected getRequestMetadataAsync(url?: string | null): Promise<RequestMetadataResponse>;
56 /**
57 * Fetches an ID token.
58 * @param targetAudience the audience for the fetched ID token.
59 */
60 fetchIdToken(targetAudience: string): Promise<string>;
61 /**
62 * Determine if there are currently scopes available.
63 */
64 private hasUserScopes;
65 /**
66 * Are there any default or user scopes defined.
67 */
68 private hasAnyScopes;
69 /**
70 * Get the initial access token using gToken.
71 * @param callback Optional callback.
72 * @returns Promise that resolves with credentials
73 */
74 authorize(): Promise<Credentials>;
75 authorize(callback: (err: Error | null, result?: Credentials) => void): void;
76 private authorizeAsync;
77 /**
78 * Refreshes the access token.
79 * @param refreshToken ignored
80 * @private
81 */
82 protected refreshTokenNoCache(refreshToken?: string | null): Promise<GetTokenResponse>;
83 /**
84 * Create a gToken if it doesn't already exist.
85 */
86 private createGToken;
87 /**
88 * Create a JWT credentials instance using the given input options.
89 * @param json The input object.
90 */
91 fromJSON(json: JWTInput): void;
92 /**
93 * Create a JWT credentials instance using the given input stream.
94 * @param inputStream The input stream.
95 * @param callback Optional callback.
96 */
97 fromStream(inputStream: stream.Readable): Promise<void>;
98 fromStream(inputStream: stream.Readable, callback: (err?: Error | null) => void): void;
99 private fromStreamAsync;
100 /**
101 * Creates a JWT credentials instance using an API Key for authentication.
102 * @param apiKey The API Key in string form.
103 */
104 fromAPIKey(apiKey: string): void;
105 /**
106 * Using the key or keyFile on the JWT client, obtain an object that contains
107 * the key and the client email.
108 */
109 getCredentials(): Promise<CredentialBody>;
110}