UNPKG

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