-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.d.ts
141 lines (136 loc) · 2.93 KB
/
index.d.ts
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
interface HeaderAdditions {
/**
* Cryptographic algorithm used to secure the JWT
* @example "RS256"
*/
alg?: string,
/**
* Type of token
* @example "JWT"
*/
typ?: string,
/**
* Service account's private key ID
*/
kid?: string,
}
/**
* General purpose JWT generation
*/
declare function getToken ({
privateKeyPEM,
payload,
alg,
headerAdditions,
cryptoImpl
}: {
/**
* The private key string in PEM format
*/
privateKeyPEM: string,
payload: {
/**
* Service account's email address (sa.client_email)
*/
iss: string,
/**
* Service account's email address (sa.client_email)
*/
sub: string,
/**
* Current Unix timem when the token was issued (in seconds since epoch)
*/
iat: number,
/**
* The time exactly 3600 seconds after the token was issued, when the JWT expires
*/
exp: number,
/**
* The API endpoint.
* @example https://<SERVICE>.googleapis.com/
*/
aud: string,
/**
* The scope of the token
*/
scope: string
},
/**
* Cryptographic algorithm used to secure the JWT
* @default "RS256"
*/
alg?: string,
/**
* An object with keys and string values to be added to the header of the JWT.
*/
headerAdditions?: HeaderAdditions,
/**
* The crypto implementation to use. Use `null` to use the default implementation.
* @see https://w3c.github.io/webcrypto/#crypto-interface
* @default null
*/
cryptoImpl?: Crypto
}): Promise<string>
/**
* Generate a JWT from a service account JSON
*/
declare function getTokenFromGCPServiceAccount ({
serviceAccountJSON,
aud,
alg,
cryptoImpl,
headerAdditions,
payloadAdditions
}: {
/**
* Structure of a service account JSON
*/
serviceAccountJSON: {
type: string;
project_id: string;
private_key_id: string;
private_key: string;
client_email: string;
client_id: string;
auth_uri: string;
token_uri: string;
auth_provider_x509_cert_url: string;
client_x509_cert_url: string;
},
/**
* The API endpoint.
* @example https://<SERVICE>.googleapis.com/
*/
aud: string,
/**
* Cryptographic algorithm used to secure the JWT
* @default "RS256"
*/
alg?: string,
/**
* The crypto implementation to use. Use `null` to use the default implementation.
* @see https://w3c.github.io/webcrypto/#crypto-interface
* @default null
*/
cryptoImpl?: Crypto,
/**
* The time in seconds after the token was issued when the JWT expires
* @default 3600
*/
expiredAfter?: number,
/**
* An object with keys and string values to be added to the header of the JWT.
*/
headerAdditions?: HeaderAdditions,
/**
* an object with keys and string values to be added to the payload of the JWT.
* @example { scope: 'https://www.googleapis.com/auth/chat.bot' }
*/
payloadAdditions?: Record<string, any>
}): Promise<string>
export { getTokenFromGCPServiceAccount, getToken }
interface commonjsModule {
getTokenFromGCPServiceAccount,
getToken
}
export default commonjsModule;