alepha 0.9.2 → 0.9.4

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.
package/react/auth.d.ts CHANGED
@@ -1,187 +1,496 @@
1
- import * as _alepha_core0$1 from "alepha";
2
1
  import * as _alepha_core4 from "alepha";
3
- import * as _alepha_core0 from "alepha";
4
- import { Alepha, Async, Descriptor, KIND } from "alepha";
5
- import * as _alepha_server_cookies0 from "alepha/server/cookies";
2
+ import { Alepha, AlephaError, Async, Descriptor, KIND, Static } from "alepha";
3
+ import * as _alepha_server_cookies1 from "alepha/server/cookies";
6
4
  import { Cookies, ServerCookiesProvider } from "alepha/server/cookies";
5
+ import { DateTimeProvider } from "alepha/datetime";
6
+ import { AccessTokenResponse, RealmDescriptor, SecurityProvider, UserAccount, UserAccountToken } from "alepha/security";
7
+ import { Configuration } from "openid-client";
8
+ import * as _alepha_logger0 from "alepha/logger";
7
9
  import * as _alepha_server0 from "alepha/server";
8
10
  import { HttpClient } from "alepha/server";
9
- import { Configuration } from "openid-client";
10
- import { HttpVirtualClient } from "alepha/server/links";
11
- import { UserAccountToken } from "alepha/security";
12
- import * as _sinclair_typebox0 from "@sinclair/typebox";
11
+ import { HttpVirtualClient, LinkProvider, ServerLinksProvider } from "alepha/server/links";
12
+ import * as _sinclair_typebox156 from "@sinclair/typebox";
13
13
 
14
- //#region src/descriptors/$auth.d.ts
15
- declare const $auth: {
16
- (options: AuthDescriptorOptions): AuthDescriptor;
17
- [KIND]: typeof AuthDescriptor;
18
- };
19
- interface AuthDescriptorOptions {
20
- name?: string;
21
- fallback?: () => Async<AccessToken>;
22
- oidc?: {
23
- issuer: string;
24
- clientId: string;
25
- clientSecret?: string;
26
- redirectUri?: string;
27
- useIdToken?: boolean;
28
- logoutUri?: string;
14
+ //#region src/schemas/tokensSchema.d.ts
15
+ declare const tokensSchema: _sinclair_typebox156.TObject<{
16
+ provider: _sinclair_typebox156.TString;
17
+ access_token: _sinclair_typebox156.TString;
18
+ issued_at: _sinclair_typebox156.TNumber;
19
+ expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
20
+ refresh_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
21
+ refresh_token_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
22
+ refresh_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
23
+ id_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
24
+ scope: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
25
+ token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
26
+ realm: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
27
+ }>;
28
+ type Tokens = Static<typeof tokensSchema>;
29
+ //#endregion
30
+ //#region src/services/ReactAuth.d.ts
31
+ /**
32
+ * Browser, SSR friendly, service to handle authentication.
33
+ */
34
+ declare class ReactAuth {
35
+ protected readonly log: _alepha_logger0.Logger;
36
+ protected readonly alepha: Alepha;
37
+ protected readonly linkProvider: LinkProvider;
38
+ protected readonly httpClient: HttpClient;
39
+ static path: {
40
+ login: string;
41
+ callback: string;
42
+ logout: string;
43
+ token: string;
44
+ refresh: string;
45
+ userinfo: string;
29
46
  };
47
+ protected readonly onBeginTransition: _alepha_core4.HookDescriptor<"react:transition:begin">;
48
+ csrfCookie: _alepha_server_cookies1.AbstractCookieDescriptor<_sinclair_typebox156.TString>;
49
+ protected readonly onFetchRequest: _alepha_core4.HookDescriptor<"client:onRequest">;
50
+ get user(): UserAccountToken | undefined;
51
+ ping(): Promise<{
52
+ name?: string | undefined;
53
+ email?: string | undefined;
54
+ username?: string | undefined;
55
+ picture?: string | undefined;
56
+ sessionId?: string | undefined;
57
+ organizations?: string[] | undefined;
58
+ roles?: string[] | undefined;
59
+ id: string;
60
+ } | undefined>;
61
+ login(provider: string, options: {
62
+ hostname?: string;
63
+ username?: string;
64
+ password?: string;
65
+ redirect?: string;
66
+ [extra: string]: any;
67
+ }): Promise<Tokens>;
68
+ logout(): void;
30
69
  }
31
- declare class AuthDescriptor extends Descriptor<AuthDescriptorOptions> {
32
- get name(): string;
33
- jwks(): string;
34
- }
35
- type AccessToken = string;
36
- //# sourceMappingURL=$auth.d.ts.map
37
70
  //#endregion
38
71
  //#region src/providers/ReactAuthProvider.d.ts
39
72
  declare class ReactAuthProvider {
40
- protected readonly log: _alepha_core0$1.Logger;
73
+ protected readonly log: _alepha_logger0.Logger;
41
74
  protected readonly alepha: Alepha;
42
75
  protected readonly serverCookiesProvider: ServerCookiesProvider;
43
- protected authProviders: AuthProvider[];
44
- protected readonly authorizationCode: _alepha_server_cookies0.CookieDescriptor<_sinclair_typebox0.TObject<{
45
- codeVerifier: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
46
- redirectUri: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
76
+ protected readonly dateTimeProvider: DateTimeProvider;
77
+ protected readonly serverLinksProvider: ServerLinksProvider;
78
+ protected readonly reactAuth: ReactAuth;
79
+ protected readonly authorizationCode: _alepha_server_cookies1.AbstractCookieDescriptor<_sinclair_typebox156.TObject<{
80
+ provider: _sinclair_typebox156.TString;
81
+ codeVerifier: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
82
+ redirectUri: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
83
+ state: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
84
+ nonce: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
47
85
  }>>;
48
- readonly tokens: _alepha_server_cookies0.CookieDescriptor<_sinclair_typebox0.TObject<{
49
- provider: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
50
- access_token: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
51
- expires_in: _sinclair_typebox0.TOptional<_sinclair_typebox0.TNumber>;
52
- refresh_token: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
53
- id_token: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
54
- scope: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
55
- issued_at: _sinclair_typebox0.TOptional<_sinclair_typebox0.TNumber>;
86
+ readonly tokens: _alepha_server_cookies1.AbstractCookieDescriptor<_sinclair_typebox156.TObject<{
87
+ provider: _sinclair_typebox156.TString;
88
+ access_token: _sinclair_typebox156.TString;
89
+ issued_at: _sinclair_typebox156.TNumber;
90
+ expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
91
+ refresh_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
92
+ refresh_token_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
93
+ refresh_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
94
+ id_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
95
+ scope: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
96
+ token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
97
+ realm: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
56
98
  }>>;
57
- readonly user: _alepha_server_cookies0.CookieDescriptor<_sinclair_typebox0.TObject<{
58
- id: _sinclair_typebox0.TString;
59
- name: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
60
- email: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
61
- picture: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
62
- }>>;
63
- readonly onRender: _alepha_core0$1.HookDescriptor<"react:server:render:begin">;
64
- protected readonly configure: _alepha_core0$1.HookDescriptor<"configure">;
65
- protected getAccessTokenFromCookies(tokens: SessionTokens): Promise<string | undefined>;
99
+ readonly onRender: _alepha_core4.HookDescriptor<"react:server:render:begin">;
100
+ get identities(): Array<AuthDescriptor>;
101
+ protected readonly configure: _alepha_core4.HookDescriptor<"configure">;
102
+ protected getAccessTokens(tokens: Tokens): string | undefined;
66
103
  /**
67
- * Configure Fastify to forward Session Access Token to Header Authorization.
104
+ * Fill request headers with access token from cookies or fallback to provider's fallback function.
68
105
  */
69
- protected readonly onRequest: _alepha_core0$1.HookDescriptor<"server:onRequest">;
106
+ protected readonly onRequest: _alepha_core4.HookDescriptor<"server:onRequest">;
70
107
  /**
71
- *
72
- * @param cookies
73
- * @protected
108
+ * Convert cookies to tokens.
109
+ * If the tokens are expired, try to refresh them using the refresh token.
74
110
  */
75
- protected refresh(cookies: Cookies): Promise<SessionTokens | undefined>;
76
- readonly login: _alepha_server0.RouteDescriptor<{
77
- query: _sinclair_typebox0.TObject<{
78
- redirect: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
79
- provider: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
111
+ protected cookiesToTokens(cookies: Cookies): Promise<Tokens | undefined>;
112
+ protected checkCsrf(cookies: Cookies, csrfHeader: string): Promise<void>;
113
+ protected refreshTokens(tokens: Tokens): Promise<Tokens | undefined>;
114
+ /**
115
+ * Get user information.
116
+ */
117
+ readonly userinfo: _alepha_server0.RouteDescriptor<{
118
+ response: _sinclair_typebox156.TObject<{
119
+ user: _sinclair_typebox156.TOptional<_sinclair_typebox156.TObject<{
120
+ id: _sinclair_typebox156.TString;
121
+ name: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
122
+ email: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
123
+ username: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
124
+ picture: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
125
+ sessionId: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
126
+ organizations: _sinclair_typebox156.TOptional<_sinclair_typebox156.TArray<_sinclair_typebox156.TString>>;
127
+ roles: _sinclair_typebox156.TOptional<_sinclair_typebox156.TArray<_sinclair_typebox156.TString>>;
128
+ }>>;
129
+ api: _sinclair_typebox156.TObject<{
130
+ prefix: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
131
+ links: _sinclair_typebox156.TArray<_sinclair_typebox156.TObject<{
132
+ name: _sinclair_typebox156.TString;
133
+ group: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
134
+ path: _sinclair_typebox156.TString;
135
+ method: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
136
+ requestBodyType: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
137
+ service: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
138
+ }>>;
139
+ }>;
80
140
  }>;
81
141
  }>;
82
- readonly callback: _alepha_server0.RouteDescriptor<{
83
- query: _sinclair_typebox0.TObject<{
84
- provider: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
142
+ /**
143
+ * Refresh a token for internal providers.
144
+ */
145
+ readonly refresh: _alepha_server0.RouteDescriptor<{
146
+ query: _sinclair_typebox156.TObject<{
147
+ provider: _sinclair_typebox156.TString;
148
+ }>;
149
+ body: _sinclair_typebox156.TObject<{
150
+ refresh_token: _sinclair_typebox156.TString;
151
+ access_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
152
+ }>;
153
+ response: _sinclair_typebox156.TObject<{
154
+ provider: _sinclair_typebox156.TString;
155
+ access_token: _sinclair_typebox156.TString;
156
+ issued_at: _sinclair_typebox156.TNumber;
157
+ expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
158
+ refresh_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
159
+ refresh_token_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
160
+ refresh_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
161
+ id_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
162
+ scope: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
163
+ token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
164
+ realm: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
85
165
  }>;
86
166
  }>;
87
167
  /**
88
- *
89
- * @param accessToken
90
- * @protected
91
- */
92
- protected userFromAccessToken(accessToken: string): {
93
- id: any;
94
- name: any;
95
- email: any;
96
- picture: any;
97
- } | undefined;
98
- readonly logout: _alepha_server0.RouteDescriptor<{
99
- query: _sinclair_typebox0.TObject<{
100
- redirect: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
101
- provider: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
168
+ * Login for local password-based authentication.
169
+ */
170
+ readonly token: _alepha_server0.RouteDescriptor<{
171
+ query: _sinclair_typebox156.TObject<{
172
+ provider: _sinclair_typebox156.TString;
173
+ }>;
174
+ body: _sinclair_typebox156.TObject<{
175
+ username: _sinclair_typebox156.TString;
176
+ password: _sinclair_typebox156.TString;
177
+ }>;
178
+ response: _sinclair_typebox156.TObject<{
179
+ provider: _sinclair_typebox156.TString;
180
+ access_token: _sinclair_typebox156.TString;
181
+ issued_at: _sinclair_typebox156.TNumber;
182
+ expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
183
+ refresh_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
184
+ refresh_token_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
185
+ refresh_expires_in: _sinclair_typebox156.TOptional<_sinclair_typebox156.TNumber>;
186
+ id_token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
187
+ scope: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
188
+ token: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
189
+ realm: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
190
+ user: _sinclair_typebox156.TObject<{
191
+ id: _sinclair_typebox156.TString;
192
+ name: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
193
+ email: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
194
+ username: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
195
+ picture: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
196
+ sessionId: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
197
+ organizations: _sinclair_typebox156.TOptional<_sinclair_typebox156.TArray<_sinclair_typebox156.TString>>;
198
+ roles: _sinclair_typebox156.TOptional<_sinclair_typebox156.TArray<_sinclair_typebox156.TString>>;
199
+ }>;
200
+ api: _sinclair_typebox156.TObject<{
201
+ prefix: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
202
+ links: _sinclair_typebox156.TArray<_sinclair_typebox156.TObject<{
203
+ name: _sinclair_typebox156.TString;
204
+ group: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
205
+ path: _sinclair_typebox156.TString;
206
+ method: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
207
+ requestBodyType: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
208
+ service: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
209
+ }>>;
210
+ }>;
102
211
  }>;
103
212
  }>;
104
213
  /**
105
- *
106
- * @param name
107
- * @protected
108
- */
109
- protected provider(name?: string): Promise<{
110
- client: Configuration;
111
- name: string;
112
- redirectUri: string;
113
- fallback?: () => Async<AccessToken>;
114
- useIdToken?: boolean;
115
- logoutUri?: string;
214
+ * Oauth2/OIDC login route.
215
+ */
216
+ readonly login: _alepha_server0.RouteDescriptor<{
217
+ query: _sinclair_typebox156.TObject<{
218
+ provider: _sinclair_typebox156.TString;
219
+ redirect_uri: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
220
+ }>;
116
221
  }>;
117
222
  /**
118
- *
119
- * @param file
120
- * @protected
223
+ * Callback for OAuth2/OIDC providers.
224
+ * It handles the authorization code flow and retrieves the access token.
121
225
  */
122
- protected isViteFile(file: string): boolean;
123
- }
124
- interface SessionTokens {
125
- access_token?: string;
126
- expires_in?: number;
127
- refresh_token?: string;
128
- id_token?: string;
129
- scope?: string;
130
- issued_at?: number;
131
- provider?: string;
226
+ readonly callback: _alepha_server0.RouteDescriptor<_alepha_server0.RequestConfigSchema>;
227
+ /**
228
+ * Logout route for OAuth2/OIDC providers.
229
+ */
230
+ readonly logout: _alepha_server0.RouteDescriptor<{
231
+ query: _sinclair_typebox156.TObject<{
232
+ post_logout_redirect_uri: _sinclair_typebox156.TOptional<_sinclair_typebox156.TString>;
233
+ }>;
234
+ }>;
235
+ protected provider(opts: string | {
236
+ provider: string;
237
+ }): AuthDescriptor;
238
+ protected setTokens(tokens: Tokens, cookies?: Cookies): void;
132
239
  }
133
- interface AuthProvider {
134
- name: string;
135
- redirectUri: string;
136
- client: {
137
- get: () => Promise<Configuration>;
240
+ interface OAuth2Profile {
241
+ sub: string;
242
+ email?: string;
243
+ name?: string;
244
+ given_name?: string;
245
+ family_name?: string;
246
+ middle_name?: string;
247
+ nickname?: string;
248
+ preferred_username?: string;
249
+ profile?: string;
250
+ picture?: string;
251
+ website?: string;
252
+ email_verified?: boolean;
253
+ gender?: string;
254
+ birthdate?: string;
255
+ zoneinfo?: string;
256
+ locale?: string;
257
+ phone_number?: string;
258
+ phone_number_verified?: boolean;
259
+ address?: {
260
+ formatted?: string;
261
+ street_address?: string;
262
+ locality?: string;
263
+ region?: string;
264
+ postal_code?: string;
265
+ country?: string;
138
266
  };
267
+ updated_at?: number;
268
+ [key: string]: unknown;
269
+ }
270
+ //#endregion
271
+ //#region src/descriptors/$auth.d.ts
272
+ declare const $auth: {
273
+ (options: AuthDescriptorOptions): AuthDescriptor;
274
+ [KIND]: typeof AuthDescriptor;
275
+ };
276
+ type AuthDescriptorOptions = {
277
+ /**
278
+ * Name of the identity provider.
279
+ * If not provided, it will be derived from the property key.
280
+ */
281
+ name?: string;
282
+ /**
283
+ * If true, auth provider will be skipped.
284
+ */
285
+ disabled?: boolean;
286
+ } & (AuthExternal | AuthInternal);
287
+ /**
288
+ * When you let an external service handle authentication. (e.g. Keycloak, Auth0, etc.)
289
+ */
290
+ type AuthExternal = {
291
+ /**
292
+ * Only OIDC is supported for external authentication.
293
+ */
294
+ oidc: OidcOptions;
295
+ /**
296
+ * For anonymous access, this will expect a service account access token.
297
+ *
298
+ * ```ts
299
+ * class App {
300
+ * anonymous = $serviceAccount(...);
301
+ * auth = $auth({
302
+ * // ... config ...
303
+ * fallback: this.anonymous,
304
+ * })
305
+ * }
306
+ * ```
307
+ */
139
308
  fallback?: () => Async<AccessToken>;
309
+ };
310
+ /**
311
+ * When using your own authentication system, e.g. using a database to store user accounts.
312
+ * This is usually used with a custom login form.
313
+ *
314
+ * This relies on the `realm`, which is used to create/verify the access token.
315
+ */
316
+ type AuthInternal = {
317
+ realm: RealmDescriptor;
318
+ } & ({
319
+ /**
320
+ * The common username/password authentication.
321
+ *
322
+ * - It uses the OAuth2 Client Credentials flow to obtain an access token.
323
+ *
324
+ * This is usually used with a custom login form on your website or mobile app.
325
+ */
326
+ credentials: CredentialsOptions;
327
+ } | {
328
+ /**
329
+ * OAuth2 authentication. Delegates authentication to an OAuth2 provider. (e.g. Google, GitHub, etc.)
330
+ *
331
+ * - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
332
+ *
333
+ * This is usually used with a login button that redirects to the OAuth2 provider.
334
+ */
335
+ oauth: OAuth2Options;
336
+ } | {
337
+ /**
338
+ * Like OAuth2, but uses OIDC (OpenID Connect) for authentication and user information retrieval.
339
+ * OIDC is an identity layer on top of OAuth2, providing user authentication and profile information.
340
+ *
341
+ * - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
342
+ * - PCKE (Proof Key for Code Exchange) is recommended for security.
343
+ *
344
+ * This is usually used with a login button that redirects to the OIDC provider.
345
+ */
346
+ oidc: OidcOptions;
347
+ });
348
+ type CredentialsOptions = {
349
+ account: (credentials: {
350
+ username: string;
351
+ password: string;
352
+ }) => Async<UserAccount>;
353
+ };
354
+ interface OidcOptions {
355
+ /**
356
+ * URL of the OIDC issuer.
357
+ */
358
+ issuer: string;
359
+ /**
360
+ * Client ID for the OIDC client.
361
+ */
362
+ clientId: string;
363
+ /**
364
+ * Client secret for the OIDC client.
365
+ * Optional if PKCE (Proof Key for Code Exchange) is used.
366
+ */
367
+ clientSecret?: string;
368
+ /**
369
+ * Redirect URI for the OIDC client.
370
+ * This is where the user will be redirected after authentication.
371
+ */
372
+ redirectUri?: string;
373
+ /**
374
+ * For external auth providers only.
375
+ * Take the ID token instead of the access token for validation.
376
+ */
140
377
  useIdToken?: boolean;
378
+ /**
379
+ * URI to redirect the user after logout.
380
+ */
141
381
  logoutUri?: string;
382
+ /**
383
+ * Optional scope for the OIDC client.
384
+ * @default "openid profile email".
385
+ */
386
+ scope?: string;
387
+ account?: (tokens: {
388
+ access_token: string;
389
+ user: OAuth2Profile;
390
+ id_token?: string;
391
+ expires_in?: number;
392
+ scope?: string;
393
+ }) => Async<UserAccount>;
142
394
  }
143
- interface ReactUser {
144
- id: string;
145
- name?: string;
146
- email?: string;
395
+ interface OAuth2Options {
396
+ /**
397
+ * URL of the OAuth2 authorization endpoint.
398
+ */
399
+ clientId: string;
400
+ /**
401
+ * Client secret for the OAuth2 client.
402
+ */
403
+ clientSecret: string;
404
+ /**
405
+ * URL of the OAuth2 authorization endpoint.
406
+ */
407
+ authorization: string;
408
+ /**
409
+ * URL of the OAuth2 token endpoint.
410
+ */
411
+ token: string;
412
+ /**
413
+ * Function to retrieve user profile information from the OAuth2 tokens.
414
+ */
415
+ userinfo: (tokens: Tokens) => Async<OAuth2Profile>;
416
+ account?: (tokens: {
417
+ access_token: string;
418
+ user: OAuth2Profile;
419
+ id_token?: string;
420
+ expires_in?: number;
421
+ scope?: string;
422
+ }) => Async<UserAccount>;
423
+ /**
424
+ * URL of the OAuth2 authorization endpoint.
425
+ */
426
+ redirectUri?: string;
427
+ /**
428
+ * URL of the OAuth2 authorization endpoint.
429
+ */
430
+ scope?: string;
147
431
  }
148
- //# sourceMappingURL=ReactAuthProvider.d.ts.map
149
- //#endregion
150
- //#region src/hooks/useAuth.d.ts
151
- declare const useAuth: () => AuthHook;
152
- interface AuthHook {
153
- user?: UserAccountToken;
154
- logout: () => void;
155
- login: (provider?: string) => void;
156
- can: <T extends object>(name: keyof HttpVirtualClient<T>) => boolean;
432
+ declare class AuthDescriptor extends Descriptor<AuthDescriptorOptions> {
433
+ protected readonly securityProvider: SecurityProvider;
434
+ protected readonly dateTimeProvider: DateTimeProvider;
435
+ oauth?: Configuration;
436
+ get name(): string;
437
+ get jwks_uri(): string;
438
+ get scope(): string | undefined;
439
+ get redirect_uri(): string | undefined;
440
+ /**
441
+ * Refreshes the access token using the refresh token.
442
+ * Can be used on oauth2, oidc or credentials auth providers.
443
+ */
444
+ refresh(refreshToken: string, accessToken?: string): Promise<AccessTokenResponse>;
445
+ /**
446
+ * Extracts user information from the access token.
447
+ * This is used to create a user account from the access token.
448
+ */
449
+ user(tokens: Tokens): Promise<UserAccount>;
450
+ protected getUserFromIdToken(idToken: string): OAuth2Profile;
451
+ prepare(): Promise<void>;
157
452
  }
158
- //# sourceMappingURL=useAuth.d.ts.map
453
+ type AccessToken = string | {
454
+ token: () => Async<string>;
455
+ };
159
456
  //#endregion
160
- //#region src/services/ReactAuth.d.ts
161
- declare class ReactAuth {
162
- protected readonly log: _alepha_core4.Logger;
163
- protected readonly alepha: Alepha;
164
- protected readonly client: HttpClient;
165
- static path: {
166
- login: string;
167
- callback: string;
168
- logout: string;
169
- };
170
- readonly onRender: _alepha_core4.HookDescriptor<"react:transition:begin">;
171
- get user(): UserAccountToken | undefined;
172
- protected getUserFromCookies(): UserAccountToken | undefined;
173
- login(): void;
174
- logout(): void;
457
+ //#region src/errors/SessionExpiredError.d.ts
458
+ declare class SessionExpiredError extends AlephaError {
459
+ readonly name = "SessionExpiredError";
460
+ readonly status = 401;
175
461
  }
176
- //# sourceMappingURL=ReactAuth.d.ts.map
462
+ //#endregion
463
+ //#region src/hooks/useAuth.d.ts
464
+ declare const useAuth: <T extends object = any>() => {
465
+ user: {
466
+ name?: string | undefined;
467
+ email?: string | undefined;
468
+ username?: string | undefined;
469
+ picture?: string | undefined;
470
+ sessionId?: string | undefined;
471
+ organizations?: string[] | undefined;
472
+ roles?: string[] | undefined;
473
+ id: string;
474
+ } | undefined;
475
+ logout: () => void;
476
+ login: (provider: keyof T, options?: {
477
+ username?: string;
478
+ password?: string;
479
+ redirect?: string;
480
+ [extra: string]: any;
481
+ }) => Promise<void>;
482
+ can: <Api extends object = any>(name: keyof HttpVirtualClient<Api>) => boolean;
483
+ };
177
484
  //#endregion
178
485
  //#region src/index.d.ts
179
- declare module "alepha/react" {
180
- interface PageReactContext {
181
- user?: UserAccountToken;
486
+ declare module "alepha" {
487
+ interface State {
488
+ user?: UserAccount;
182
489
  }
183
- interface ReactHydrationState {
184
- user?: ReactUser;
490
+ }
491
+ declare module "alepha/react" {
492
+ interface ReactRouterState {
493
+ user?: UserAccount;
185
494
  }
186
495
  }
187
496
  /**
@@ -190,9 +499,7 @@ declare module "alepha/react" {
190
499
  * @see {@link ReactAuthProvider}
191
500
  * @module alepha.react.auth
192
501
  */
193
- declare const AlephaReactAuth: _alepha_core0.ModuleDescriptor;
194
- //# sourceMappingURL=index.d.ts.map
195
-
502
+ declare const AlephaReactAuth: _alepha_core4.Service<_alepha_core4.Module>;
196
503
  //#endregion
197
- export { $auth, AccessToken, AlephaReactAuth, AuthDescriptor, AuthDescriptorOptions, AuthHook, AuthProvider, ReactAuth, ReactAuthProvider, ReactUser, SessionTokens, useAuth };
504
+ export { $auth, AccessToken, AlephaReactAuth, AuthDescriptor, AuthDescriptorOptions, AuthExternal, AuthInternal, CredentialsOptions, OAuth2Options, OAuth2Profile, OidcOptions, ReactAuth, ReactAuthProvider, SessionExpiredError, useAuth };
198
505
  //# sourceMappingURL=index.d.ts.map