index.d.ts
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
export declare type GetTokenCallback = (err: Error | null, token?: TokenData) => void;
export interface Credentials {
privateKey: string;
clientEmail?: string;
}
export interface TokenData {
refresh_token?: string;
expires_in?: number;
access_token?: string;
token_type?: string;
id_token?: string;
}
export interface TokenOptions {
keyFile?: string;
key?: string;
email?: string;
iss?: string;
sub?: string;
scope?: string | string[];
additionalClaims?: {};
eagerRefreshThresholdMillis?: number;
}
export interface GetTokenOptions {
forceRefresh?: boolean;
}
export declare class GoogleToken {
get accessToken(): string | undefined;
get idToken(): string | undefined;
get tokenType(): string | undefined;
get refreshToken(): string | undefined;
expiresAt?: number;
key?: string;
keyFile?: string;
iss?: string;
sub?: string;
scope?: string;
rawToken?: TokenData;
tokenExpires?: number;
email?: string;
additionalClaims?: {};
eagerRefreshThresholdMillis?: number;
private inFlightRequest?;
/**
* Create a GoogleToken.
*
* @param options Configuration object.
*/
constructor(options?: TokenOptions);
/**
* Returns whether the token has expired.
*
* @return true if the token has expired, false otherwise.
*/
hasExpired(): boolean;
/**
* Returns whether the token will expire within eagerRefreshThresholdMillis
*
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise.
*/
isTokenExpiring(): boolean;
/**
* Returns a cached token or retrieves a new one from Google.
*
* @param callback The callback function.
*/
getToken(opts?: GetTokenOptions): Promise<TokenData>;
getToken(callback: GetTokenCallback, opts?: GetTokenOptions): void;
/**
* Given a keyFile, extract the key and client email if available
* @param keyFile Path to a json, pem, or p12 file that contains the key.
* @returns an object with privateKey and clientEmail properties
*/
getCredentials(keyFile: string): Promise<Credentials>;
private getTokenAsync;
private getTokenAsyncInner;
private ensureEmail;
/**
* Revoke the token if one is set.
*
* @param callback The callback function.
*/
revokeToken(): Promise<void>;
revokeToken(callback: (err?: Error) => void): void;
private revokeTokenAsync;
/**
* Configure the GoogleToken for re-use.
* @param {object} options Configuration object.
*/
private configure;
/**
* Request the token from Google.
*/
private requestToken;
}