forked from simov/grant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grant.d.ts
442 lines (418 loc) · 9.1 KB
/
grant.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
import {
RequestOptions as RequestComposeOptions,
} from 'request-compose'
// ----------------------------------------------------------------------------
/**
* Grant options
*/
export interface GrantOptions {
/**
* Handler name
*/
handler?: 'express' | 'koa' | 'hapi' | 'fastify' | 'curveball' |
'node' | 'aws' | 'azure' | 'gcloud' | 'vercel'
/**
* Grant configuration
*/
config?: GrantConfig
/**
* HTTP client options
*/
request?: RequestComposeOptions
/**
* Grant session options
*/
session?: GrantSessionConfig
// exclude
defaults?: never
}
/**
* Grant config
*/
export interface GrantConfig {
/**
* Default configuration for all providers
*/
defaults?: GrantProvider
/**
* Provider configuration
*/
[provider: string]: GrantProvider | undefined
// exclude
handler?: never
config?: never
request?: never
session?: never
}
/**
* Grant provider
*/
export interface GrantProvider {
// Authorization Server
/**
* OAuth 1.0a only, first step
*/
request_url?: string
/**
* OAuth 2.0 first step, OAuth 1.0a second step
*/
authorize_url?: string
/**
* OAuth 2.0 second step, OAuth 1.0a third step
*/
access_url?: string
/**
* OAuth version number
*/
oauth?: number
/**
* String delimiter used for concatenating multiple scopes
*/
scope_delimiter?: string
/**
* Authentication method for the token endpoint
*/
token_endpoint_auth_method?: string
/**
* Signing algorithm for the token endpoint
*/
token_endpoint_auth_signing_alg?: string
// Client Server
/**
* Where your client server can be reached
*/
origin?: string
/**
* Path prefix for the Grant internal routes
*/
prefix?: string
/**
* Random state string for OAuth 2.0
*/
state?: boolean | string
/**
* Random nonce string for OpenID Connect
*/
nonce?: boolean | string
/**
* Toggle PKCE support
*/
pkce?: boolean
/**
* Response data to receive
*/
response?: string[]
/**
* Transport type to deliver the response data
*/
transport?: string
/**
* Relative or absolute URL to receive the response data
*/
callback?: string
/**
* Static configuration overrides for a provider
*/
overrides?: {
[key: string]: Omit<GrantProvider, 'overrides'>
}
/**
* Configuration keys that can be overridden dynamically over HTTP
*/
dynamic?: boolean | string[]
// Client App
/**
* The client_id or consumer_key of your OAuth app
*/
key?: string
/**
* The client_id or consumer_key of your OAuth app
*/
client_id?: string
/**
* The client_id or consumer_key of your OAuth app
*/
consumer_key?: string
/**
* The client_secret or consumer_secret of your OAuth app
*/
secret?: string
/**
* The client_secret or consumer_secret of your OAuth app
*/
client_secret?: string
/**
* The client_secret or consumer_secret of your OAuth app
*/
consumer_secret?: string
/**
* List of scopes to request
*/
scope?: string | string[]
/**
* Custom authorization parameters and their values
*/
custom_params?: any
/**
* String to embed into the authorization server URLs
*/
subdomain?: string
/**
* Public PEM or JWK
*/
public_key?: any
/**
* Private PEM or JWK
*/
private_key?: any
/**
* Absolute redirect URL of the OAuth app
*/
redirect_uri?: string
/**
* User profile URL
*/
profile_url?: string
}
/**
* Grant session config
*/
export interface GrantSessionConfig {
/**
* Cookie name
*/
name?: string
/**
* Cookie secret
*/
secret: string
/**
* Cookie options
*/
cookie?: any
/**
* Session store
*/
store?: GrantSessionStore
}
/**
* Grant session store
*/
export interface GrantSessionStore {
/**
* Get item from session store
*/
get: (sid: string) => any
/**
* Set item in session store
*/
set: (sid: string, json: any) => void
/**
* Remove item from session store
*/
remove?: (sid: string) => void
}
// ----------------------------------------------------------------------------
/**
* Grant instance
*/
export interface GrantInstance {
/**
* Grant instance configuration
*/
config: any
}
/**
* Grant handler
*/
export type GrantHandler = (
/**
* Request object
*/
req: any,
/**
* Response object
*/
res?: any,
/**
* Grant dynamic state overrides
*/
state?: {dynamic: GrantProvider}
) => Promise<GrantHandlerResult>
/**
* Grant handler result
*/
export interface GrantHandlerResult {
/**
* Grant session store instance
*/
session: GrantSessionStore
/**
* HTTP redirect
*/
redirect?: any
/**
* Grant response
*/
response?: GrantResponse
}
// ----------------------------------------------------------------------------
/**
* Grant session
*/
export interface GrantSession {
/**
* The provider name used for this authorization
*/
provider: string
/**
* The static override name used for this authorization
*/
override?: string
/**
* The dynamic override configuration passed to this authorization
*/
dynamic?: any
/**
* OAuth 2.0 state string that was generated
*/
state?: string
/**
* OpenID Connect nonce string that was generated
*/
nonce?: string
/**
* The code verifier that was generated for PKCE
*/
code_verifier?: string
/**
* Data returned from the first request of the OAuth 1.0a flow
*/
request?: string
/**
* The final response data
*/
response?: GrantResponse
}
/**
* Grant response
*/
export interface GrantResponse {
/**
* OAuth 2.0 and OAuth 1.0a access secret
*/
access_token?: string
/**
* OAuth 2.0 refresh token
*/
refresh_token?: string
/**
* OpenID Connect id token
*/
id_token?: string
/**
* OAuth 1.0a access secret
*/
access_secret?: string
/**
* Raw response data
*/
raw?: any
/**
* Parsed id_token JWT
*/
jwt?: {
id_token?: {header: any, payload: any, signature: string}
}
/**
* User profile response
*/
profile?: any
/**
* Error response
*/
error?: any
}
// ----------------------------------------------------------------------------
/**
* Express middleware
*/
export type ExpressMiddleware = () => Promise<void>
/**
* Koa middleware
*/
export type KoaMiddleware = (ctx: any, next?: () => Promise<void>) => Promise<void>
/**
* Hapi middleware
*/
export interface HapiMiddleware {register: (server: any, options?: any) => void, pkg: any}
/**
* Fastify middleware
*/
export type FastifyMiddleware = (server: any, options: any, next: () => void) => void
/**
* Curveball middleware
*/
export type CurveballMiddleware = (ctx: any, next?: () => Promise<void>) => Promise<void>
// ----------------------------------------------------------------------------
/**
* Grant OAuth Proxy
*/
declare function grant(): (config: GrantConfig | GrantOptions) => any
declare function grant(config: GrantConfig | GrantOptions): any
/**
* Grant OAuth Proxy
*/
declare namespace grant {
/**
* Express handler
*/
function express(): (config: GrantConfig | GrantOptions) => ExpressMiddleware & GrantInstance
function express(config: GrantConfig | GrantOptions): ExpressMiddleware & GrantInstance
/**
* Koa handler
*/
function koa(): (config: GrantConfig | GrantOptions) => KoaMiddleware & GrantInstance
function koa(config: GrantConfig | GrantOptions): KoaMiddleware & GrantInstance
/**
* Hapi handler
*/
function hapi(): (config: GrantConfig | GrantOptions) => HapiMiddleware & GrantInstance
function hapi(config: GrantConfig | GrantOptions): HapiMiddleware & GrantInstance
/**
* Fastify handler
*/
function fastify(): (config: GrantConfig | GrantOptions) => FastifyMiddleware & GrantInstance
function fastify(config: GrantConfig | GrantOptions): FastifyMiddleware & GrantInstance
/**
* Curveball handler
*/
function curveball(): (config: GrantConfig | GrantOptions) => CurveballMiddleware & GrantInstance
function curveball(config: GrantConfig | GrantOptions): CurveballMiddleware & GrantInstance
/**
* Node handler
*/
function node(): (config: GrantConfig | GrantOptions) => GrantHandler & GrantInstance
function node(config: GrantConfig | GrantOptions): GrantHandler & GrantInstance
/**
* AWS Lambda handler
*/
function aws(): (config: GrantConfig | GrantOptions) => GrantHandler & GrantInstance
function aws(config: GrantConfig | GrantOptions): GrantHandler & GrantInstance
/**
* Azure Function handler
*/
function azure(): (config: GrantConfig | GrantOptions) => GrantHandler & GrantInstance
function azure(config: GrantConfig | GrantOptions): GrantHandler & GrantInstance
/**
* Google Cloud Function handler
*/
function gcloud(): (config: GrantConfig | GrantOptions) => GrantHandler & GrantInstance
function gcloud(config: GrantConfig | GrantOptions): GrantHandler & GrantInstance
/**
* Vercel Function handler
*/
function vercel(): (config: GrantConfig | GrantOptions) => GrantHandler & GrantInstance
function vercel(config: GrantConfig | GrantOptions): GrantHandler & GrantInstance
}
export default grant