@tachybase/plugin-auth-oidc 0.23.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.turbo/turbo-build.log +12 -0
  2. package/README.md +11 -0
  3. package/README.zh-CN.md +38 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/OIDCButton.d.ts +9 -0
  7. package/dist/client/Options.d.ts +2 -0
  8. package/dist/client/index.d.ts +5 -0
  9. package/dist/client/index.js +3 -0
  10. package/dist/client/locale/index.d.ts +3 -0
  11. package/dist/constants.d.ts +3 -0
  12. package/dist/constants.js +34 -0
  13. package/dist/externalVersion.js +14 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +39 -0
  16. package/dist/locale/en-US.json +40 -0
  17. package/dist/locale/es-ES.json +25 -0
  18. package/dist/locale/fr-FR.json +21 -0
  19. package/dist/locale/ko_KR.json +28 -0
  20. package/dist/locale/pt-BR.json +21 -0
  21. package/dist/locale/zh-CN.json +28 -0
  22. package/dist/node_modules/nanoid/.devcontainer.json +23 -0
  23. package/dist/node_modules/nanoid/LICENSE +20 -0
  24. package/dist/node_modules/nanoid/async/index.browser.cjs +69 -0
  25. package/dist/node_modules/nanoid/async/index.browser.js +69 -0
  26. package/dist/node_modules/nanoid/async/index.cjs +71 -0
  27. package/dist/node_modules/nanoid/async/index.d.ts +56 -0
  28. package/dist/node_modules/nanoid/async/index.js +71 -0
  29. package/dist/node_modules/nanoid/async/index.native.js +57 -0
  30. package/dist/node_modules/nanoid/async/package.json +12 -0
  31. package/dist/node_modules/nanoid/bin/nanoid.cjs +55 -0
  32. package/dist/node_modules/nanoid/index.browser.cjs +72 -0
  33. package/dist/node_modules/nanoid/index.browser.js +72 -0
  34. package/dist/node_modules/nanoid/index.cjs +1 -0
  35. package/dist/node_modules/nanoid/index.d.cts +91 -0
  36. package/dist/node_modules/nanoid/index.d.ts +91 -0
  37. package/dist/node_modules/nanoid/index.js +85 -0
  38. package/dist/node_modules/nanoid/nanoid.js +1 -0
  39. package/dist/node_modules/nanoid/non-secure/index.cjs +34 -0
  40. package/dist/node_modules/nanoid/non-secure/index.d.ts +33 -0
  41. package/dist/node_modules/nanoid/non-secure/index.js +34 -0
  42. package/dist/node_modules/nanoid/non-secure/package.json +6 -0
  43. package/dist/node_modules/nanoid/package.json +1 -0
  44. package/dist/node_modules/nanoid/url-alphabet/index.cjs +7 -0
  45. package/dist/node_modules/nanoid/url-alphabet/index.js +7 -0
  46. package/dist/node_modules/nanoid/url-alphabet/package.json +6 -0
  47. package/dist/node_modules/openid-client/lib/client.js +1884 -0
  48. package/dist/node_modules/openid-client/lib/device_flow_handle.js +125 -0
  49. package/dist/node_modules/openid-client/lib/errors.js +55 -0
  50. package/dist/node_modules/openid-client/lib/helpers/assert.js +24 -0
  51. package/dist/node_modules/openid-client/lib/helpers/base64url.js +13 -0
  52. package/dist/node_modules/openid-client/lib/helpers/client.js +208 -0
  53. package/dist/node_modules/openid-client/lib/helpers/consts.js +7 -0
  54. package/dist/node_modules/openid-client/lib/helpers/decode_jwt.js +27 -0
  55. package/dist/node_modules/openid-client/lib/helpers/deep_clone.js +1 -0
  56. package/dist/node_modules/openid-client/lib/helpers/defaults.js +27 -0
  57. package/dist/node_modules/openid-client/lib/helpers/generators.js +14 -0
  58. package/dist/node_modules/openid-client/lib/helpers/is_key_object.js +4 -0
  59. package/dist/node_modules/openid-client/lib/helpers/is_plain_object.js +1 -0
  60. package/dist/node_modules/openid-client/lib/helpers/issuer.js +111 -0
  61. package/dist/node_modules/openid-client/lib/helpers/keystore.js +298 -0
  62. package/dist/node_modules/openid-client/lib/helpers/merge.js +24 -0
  63. package/dist/node_modules/openid-client/lib/helpers/pick.js +9 -0
  64. package/dist/node_modules/openid-client/lib/helpers/process_response.js +71 -0
  65. package/dist/node_modules/openid-client/lib/helpers/request.js +200 -0
  66. package/dist/node_modules/openid-client/lib/helpers/unix_timestamp.js +1 -0
  67. package/dist/node_modules/openid-client/lib/helpers/weak_cache.js +1 -0
  68. package/dist/node_modules/openid-client/lib/helpers/webfinger_normalize.js +71 -0
  69. package/dist/node_modules/openid-client/lib/helpers/www_authenticate_parser.js +14 -0
  70. package/dist/node_modules/openid-client/lib/index.js +1 -0
  71. package/dist/node_modules/openid-client/lib/issuer.js +192 -0
  72. package/dist/node_modules/openid-client/lib/issuer_registry.js +3 -0
  73. package/dist/node_modules/openid-client/lib/passport_strategy.js +205 -0
  74. package/dist/node_modules/openid-client/lib/token_set.js +35 -0
  75. package/dist/node_modules/openid-client/package.json +1 -0
  76. package/dist/node_modules/openid-client/types/index.d.ts +623 -0
  77. package/dist/server/actions/getAuthUrl.d.ts +2 -0
  78. package/dist/server/actions/getAuthUrl.js +47 -0
  79. package/dist/server/actions/redirect.d.ts +2 -0
  80. package/dist/server/actions/redirect.js +55 -0
  81. package/dist/server/index.d.ts +1 -0
  82. package/dist/server/index.js +33 -0
  83. package/dist/server/migrations/20231007124508-update-autosignup.d.ts +6 -0
  84. package/dist/server/migrations/20231007124508-update-autosignup.js +52 -0
  85. package/dist/server/oidc-auth.d.ts +15 -0
  86. package/dist/server/oidc-auth.js +154 -0
  87. package/dist/server/plugin.d.ts +11 -0
  88. package/dist/server/plugin.js +83 -0
  89. package/dist/swagger/index.d.ts +143 -0
  90. package/dist/swagger/index.js +178 -0
  91. package/package.json +37 -0
  92. package/server.d.ts +2 -0
  93. package/server.js +1 -0
@@ -0,0 +1,623 @@
1
+ /// <reference types="node" />
2
+ // TypeScript Version: 3.6
3
+
4
+ import * as http from 'http';
5
+ import * as https from 'https';
6
+ import * as http2 from 'http2';
7
+
8
+ import { URL } from 'url';
9
+ import * as jose from 'jose';
10
+ import * as crypto from 'crypto';
11
+ import { format } from 'util';
12
+
13
+ export type HttpOptions = Partial<
14
+ Pick<
15
+ https.RequestOptions,
16
+ | 'agent'
17
+ | 'ca'
18
+ | 'cert'
19
+ | 'crl'
20
+ | 'headers'
21
+ | 'key'
22
+ | 'lookup'
23
+ | 'passphrase'
24
+ | 'pfx'
25
+ | 'timeout'
26
+ >
27
+ >;
28
+ export type RetryFunction = (retry: number, error: Error) => number;
29
+ export type CustomHttpOptionsProvider = (
30
+ url: URL,
31
+ options: Omit<https.RequestOptions, keyof URL>,
32
+ ) => HttpOptions;
33
+ export type TokenTypeHint = 'access_token' | 'refresh_token' | string;
34
+ export type DPoPInput = crypto.KeyObject | Parameters<typeof crypto.createPrivateKey>[0];
35
+
36
+ interface UnknownObject {
37
+ [key: string]: unknown;
38
+ }
39
+
40
+ export const custom: {
41
+ setHttpOptionsDefaults(params: HttpOptions): undefined;
42
+ readonly http_options: unique symbol;
43
+ readonly clock_tolerance: unique symbol;
44
+ };
45
+
46
+ export type ResponseType = 'code' | 'id_token' | 'code id_token' | 'none' | string;
47
+ export type ClientAuthMethod =
48
+ | 'client_secret_basic'
49
+ | 'client_secret_post'
50
+ | 'client_secret_jwt'
51
+ | 'private_key_jwt'
52
+ | 'tls_client_auth'
53
+ | 'self_signed_tls_client_auth'
54
+ | 'none';
55
+
56
+ export interface ClientMetadata {
57
+ // important
58
+ client_id: string;
59
+ id_token_signed_response_alg?: string;
60
+ token_endpoint_auth_method?: ClientAuthMethod;
61
+ client_secret?: string;
62
+ redirect_uris?: string[];
63
+ response_types?: ResponseType[];
64
+ post_logout_redirect_uris?: string[];
65
+ default_max_age?: number;
66
+ require_auth_time?: boolean;
67
+ tls_client_certificate_bound_access_tokens?: boolean;
68
+ request_object_signing_alg?: string;
69
+
70
+ // less important
71
+ id_token_encrypted_response_alg?: string;
72
+ id_token_encrypted_response_enc?: string;
73
+ introspection_endpoint_auth_method?: ClientAuthMethod;
74
+ introspection_endpoint_auth_signing_alg?: string;
75
+ request_object_encryption_alg?: string;
76
+ request_object_encryption_enc?: string;
77
+ revocation_endpoint_auth_method?: ClientAuthMethod;
78
+ revocation_endpoint_auth_signing_alg?: string;
79
+ token_endpoint_auth_signing_alg?: string;
80
+ userinfo_encrypted_response_alg?: string;
81
+ userinfo_encrypted_response_enc?: string;
82
+ userinfo_signed_response_alg?: string;
83
+ authorization_encrypted_response_alg?: string;
84
+ authorization_encrypted_response_enc?: string;
85
+ authorization_signed_response_alg?: string;
86
+
87
+ [key: string]: unknown;
88
+ }
89
+
90
+ export interface ClaimsParameterMember {
91
+ essential?: boolean;
92
+ value?: string;
93
+ values?: string[];
94
+
95
+ [key: string]: unknown;
96
+ }
97
+
98
+ export interface AuthorizationParameters {
99
+ acr_values?: string;
100
+ audience?: string;
101
+ claims?:
102
+ | string
103
+ | {
104
+ id_token?: {
105
+ [key: string]: null | ClaimsParameterMember;
106
+ };
107
+ userinfo?: {
108
+ [key: string]: null | ClaimsParameterMember;
109
+ };
110
+ };
111
+ claims_locales?: string;
112
+ client_id?: string;
113
+ code_challenge_method?: string;
114
+ code_challenge?: string;
115
+ display?: string;
116
+ id_token_hint?: string;
117
+ login_hint?: string;
118
+ max_age?: number;
119
+ nonce?: string;
120
+ prompt?: string;
121
+ redirect_uri?: string;
122
+ registration?: string;
123
+ request_uri?: string;
124
+ request?: string;
125
+ resource?: string | string[];
126
+ response_mode?: string;
127
+ response_type?: string;
128
+ scope?: string;
129
+ state?: string;
130
+ ui_locales?: string;
131
+
132
+ [key: string]: unknown;
133
+ }
134
+
135
+ export interface EndSessionParameters {
136
+ id_token_hint?: TokenSet | string;
137
+ post_logout_redirect_uri?: string;
138
+ state?: string;
139
+ client_id?: string;
140
+ logout_hint?: string;
141
+
142
+ [key: string]: unknown;
143
+ }
144
+
145
+ export interface CallbackParamsType {
146
+ access_token?: string;
147
+ code?: string;
148
+ error?: string;
149
+ error_description?: string;
150
+ error_uri?: string;
151
+ expires_in?: string;
152
+ id_token?: string;
153
+ state?: string;
154
+ token_type?: string;
155
+ session_state?: string;
156
+ response?: string;
157
+
158
+ [key: string]: unknown;
159
+ }
160
+
161
+ export interface OAuthCallbackChecks {
162
+ response_type?: string;
163
+ state?: string;
164
+ code_verifier?: string;
165
+ jarm?: boolean;
166
+ scope?: string; // TODO: remove in v6.x
167
+ }
168
+
169
+ export interface OpenIDCallbackChecks extends OAuthCallbackChecks {
170
+ max_age?: number;
171
+ nonce?: string;
172
+ }
173
+
174
+ export interface CallbackExtras {
175
+ exchangeBody?: object;
176
+ clientAssertionPayload?: object;
177
+ DPoP?: DPoPInput;
178
+ }
179
+
180
+ export interface RefreshExtras {
181
+ exchangeBody?: object;
182
+ clientAssertionPayload?: object;
183
+ DPoP?: DPoPInput;
184
+ }
185
+
186
+ export interface GrantBody {
187
+ grant_type: string;
188
+
189
+ [key: string]: unknown;
190
+ }
191
+
192
+ export interface GrantExtras {
193
+ clientAssertionPayload?: object;
194
+ DPoP?: DPoPInput;
195
+ }
196
+
197
+ export interface IntrospectExtras {
198
+ introspectBody?: object;
199
+ clientAssertionPayload?: object;
200
+ }
201
+
202
+ export interface RevokeExtras {
203
+ revokeBody?: object;
204
+ clientAssertionPayload?: object;
205
+ }
206
+
207
+ export interface RequestObjectPayload extends AuthorizationParameters {
208
+ client_id?: string;
209
+ iss?: string;
210
+ aud?: string;
211
+ iat?: number;
212
+ exp?: number;
213
+ jti?: string;
214
+
215
+ [key: string]: unknown;
216
+ }
217
+
218
+ export interface RegisterOther {
219
+ jwks?: { keys: jose.JWK[] };
220
+ initialAccessToken?: string;
221
+ }
222
+
223
+ export interface DeviceAuthorizationParameters {
224
+ client_id?: string;
225
+ scope?: string;
226
+
227
+ [key: string]: unknown;
228
+ }
229
+
230
+ export interface DeviceAuthorizationExtras {
231
+ exchangeBody?: object;
232
+ clientAssertionPayload?: object;
233
+ DPoP?: DPoPInput;
234
+ }
235
+
236
+ export interface PushedAuthorizationRequestExtras {
237
+ clientAssertionPayload?: object;
238
+ }
239
+
240
+ export type Address<ExtendedAddress extends {} = UnknownObject> = Override<
241
+ {
242
+ formatted?: string;
243
+ street_address?: string;
244
+ locality?: string;
245
+ region?: string;
246
+ postal_code?: string;
247
+ country?: string;
248
+ },
249
+ ExtendedAddress
250
+ >;
251
+
252
+ export type UserinfoResponse<
253
+ UserInfo extends {} = UnknownObject,
254
+ ExtendedAddress extends {} = UnknownObject,
255
+ > = Override<
256
+ {
257
+ sub: string;
258
+ name?: string;
259
+ given_name?: string;
260
+ family_name?: string;
261
+ middle_name?: string;
262
+ nickname?: string;
263
+ preferred_username?: string;
264
+ profile?: string;
265
+ picture?: string;
266
+ website?: string;
267
+ email?: string;
268
+ email_verified?: boolean;
269
+ gender?: string;
270
+ birthdate?: string;
271
+ zoneinfo?: string;
272
+ locale?: string;
273
+ phone_number?: string;
274
+ updated_at?: number;
275
+ address?: Address<ExtendedAddress>;
276
+ },
277
+ UserInfo
278
+ >;
279
+
280
+ export interface IntrospectionResponse {
281
+ active: boolean;
282
+ client_id?: string;
283
+ exp?: number;
284
+ iat?: number;
285
+ sid?: string;
286
+ iss?: string;
287
+ jti?: string;
288
+ username?: string;
289
+ aud?: string | string[];
290
+ scope: string;
291
+ sub?: string;
292
+ nbf?: number;
293
+ token_type?: string;
294
+ cnf?: {
295
+ 'x5t#S256'?: string;
296
+
297
+ [key: string]: unknown;
298
+ };
299
+
300
+ [key: string]: unknown;
301
+ }
302
+
303
+ export interface ClientOptions {
304
+ additionalAuthorizedParties?: string | string[];
305
+ }
306
+
307
+ export type Client = InstanceType<Issuer['Client']>;
308
+ declare class BaseClient {
309
+ constructor(metadata: ClientMetadata, jwks?: { keys: jose.JWK[] }, options?: ClientOptions);
310
+ [custom.http_options]: CustomHttpOptionsProvider;
311
+ [custom.clock_tolerance]: number;
312
+ metadata: ClientMetadata;
313
+ issuer: Issuer<this>;
314
+ static issuer: Issuer<BaseClient>;
315
+
316
+ authorizationUrl(parameters?: AuthorizationParameters): string;
317
+ endSessionUrl(parameters?: EndSessionParameters): string;
318
+ callbackParams(
319
+ input: string | http.IncomingMessage | http2.Http2ServerRequest,
320
+ ): CallbackParamsType;
321
+ callback(
322
+ redirectUri: string | undefined,
323
+ parameters: CallbackParamsType,
324
+ checks?: OpenIDCallbackChecks,
325
+ extras?: CallbackExtras,
326
+ ): Promise<TokenSet>;
327
+ oauthCallback(
328
+ redirectUri: string | undefined,
329
+ parameters: CallbackParamsType,
330
+ checks?: OAuthCallbackChecks,
331
+ extras?: CallbackExtras,
332
+ ): Promise<TokenSet>;
333
+ refresh(refreshToken: TokenSet | string, extras?: RefreshExtras): Promise<TokenSet>;
334
+ userinfo<TUserInfo extends {} = UnknownObject, TAddress extends {} = UnknownObject>(
335
+ accessToken: TokenSet | string,
336
+ options?: {
337
+ method?: 'GET' | 'POST';
338
+ via?: 'header' | 'body';
339
+ tokenType?: string;
340
+ params?: object;
341
+ DPoP?: DPoPInput;
342
+ },
343
+ ): Promise<UserinfoResponse<TUserInfo, TAddress>>;
344
+ requestResource(
345
+ resourceUrl: string | URL,
346
+ accessToken: TokenSet | string,
347
+ options?: {
348
+ headers?: object;
349
+ body?: string | Buffer;
350
+ method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'PATCH';
351
+ tokenType?: string;
352
+ DPoP?: DPoPInput;
353
+ },
354
+ ): Promise<{ body?: Buffer } & http.IncomingMessage>;
355
+ grant(body: GrantBody, extras?: GrantExtras): Promise<TokenSet>;
356
+ introspect(
357
+ token: string,
358
+ tokenTypeHint?: TokenTypeHint,
359
+ extras?: IntrospectExtras,
360
+ ): Promise<IntrospectionResponse>;
361
+ revoke(token: string, tokenTypeHint?: TokenTypeHint, extras?: RevokeExtras): Promise<undefined>;
362
+ requestObject(payload: RequestObjectPayload): Promise<string>;
363
+ deviceAuthorization(
364
+ parameters?: DeviceAuthorizationParameters,
365
+ extras?: DeviceAuthorizationExtras,
366
+ ): Promise<DeviceFlowHandle<BaseClient>>;
367
+ pushedAuthorizationRequest(
368
+ parameters?: AuthorizationParameters,
369
+ extras?: PushedAuthorizationRequestExtras,
370
+ ): Promise<{
371
+ request_uri: string;
372
+ expires_in: number;
373
+ [key: string]: unknown;
374
+ }>;
375
+ static register(metadata: object, other?: RegisterOther & ClientOptions): Promise<BaseClient>;
376
+ static fromUri(
377
+ registrationClientUri: string,
378
+ registrationAccessToken: string,
379
+ jwks?: { keys: jose.JWK[] },
380
+ clientOptions?: ClientOptions,
381
+ ): Promise<BaseClient>;
382
+ static [custom.http_options]: CustomHttpOptionsProvider;
383
+
384
+ [key: string]: unknown;
385
+ }
386
+
387
+ interface DeviceFlowPollOptions {
388
+ // @ts-ignore
389
+ signal?: AbortSignal;
390
+ }
391
+
392
+ export class DeviceFlowHandle<TClient extends BaseClient = BaseClient> {
393
+ poll(options?: DeviceFlowPollOptions): Promise<TokenSet>;
394
+ abort(): void;
395
+ expired(): boolean;
396
+ expires_at: number;
397
+ client: TClient;
398
+ user_code: string;
399
+ device_code: string;
400
+ verification_uri: string;
401
+ verification_uri_complete: string;
402
+ expires_in: number;
403
+ }
404
+
405
+ export interface IssuerMetadata {
406
+ issuer: string;
407
+ authorization_endpoint?: string;
408
+ token_endpoint?: string;
409
+ jwks_uri?: string;
410
+ userinfo_endpoint?: string;
411
+ revocation_endpoint?: string;
412
+ end_session_endpoint?: string;
413
+ registration_endpoint?: string;
414
+ token_endpoint_auth_methods_supported?: string[];
415
+ token_endpoint_auth_signing_alg_values_supported?: string[];
416
+ introspection_endpoint_auth_methods_supported?: string[];
417
+ introspection_endpoint_auth_signing_alg_values_supported?: string[];
418
+ revocation_endpoint_auth_methods_supported?: string[];
419
+ revocation_endpoint_auth_signing_alg_values_supported?: string[];
420
+ request_object_signing_alg_values_supported?: string[];
421
+ mtls_endpoint_aliases?: MtlsEndpointAliases;
422
+
423
+ [key: string]: unknown;
424
+ }
425
+
426
+ export interface MtlsEndpointAliases {
427
+ token_endpoint?: string;
428
+ userinfo_endpoint?: string;
429
+ revocation_endpoint?: string;
430
+ introspection_endpoint?: string;
431
+ device_authorization_endpoint?: string;
432
+ }
433
+
434
+ export interface TypeOfGenericClient<TClient extends BaseClient = BaseClient> {
435
+ new (metadata: ClientMetadata, jwks?: { keys: jose.JWK[] }, options?: ClientOptions): TClient;
436
+ [custom.http_options]: CustomHttpOptionsProvider;
437
+ [custom.clock_tolerance]: number;
438
+ }
439
+
440
+ export class Issuer<TClient extends BaseClient = BaseClient> {
441
+ constructor(metadata: IssuerMetadata);
442
+
443
+ Client: TypeOfGenericClient<TClient>;
444
+
445
+ FAPI1Client: TypeOfGenericClient<TClient>;
446
+ FAPI2Client: TypeOfGenericClient<TClient>;
447
+
448
+ metadata: IssuerMetadata;
449
+ [custom.http_options]: CustomHttpOptionsProvider;
450
+ static discover(issuer: string): Promise<Issuer<BaseClient>>;
451
+ static webfinger(input: string): Promise<Issuer<BaseClient>>;
452
+ static [custom.http_options]: CustomHttpOptionsProvider;
453
+ [key: string]: unknown;
454
+ }
455
+
456
+ export interface TokenSetParameters {
457
+ access_token?: string;
458
+ token_type?: string;
459
+ id_token?: string;
460
+ refresh_token?: string;
461
+ scope?: string;
462
+
463
+ expires_at?: number;
464
+ session_state?: string;
465
+
466
+ [key: string]: unknown;
467
+ }
468
+
469
+ export interface IdTokenClaims extends UserinfoResponse {
470
+ acr?: string;
471
+ amr?: string[];
472
+ at_hash?: string;
473
+ aud: string | string[];
474
+ auth_time?: number;
475
+ azp?: string;
476
+ c_hash?: string;
477
+ exp: number;
478
+ iat: number;
479
+ iss: string;
480
+ nonce?: string;
481
+ s_hash?: string;
482
+ sub: string;
483
+
484
+ [key: string]: unknown;
485
+ }
486
+
487
+ export class TokenSet implements TokenSetParameters {
488
+ access_token?: string;
489
+ token_type?: string;
490
+ id_token?: string;
491
+ refresh_token?: string;
492
+ expires_in?: number;
493
+ expires_at?: number;
494
+ session_state?: string;
495
+ scope?: string;
496
+
497
+ constructor(input?: TokenSetParameters);
498
+
499
+ expired(): boolean;
500
+ claims(): IdTokenClaims;
501
+
502
+ [key: string]: unknown;
503
+ }
504
+
505
+ export type StrategyVerifyCallbackUserInfo<
506
+ TUser,
507
+ TUserInfo extends {} = UnknownObject,
508
+ TAddress extends {} = UnknownObject,
509
+ > = (
510
+ tokenset: TokenSet,
511
+ userinfo: UserinfoResponse<TUserInfo, TAddress>,
512
+ done: (err: any, user?: TUser) => void,
513
+ ) => void;
514
+ export type StrategyVerifyCallback<TUser> = (
515
+ tokenset: TokenSet,
516
+ done: (err: any, user?: TUser) => void,
517
+ ) => void;
518
+ export type StrategyVerifyCallbackReqUserInfo<
519
+ TUser,
520
+ TUserInfo extends {} = UnknownObject,
521
+ TAddress extends {} = UnknownObject,
522
+ > = (
523
+ req: http.IncomingMessage,
524
+ tokenset: TokenSet,
525
+ userinfo: UserinfoResponse<TUserInfo, TAddress>,
526
+ done: (err: any, user?: TUser) => void,
527
+ ) => void;
528
+ export type StrategyVerifyCallbackReq<TUser> = (
529
+ req: http.IncomingMessage,
530
+ tokenset: TokenSet,
531
+ done: (err: any, user?: TUser) => void,
532
+ ) => void;
533
+
534
+ export interface StrategyOptions<TClient extends BaseClient = BaseClient> {
535
+ client: TClient;
536
+ params?: AuthorizationParameters;
537
+ extras?: CallbackExtras;
538
+ passReqToCallback?: boolean;
539
+ usePKCE?: boolean | string;
540
+ sessionKey?: string;
541
+ }
542
+
543
+ export class Strategy<TUser, TClient extends BaseClient = BaseClient> {
544
+ constructor(
545
+ options: StrategyOptions<TClient>,
546
+ verify:
547
+ | StrategyVerifyCallback<TUser>
548
+ | StrategyVerifyCallbackUserInfo<TUser>
549
+ | StrategyVerifyCallbackReq<TUser>
550
+ | StrategyVerifyCallbackReqUserInfo<TUser>,
551
+ );
552
+
553
+ authenticate(req: any, options?: any): void;
554
+ success(user: any, info?: any): void;
555
+ fail(challenge: any, status: number): void;
556
+ fail(status: number): void;
557
+ redirect(url: string, status?: number): void;
558
+ pass(): void;
559
+ error(err: Error): void;
560
+ }
561
+
562
+ export namespace generators {
563
+ function random(bytes?: number): string;
564
+ function state(bytes?: number): string;
565
+ function nonce(bytes?: number): string;
566
+ function codeVerifier(bytes?: number): string;
567
+ function codeChallenge(verifier: string): string;
568
+ }
569
+
570
+ export namespace errors {
571
+ class OPError extends Error {
572
+ error_description?: string;
573
+ error?: string;
574
+ error_uri?: string;
575
+ state?: string;
576
+ scope?: string;
577
+ session_state?: string;
578
+ response?: { body?: UnknownObject | Buffer } & http.IncomingMessage;
579
+
580
+ constructor(
581
+ params: {
582
+ error: string;
583
+ error_description?: string;
584
+ error_uri?: string;
585
+ state?: string;
586
+ scope?: string;
587
+ session_state?: string;
588
+ },
589
+ response?: { body?: UnknownObject | Buffer } & http.IncomingMessage,
590
+ );
591
+ }
592
+
593
+ class RPError extends Error {
594
+ jwt?: string;
595
+ checks?: object;
596
+ params?: object;
597
+ body?: object;
598
+ response?: { body?: UnknownObject | Buffer } & http.IncomingMessage;
599
+ now?: number;
600
+ tolerance?: number;
601
+ nbf?: number;
602
+ exp?: number;
603
+ iat?: number;
604
+ auth_time?: number;
605
+
606
+ constructor(...args: Parameters<typeof format>);
607
+ constructor(options: {
608
+ message?: string;
609
+ printf?: Parameters<typeof format>;
610
+ response?: { body?: UnknownObject | Buffer } & http.IncomingMessage;
611
+ [key: string]: unknown;
612
+ });
613
+ }
614
+ }
615
+
616
+ type KnownKeys<T> = {
617
+ [K in keyof T]: string extends K ? never : number extends K ? never : K;
618
+ } extends { [_ in keyof T]: infer U }
619
+ ? {} extends U
620
+ ? never
621
+ : U
622
+ : never;
623
+ type Override<T1, T2> = Omit<T1, keyof Omit<T2, keyof KnownKeys<T2>>> & T2;
@@ -0,0 +1,2 @@
1
+ import { Context, Next } from '@tachybase/actions';
2
+ export declare const getAuthUrl: (ctx: Context, next: Next) => Promise<any>;
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var getAuthUrl_exports = {};
19
+ __export(getAuthUrl_exports, {
20
+ getAuthUrl: () => getAuthUrl
21
+ });
22
+ module.exports = __toCommonJS(getAuthUrl_exports);
23
+ var import_nanoid = require("nanoid");
24
+ var import_constants = require("../../constants");
25
+ const getAuthUrl = async (ctx, next) => {
26
+ const { redirect = "" } = ctx.action.params.values || {};
27
+ const app = ctx.app.name;
28
+ const auth = ctx.auth;
29
+ const client = await auth.createOIDCClient();
30
+ const { scope, stateToken } = auth.getOptions();
31
+ const token = stateToken || (0, import_nanoid.nanoid)(15);
32
+ ctx.cookies.set(import_constants.cookieName, token, {
33
+ httpOnly: true,
34
+ domain: ctx.hostname
35
+ });
36
+ ctx.body = client.authorizationUrl({
37
+ response_type: "code",
38
+ scope: scope || "openid email profile",
39
+ redirect_uri: `${auth.getRedirectUri()}`,
40
+ state: encodeURIComponent(`token=${token}&name=${ctx.headers["x-authenticator"]}&app=${app}&redirect=${redirect}`)
41
+ });
42
+ return next();
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ getAuthUrl
47
+ });
@@ -0,0 +1,2 @@
1
+ import { Context, Next } from '@tachybase/actions';
2
+ export declare const redirect: (ctx: Context, next: Next) => Promise<void>;