2 * Copyright 2013 Google Inc. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /// <reference types="node" />
17 import { GoogleToken } from 'gtoken';
18 import * as stream from 'stream';
19 import { CredentialBody, Credentials, JWTInput } from './credentials';
20 import { GetTokenResponse, OAuth2Client, RefreshOptions, RequestMetadataResponse } from './oauth2client';
21 export interface JWTOptions extends RefreshOptions {
26 scopes?: string | string[];
28 additionalClaims?: {};
30 export declare class JWT extends OAuth2Client {
35 scopes?: string | string[];
39 additionalClaims?: {};
42 * JWT service account credentials.
44 * Retrieve access token using gtoken.
46 * @param email service account email address.
47 * @param keyFile path to private key file.
48 * @param key value of key
49 * @param scopes list of requested scopes or a single scope.
50 * @param subject impersonated account's email address.
51 * @param key_id the ID of the key
53 constructor(options: JWTOptions);
54 constructor(email?: string, keyFile?: string, key?: string, scopes?: string | string[], subject?: string, keyId?: string);
56 * Creates a copy of the credential with the specified scopes.
57 * @param scopes List of requested scopes or a single scope.
58 * @return The cloned instance.
60 createScoped(scopes?: string | string[]): JWT;
62 * Obtains the metadata to be sent with the request.
64 * @param url the URI being authorized.
66 protected getRequestMetadataAsync(url?: string | null): Promise<RequestMetadataResponse>;
68 * Indicates whether the credential requires scopes to be created by calling
69 * createScoped before use.
71 * @return false if createScoped does not need to be called.
73 createScopedRequired(): boolean;
75 * Determine if there are currently scopes available.
79 * Get the initial access token using gToken.
80 * @param callback Optional callback.
81 * @returns Promise that resolves with credentials
83 authorize(): Promise<Credentials>;
84 authorize(callback: (err: Error | null, result?: Credentials) => void): void;
85 private authorizeAsync;
87 * Refreshes the access token.
88 * @param refreshToken ignored
91 protected refreshTokenNoCache(refreshToken?: string | null): Promise<GetTokenResponse>;
93 * Create a gToken if it doesn't already exist.
97 * Create a JWT credentials instance using the given input options.
98 * @param json The input object.
100 fromJSON(json: JWTInput): void;
102 * Create a JWT credentials instance using the given input stream.
103 * @param inputStream The input stream.
104 * @param callback Optional callback.
106 fromStream(inputStream: stream.Readable): Promise<void>;
107 fromStream(inputStream: stream.Readable, callback: (err?: Error | null) => void): void;
108 private fromStreamAsync;
110 * Creates a JWT credentials instance using an API Key for authentication.
111 * @param apiKey The API Key in string form.
113 fromAPIKey(apiKey: string): void;
115 * Using the key or keyFile on the JWT client, obtain an object that contains
116 * the key and the client email.
118 getCredentials(): Promise<CredentialBody>;