@alepha/react 0.11.11 → 0.11.12
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/README.md +1 -183
- package/dist/auth/index.browser.js +1460 -0
- package/dist/auth/index.browser.js.map +1 -0
- package/dist/auth/index.cjs +3647 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +564 -0
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.ts +564 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +3615 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/{index.browser.js → core/index.browser.js} +36 -35
- package/dist/core/index.browser.js.map +1 -0
- package/dist/{index.cjs → core/index.cjs} +141 -140
- package/dist/core/index.cjs.map +1 -0
- package/dist/{index.d.cts → core/index.d.cts} +68 -68
- package/dist/core/index.d.cts.map +1 -0
- package/dist/{index.d.ts → core/index.d.ts} +68 -68
- package/dist/core/index.d.ts.map +1 -0
- package/dist/{index.js → core/index.js} +39 -38
- package/dist/core/index.js.map +1 -0
- package/dist/form/index.cjs +2054 -0
- package/dist/form/index.cjs.map +1 -0
- package/dist/form/index.d.cts +211 -0
- package/dist/form/index.d.cts.map +1 -0
- package/dist/form/index.d.ts +211 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +2026 -0
- package/dist/form/index.js.map +1 -0
- package/dist/head/index.browser.js +1503 -0
- package/dist/head/index.browser.js.map +1 -0
- package/dist/head/index.cjs +1908 -0
- package/dist/head/index.cjs.map +1 -0
- package/dist/head/index.d.cts +595 -0
- package/dist/head/index.d.cts.map +1 -0
- package/dist/head/index.d.ts +601 -0
- package/dist/head/index.d.ts.map +1 -0
- package/dist/head/index.js +1880 -0
- package/dist/head/index.js.map +1 -0
- package/dist/i18n/index.cjs +1886 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.cts +168 -0
- package/dist/i18n/index.d.cts.map +1 -0
- package/dist/i18n/index.d.ts +168 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +1857 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/websocket/index.cjs +1774 -0
- package/dist/websocket/index.cjs.map +1 -0
- package/dist/websocket/index.d.cts +118 -0
- package/dist/websocket/index.d.cts.map +1 -0
- package/dist/websocket/index.d.ts +118 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +1750 -0
- package/dist/websocket/index.js.map +1 -0
- package/package.json +89 -67
- package/src/auth/descriptors/$auth.ts +436 -0
- package/src/auth/descriptors/$authApple.ts +8 -0
- package/src/auth/descriptors/$authGithub.ts +81 -0
- package/src/auth/descriptors/$authGoogle.ts +38 -0
- package/src/auth/errors/SessionExpiredError.ts +6 -0
- package/src/auth/hooks/useAuth.ts +31 -0
- package/src/auth/index.browser.ts +16 -0
- package/src/auth/index.shared.ts +3 -0
- package/src/auth/index.ts +47 -0
- package/src/auth/providers/ReactAuthProvider.ts +629 -0
- package/src/auth/schemas/tokenResponseSchema.ts +11 -0
- package/src/auth/schemas/tokensSchema.ts +21 -0
- package/src/auth/schemas/userinfoResponseSchema.ts +10 -0
- package/src/auth/services/ReactAuth.ts +124 -0
- package/src/{components → core/components}/ErrorViewer.tsx +3 -2
- package/src/{components → core/components}/NestedView.tsx +1 -1
- package/src/{contexts → core/contexts}/AlephaContext.ts +1 -1
- package/src/{descriptors → core/descriptors}/$page.ts +4 -4
- package/src/{hooks → core/hooks}/useAction.ts +1 -1
- package/src/{hooks → core/hooks}/useAlepha.ts +1 -1
- package/src/{hooks → core/hooks}/useClient.ts +1 -1
- package/src/{hooks → core/hooks}/useEvents.ts +1 -1
- package/src/{hooks → core/hooks}/useInject.ts +1 -1
- package/src/{hooks → core/hooks}/useQueryParams.ts +1 -1
- package/src/{hooks → core/hooks}/useRouterState.ts +1 -1
- package/src/{hooks → core/hooks}/useSchema.ts +3 -3
- package/src/{hooks → core/hooks}/useStore.ts +2 -2
- package/src/{index.browser.ts → core/index.browser.ts} +4 -4
- package/src/{index.ts → core/index.ts} +6 -6
- package/src/{providers → core/providers}/ReactBrowserProvider.ts +6 -6
- package/src/{providers → core/providers}/ReactBrowserRendererProvider.ts +2 -2
- package/src/{providers → core/providers}/ReactBrowserRouterProvider.ts +3 -3
- package/src/{providers → core/providers}/ReactPageProvider.ts +3 -3
- package/src/{providers → core/providers}/ReactServerProvider.ts +7 -7
- package/src/{services → core/services}/ReactPageServerService.ts +2 -2
- package/src/{services → core/services}/ReactPageService.ts +1 -1
- package/src/{services → core/services}/ReactRouter.ts +1 -1
- package/src/form/components/FormState.tsx +17 -0
- package/src/form/hooks/useForm.ts +47 -0
- package/src/form/hooks/useFormState.ts +130 -0
- package/src/form/index.ts +38 -0
- package/src/form/services/FormModel.ts +548 -0
- package/src/head/descriptors/$head.ts +25 -0
- package/src/head/hooks/useHead.ts +62 -0
- package/src/head/index.browser.ts +25 -0
- package/src/head/index.ts +47 -0
- package/src/head/interfaces/Head.ts +46 -0
- package/src/head/providers/BrowserHeadProvider.ts +105 -0
- package/src/head/providers/HeadProvider.ts +73 -0
- package/src/head/providers/ServerHeadProvider.ts +109 -0
- package/src/i18n/README.md +76 -0
- package/src/i18n/components/Localize.tsx +35 -0
- package/src/i18n/descriptors/$dictionary.ts +65 -0
- package/src/i18n/hooks/useI18n.ts +18 -0
- package/src/i18n/index.ts +34 -0
- package/src/i18n/providers/I18nProvider.ts +277 -0
- package/src/websocket/hooks/useRoom.tsx +223 -0
- package/src/websocket/index.ts +7 -0
- package/dist/index.browser.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- /package/src/{components → core/components}/ClientOnly.tsx +0 -0
- /package/src/{components → core/components}/ErrorBoundary.tsx +0 -0
- /package/src/{components → core/components}/Link.tsx +0 -0
- /package/src/{components → core/components}/NotFound.tsx +0 -0
- /package/src/{contexts → core/contexts}/RouterLayerContext.ts +0 -0
- /package/src/{errors → core/errors}/Redirection.ts +0 -0
- /package/src/{hooks → core/hooks}/useActive.ts +0 -0
- /package/src/{hooks → core/hooks}/useRouter.ts +0 -0
- /package/src/{index.shared.ts → core/index.shared.ts} +0 -0
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import * as alepha4 from "alepha";
|
|
2
|
+
import { Alepha, AlephaError, Async, Descriptor, KIND, Static } from "alepha";
|
|
3
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
4
|
+
import * as alepha_server0 from "alepha/server";
|
|
5
|
+
import { HttpClient } from "alepha/server";
|
|
6
|
+
import { HttpVirtualClient, ServerLinksProvider } from "alepha/server/links";
|
|
7
|
+
import * as alepha_logger0 from "alepha/logger";
|
|
8
|
+
import * as alepha_server_cookies0 from "alepha/server/cookies";
|
|
9
|
+
import { Cookies, ServerCookiesProvider } from "alepha/server/cookies";
|
|
10
|
+
import { AccessTokenResponse, RealmDescriptor, SecurityProvider, UserAccount, UserAccountToken } from "alepha/security";
|
|
11
|
+
import { Configuration } from "openid-client";
|
|
12
|
+
import * as typebox143 from "typebox";
|
|
13
|
+
|
|
14
|
+
//#region src/auth/schemas/tokensSchema.d.ts
|
|
15
|
+
declare const tokensSchema: typebox143.TObject<{
|
|
16
|
+
provider: typebox143.TString;
|
|
17
|
+
access_token: typebox143.TString;
|
|
18
|
+
issued_at: typebox143.TNumber;
|
|
19
|
+
expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
20
|
+
refresh_token: typebox143.TOptional<typebox143.TString>;
|
|
21
|
+
refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
22
|
+
refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
23
|
+
id_token: typebox143.TOptional<typebox143.TString>;
|
|
24
|
+
scope: typebox143.TOptional<typebox143.TString>;
|
|
25
|
+
}>;
|
|
26
|
+
type Tokens = Static<typeof tokensSchema>;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/auth/services/ReactAuth.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* Browser, SSR friendly, service to handle authentication.
|
|
31
|
+
*/
|
|
32
|
+
declare class ReactAuth {
|
|
33
|
+
protected readonly log: alepha_logger0.Logger;
|
|
34
|
+
protected readonly alepha: Alepha;
|
|
35
|
+
protected readonly httpClient: HttpClient;
|
|
36
|
+
static path: {
|
|
37
|
+
login: string;
|
|
38
|
+
callback: string;
|
|
39
|
+
logout: string;
|
|
40
|
+
token: string;
|
|
41
|
+
refresh: string;
|
|
42
|
+
userinfo: string;
|
|
43
|
+
};
|
|
44
|
+
protected readonly onBeginTransition: alepha4.HookDescriptor<"react:transition:begin">;
|
|
45
|
+
protected readonly onFetchRequest: alepha4.HookDescriptor<"client:onRequest">;
|
|
46
|
+
/**
|
|
47
|
+
* Get the current authenticated user.
|
|
48
|
+
*
|
|
49
|
+
* Alias for `alepha.state.get("user")`
|
|
50
|
+
*/
|
|
51
|
+
get user(): UserAccountToken | undefined;
|
|
52
|
+
ping(): Promise<{
|
|
53
|
+
name?: string | undefined;
|
|
54
|
+
email?: string | undefined;
|
|
55
|
+
username?: string | undefined;
|
|
56
|
+
picture?: string | undefined;
|
|
57
|
+
sessionId?: string | undefined;
|
|
58
|
+
organizations?: string[] | undefined;
|
|
59
|
+
roles?: string[] | undefined;
|
|
60
|
+
id: string;
|
|
61
|
+
} | undefined>;
|
|
62
|
+
login(provider: string, options: {
|
|
63
|
+
hostname?: string;
|
|
64
|
+
username?: string;
|
|
65
|
+
password?: string;
|
|
66
|
+
redirect?: string;
|
|
67
|
+
[extra: string]: any;
|
|
68
|
+
}): Promise<Tokens>;
|
|
69
|
+
logout(): void;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/auth/providers/ReactAuthProvider.d.ts
|
|
73
|
+
declare class ReactAuthProvider {
|
|
74
|
+
protected readonly log: alepha_logger0.Logger;
|
|
75
|
+
protected readonly alepha: Alepha;
|
|
76
|
+
protected readonly serverCookiesProvider: ServerCookiesProvider;
|
|
77
|
+
protected readonly dateTimeProvider: DateTimeProvider;
|
|
78
|
+
protected readonly serverLinksProvider: ServerLinksProvider;
|
|
79
|
+
protected readonly reactAuth: ReactAuth;
|
|
80
|
+
protected readonly authorizationCode: alepha_server_cookies0.AbstractCookieDescriptor<typebox143.TObject<{
|
|
81
|
+
provider: typebox143.TString;
|
|
82
|
+
codeVerifier: typebox143.TOptional<typebox143.TString>;
|
|
83
|
+
redirectUri: typebox143.TOptional<typebox143.TString>;
|
|
84
|
+
state: typebox143.TOptional<typebox143.TString>;
|
|
85
|
+
nonce: typebox143.TOptional<typebox143.TString>;
|
|
86
|
+
}>>;
|
|
87
|
+
readonly tokens: alepha_server_cookies0.AbstractCookieDescriptor<typebox143.TObject<{
|
|
88
|
+
provider: typebox143.TString;
|
|
89
|
+
access_token: typebox143.TString;
|
|
90
|
+
issued_at: typebox143.TNumber;
|
|
91
|
+
expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
92
|
+
refresh_token: typebox143.TOptional<typebox143.TString>;
|
|
93
|
+
refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
94
|
+
refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
95
|
+
id_token: typebox143.TOptional<typebox143.TString>;
|
|
96
|
+
scope: typebox143.TOptional<typebox143.TString>;
|
|
97
|
+
}>>;
|
|
98
|
+
readonly onRender: alepha4.HookDescriptor<"react:server:render:begin">;
|
|
99
|
+
get identities(): Array<AuthDescriptor>;
|
|
100
|
+
protected readonly configure: alepha4.HookDescriptor<"configure">;
|
|
101
|
+
protected getAccessTokens(tokens: Tokens): string | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Fill request headers with access token from cookies or fallback to provider's fallback function.
|
|
104
|
+
*/
|
|
105
|
+
protected readonly onRequest: alepha4.HookDescriptor<"server:onRequest">;
|
|
106
|
+
/**
|
|
107
|
+
* Convert cookies to tokens.
|
|
108
|
+
* If the tokens are expired, try to refresh them using the refresh token.
|
|
109
|
+
*/
|
|
110
|
+
protected cookiesToTokens(cookies: Cookies): Promise<Tokens | undefined>;
|
|
111
|
+
protected refreshTokens(tokens: Tokens): Promise<Tokens | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* Get user information.
|
|
114
|
+
*/
|
|
115
|
+
readonly userinfo: alepha_server0.RouteDescriptor<{
|
|
116
|
+
response: typebox143.TObject<{
|
|
117
|
+
user: typebox143.TOptional<typebox143.TObject<{
|
|
118
|
+
id: typebox143.TString;
|
|
119
|
+
name: typebox143.TOptional<typebox143.TString>;
|
|
120
|
+
email: typebox143.TOptional<typebox143.TString>;
|
|
121
|
+
username: typebox143.TOptional<typebox143.TString>;
|
|
122
|
+
picture: typebox143.TOptional<typebox143.TString>;
|
|
123
|
+
sessionId: typebox143.TOptional<typebox143.TString>;
|
|
124
|
+
organizations: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
|
|
125
|
+
roles: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
|
|
126
|
+
}>>;
|
|
127
|
+
api: typebox143.TObject<{
|
|
128
|
+
prefix: typebox143.TOptional<typebox143.TString>;
|
|
129
|
+
links: typebox143.TArray<typebox143.TObject<{
|
|
130
|
+
name: typebox143.TString;
|
|
131
|
+
group: typebox143.TOptional<typebox143.TString>;
|
|
132
|
+
path: typebox143.TString;
|
|
133
|
+
method: typebox143.TOptional<typebox143.TString>;
|
|
134
|
+
requestBodyType: typebox143.TOptional<typebox143.TString>;
|
|
135
|
+
service: typebox143.TOptional<typebox143.TString>;
|
|
136
|
+
}>>;
|
|
137
|
+
}>;
|
|
138
|
+
}>;
|
|
139
|
+
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Refresh a token for internal providers.
|
|
142
|
+
*/
|
|
143
|
+
readonly refresh: alepha_server0.RouteDescriptor<{
|
|
144
|
+
query: typebox143.TObject<{
|
|
145
|
+
provider: typebox143.TString;
|
|
146
|
+
}>;
|
|
147
|
+
body: typebox143.TObject<{
|
|
148
|
+
refresh_token: typebox143.TString;
|
|
149
|
+
access_token: typebox143.TOptional<typebox143.TString>;
|
|
150
|
+
}>;
|
|
151
|
+
response: typebox143.TObject<{
|
|
152
|
+
provider: typebox143.TString;
|
|
153
|
+
access_token: typebox143.TString;
|
|
154
|
+
issued_at: typebox143.TNumber;
|
|
155
|
+
expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
156
|
+
refresh_token: typebox143.TOptional<typebox143.TString>;
|
|
157
|
+
refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
158
|
+
refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
159
|
+
id_token: typebox143.TOptional<typebox143.TString>;
|
|
160
|
+
scope: typebox143.TOptional<typebox143.TString>;
|
|
161
|
+
}>;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Login for local password-based authentication.
|
|
165
|
+
*/
|
|
166
|
+
readonly token: alepha_server0.RouteDescriptor<{
|
|
167
|
+
query: typebox143.TObject<{
|
|
168
|
+
provider: typebox143.TString;
|
|
169
|
+
}>;
|
|
170
|
+
body: typebox143.TObject<{
|
|
171
|
+
username: typebox143.TString;
|
|
172
|
+
password: typebox143.TString;
|
|
173
|
+
}>;
|
|
174
|
+
response: typebox143.TObject<{
|
|
175
|
+
provider: typebox143.TString;
|
|
176
|
+
access_token: typebox143.TString;
|
|
177
|
+
issued_at: typebox143.TNumber;
|
|
178
|
+
expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
179
|
+
refresh_token: typebox143.TOptional<typebox143.TString>;
|
|
180
|
+
refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
181
|
+
refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
|
|
182
|
+
id_token: typebox143.TOptional<typebox143.TString>;
|
|
183
|
+
scope: typebox143.TOptional<typebox143.TString>;
|
|
184
|
+
user: typebox143.TObject<{
|
|
185
|
+
id: typebox143.TString;
|
|
186
|
+
name: typebox143.TOptional<typebox143.TString>;
|
|
187
|
+
email: typebox143.TOptional<typebox143.TString>;
|
|
188
|
+
username: typebox143.TOptional<typebox143.TString>;
|
|
189
|
+
picture: typebox143.TOptional<typebox143.TString>;
|
|
190
|
+
sessionId: typebox143.TOptional<typebox143.TString>;
|
|
191
|
+
organizations: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
|
|
192
|
+
roles: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
|
|
193
|
+
}>;
|
|
194
|
+
api: typebox143.TObject<{
|
|
195
|
+
prefix: typebox143.TOptional<typebox143.TString>;
|
|
196
|
+
links: typebox143.TArray<typebox143.TObject<{
|
|
197
|
+
name: typebox143.TString;
|
|
198
|
+
group: typebox143.TOptional<typebox143.TString>;
|
|
199
|
+
path: typebox143.TString;
|
|
200
|
+
method: typebox143.TOptional<typebox143.TString>;
|
|
201
|
+
requestBodyType: typebox143.TOptional<typebox143.TString>;
|
|
202
|
+
service: typebox143.TOptional<typebox143.TString>;
|
|
203
|
+
}>>;
|
|
204
|
+
}>;
|
|
205
|
+
}>;
|
|
206
|
+
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Oauth2/OIDC login route.
|
|
209
|
+
*/
|
|
210
|
+
readonly login: alepha_server0.RouteDescriptor<{
|
|
211
|
+
query: typebox143.TObject<{
|
|
212
|
+
provider: typebox143.TString;
|
|
213
|
+
redirect_uri: typebox143.TOptional<typebox143.TString>;
|
|
214
|
+
}>;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Callback for OAuth2/OIDC providers.
|
|
218
|
+
* It handles the authorization code flow and retrieves the access token.
|
|
219
|
+
*/
|
|
220
|
+
readonly callback: alepha_server0.RouteDescriptor<alepha_server0.RequestConfigSchema>;
|
|
221
|
+
/**
|
|
222
|
+
* Logout route for OAuth2/OIDC providers.
|
|
223
|
+
*/
|
|
224
|
+
readonly logout: alepha_server0.RouteDescriptor<{
|
|
225
|
+
query: typebox143.TObject<{
|
|
226
|
+
post_logout_redirect_uri: typebox143.TOptional<typebox143.TString>;
|
|
227
|
+
}>;
|
|
228
|
+
}>;
|
|
229
|
+
protected provider(opts: string | {
|
|
230
|
+
provider: string;
|
|
231
|
+
}): AuthDescriptor;
|
|
232
|
+
protected setTokens(tokens: Tokens, cookies?: Cookies): void;
|
|
233
|
+
}
|
|
234
|
+
interface OAuth2Profile {
|
|
235
|
+
sub: string;
|
|
236
|
+
email?: string;
|
|
237
|
+
name?: string;
|
|
238
|
+
given_name?: string;
|
|
239
|
+
family_name?: string;
|
|
240
|
+
middle_name?: string;
|
|
241
|
+
nickname?: string;
|
|
242
|
+
preferred_username?: string;
|
|
243
|
+
profile?: string;
|
|
244
|
+
picture?: string;
|
|
245
|
+
website?: string;
|
|
246
|
+
email_verified?: boolean;
|
|
247
|
+
gender?: string;
|
|
248
|
+
birthdate?: string;
|
|
249
|
+
zoneinfo?: string;
|
|
250
|
+
locale?: string;
|
|
251
|
+
phone_number?: string;
|
|
252
|
+
phone_number_verified?: boolean;
|
|
253
|
+
address?: {
|
|
254
|
+
formatted?: string;
|
|
255
|
+
street_address?: string;
|
|
256
|
+
locality?: string;
|
|
257
|
+
region?: string;
|
|
258
|
+
postal_code?: string;
|
|
259
|
+
country?: string;
|
|
260
|
+
};
|
|
261
|
+
updated_at?: number;
|
|
262
|
+
[key: string]: unknown;
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/auth/descriptors/$auth.d.ts
|
|
266
|
+
/**
|
|
267
|
+
* Creates an authentication provider descriptor for handling user login flows.
|
|
268
|
+
*
|
|
269
|
+
* Supports multiple authentication strategies: credentials (username/password), OAuth2,
|
|
270
|
+
* and OIDC (OpenID Connect). Handles token management, user profile retrieval, and
|
|
271
|
+
* integration with both external identity providers (Auth0, Keycloak) and internal realms.
|
|
272
|
+
*
|
|
273
|
+
* **Authentication Types**: Credentials, OAuth2 (Google, GitHub), OIDC, External providers
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* class AuthProviders {
|
|
278
|
+
* // Internal credentials-based auth
|
|
279
|
+
* credentials = $auth({
|
|
280
|
+
* realm: this.userRealm,
|
|
281
|
+
* credentials: {
|
|
282
|
+
* account: async ({ username, password }) => {
|
|
283
|
+
* return await this.validateUser(username, password);
|
|
284
|
+
* }
|
|
285
|
+
* }
|
|
286
|
+
* });
|
|
287
|
+
*
|
|
288
|
+
* // External OIDC provider
|
|
289
|
+
* keycloak = $auth({
|
|
290
|
+
* oidc: {
|
|
291
|
+
* issuer: "https://auth.example.com",
|
|
292
|
+
* clientId: "my-app",
|
|
293
|
+
* clientSecret: "secret",
|
|
294
|
+
* redirectUri: "/auth/callback"
|
|
295
|
+
* }
|
|
296
|
+
* });
|
|
297
|
+
* }
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
declare const $auth: {
|
|
301
|
+
(options: AuthDescriptorOptions): AuthDescriptor;
|
|
302
|
+
[KIND]: typeof AuthDescriptor;
|
|
303
|
+
};
|
|
304
|
+
type AuthDescriptorOptions = {
|
|
305
|
+
/**
|
|
306
|
+
* Name of the identity provider.
|
|
307
|
+
* If not provided, it will be derived from the property key.
|
|
308
|
+
*/
|
|
309
|
+
name?: string;
|
|
310
|
+
/**
|
|
311
|
+
* If true, auth provider will be skipped.
|
|
312
|
+
*/
|
|
313
|
+
disabled?: boolean;
|
|
314
|
+
} & (AuthExternal | AuthInternal);
|
|
315
|
+
/**
|
|
316
|
+
* When you let an external service handle authentication. (e.g. Keycloak, Auth0, etc.)
|
|
317
|
+
*/
|
|
318
|
+
type AuthExternal = {
|
|
319
|
+
/**
|
|
320
|
+
* Only OIDC is supported for external authentication.
|
|
321
|
+
*/
|
|
322
|
+
oidc: OidcOptions;
|
|
323
|
+
/**
|
|
324
|
+
* For anonymous access, this will expect a service account access token.
|
|
325
|
+
*
|
|
326
|
+
* ```ts
|
|
327
|
+
* class App {
|
|
328
|
+
* anonymous = $serviceAccount(...);
|
|
329
|
+
* auth = $auth({
|
|
330
|
+
* // ... config ...
|
|
331
|
+
* fallback: this.anonymous,
|
|
332
|
+
* })
|
|
333
|
+
* }
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
fallback?: () => Async<AccessToken>;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* When using your own authentication system, e.g. using a database to store user accounts.
|
|
340
|
+
* This is usually used with a custom login form.
|
|
341
|
+
*
|
|
342
|
+
* This relies on the `realm`, which is used to create/verify the access token.
|
|
343
|
+
*/
|
|
344
|
+
type AuthInternal = {
|
|
345
|
+
realm: RealmDescriptor;
|
|
346
|
+
} & ({
|
|
347
|
+
/**
|
|
348
|
+
* The common username/password authentication.
|
|
349
|
+
*
|
|
350
|
+
* - It uses the OAuth2 Client Credentials flow to obtain an access token.
|
|
351
|
+
*
|
|
352
|
+
* This is usually used with a custom login form on your website or mobile app.
|
|
353
|
+
*/
|
|
354
|
+
credentials: CredentialsOptions;
|
|
355
|
+
} | {
|
|
356
|
+
/**
|
|
357
|
+
* OAuth2 authentication. Delegates authentication to an OAuth2 provider. (e.g. Google, GitHub, etc.)
|
|
358
|
+
*
|
|
359
|
+
* - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
|
|
360
|
+
*
|
|
361
|
+
* This is usually used with a login button that redirects to the OAuth2 provider.
|
|
362
|
+
*/
|
|
363
|
+
oauth: OAuth2Options;
|
|
364
|
+
} | {
|
|
365
|
+
/**
|
|
366
|
+
* Like OAuth2, but uses OIDC (OpenID Connect) for authentication and user information retrieval.
|
|
367
|
+
* OIDC is an identity layer on top of OAuth2, providing user authentication and profile information.
|
|
368
|
+
*
|
|
369
|
+
* - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
|
|
370
|
+
* - PCKE (Proof Key for Code Exchange) is recommended for security.
|
|
371
|
+
*
|
|
372
|
+
* This is usually used with a login button that redirects to the OIDC provider.
|
|
373
|
+
*/
|
|
374
|
+
oidc: OidcOptions;
|
|
375
|
+
});
|
|
376
|
+
type CredentialsOptions = {
|
|
377
|
+
account: (credentials: {
|
|
378
|
+
username: string;
|
|
379
|
+
password: string;
|
|
380
|
+
}) => Async<UserAccount>;
|
|
381
|
+
};
|
|
382
|
+
interface OidcOptions {
|
|
383
|
+
/**
|
|
384
|
+
* URL of the OIDC issuer.
|
|
385
|
+
*/
|
|
386
|
+
issuer: string;
|
|
387
|
+
/**
|
|
388
|
+
* Client ID for the OIDC client.
|
|
389
|
+
*/
|
|
390
|
+
clientId: string;
|
|
391
|
+
/**
|
|
392
|
+
* Client secret for the OIDC client.
|
|
393
|
+
* Optional if PKCE (Proof Key for Code Exchange) is used.
|
|
394
|
+
*/
|
|
395
|
+
clientSecret?: string;
|
|
396
|
+
/**
|
|
397
|
+
* Redirect URI for the OIDC client.
|
|
398
|
+
* This is where the user will be redirected after authentication.
|
|
399
|
+
*/
|
|
400
|
+
redirectUri?: string;
|
|
401
|
+
/**
|
|
402
|
+
* For external auth providers only.
|
|
403
|
+
* Take the ID token instead of the access token for validation.
|
|
404
|
+
*/
|
|
405
|
+
useIdToken?: boolean;
|
|
406
|
+
/**
|
|
407
|
+
* URI to redirect the user after logout.
|
|
408
|
+
*/
|
|
409
|
+
logoutUri?: string;
|
|
410
|
+
/**
|
|
411
|
+
* Optional scope for the OIDC client.
|
|
412
|
+
* @default "openid profile email".
|
|
413
|
+
*/
|
|
414
|
+
scope?: string;
|
|
415
|
+
account?: (tokens: {
|
|
416
|
+
access_token: string;
|
|
417
|
+
user: OAuth2Profile;
|
|
418
|
+
id_token?: string;
|
|
419
|
+
expires_in?: number;
|
|
420
|
+
scope?: string;
|
|
421
|
+
}) => Async<UserAccount>;
|
|
422
|
+
}
|
|
423
|
+
interface OAuth2Options {
|
|
424
|
+
/**
|
|
425
|
+
* URL of the OAuth2 authorization endpoint.
|
|
426
|
+
*/
|
|
427
|
+
clientId: string;
|
|
428
|
+
/**
|
|
429
|
+
* Client secret for the OAuth2 client.
|
|
430
|
+
*/
|
|
431
|
+
clientSecret: string;
|
|
432
|
+
/**
|
|
433
|
+
* URL of the OAuth2 authorization endpoint.
|
|
434
|
+
*/
|
|
435
|
+
authorization: string;
|
|
436
|
+
/**
|
|
437
|
+
* URL of the OAuth2 token endpoint.
|
|
438
|
+
*/
|
|
439
|
+
token: string;
|
|
440
|
+
/**
|
|
441
|
+
* Function to retrieve user profile information from the OAuth2 tokens.
|
|
442
|
+
*/
|
|
443
|
+
userinfo: (tokens: Tokens) => Async<OAuth2Profile>;
|
|
444
|
+
account?: (tokens: {
|
|
445
|
+
access_token: string;
|
|
446
|
+
user: OAuth2Profile;
|
|
447
|
+
id_token?: string;
|
|
448
|
+
expires_in?: number;
|
|
449
|
+
scope?: string;
|
|
450
|
+
}) => Async<UserAccount>;
|
|
451
|
+
/**
|
|
452
|
+
* URL of the OAuth2 authorization endpoint.
|
|
453
|
+
*/
|
|
454
|
+
redirectUri?: string;
|
|
455
|
+
/**
|
|
456
|
+
* URL of the OAuth2 authorization endpoint.
|
|
457
|
+
*/
|
|
458
|
+
scope?: string;
|
|
459
|
+
}
|
|
460
|
+
declare class AuthDescriptor extends Descriptor<AuthDescriptorOptions> {
|
|
461
|
+
protected readonly securityProvider: SecurityProvider;
|
|
462
|
+
protected readonly dateTimeProvider: DateTimeProvider;
|
|
463
|
+
oauth?: Configuration;
|
|
464
|
+
get name(): string;
|
|
465
|
+
get jwks_uri(): string;
|
|
466
|
+
get scope(): string | undefined;
|
|
467
|
+
get redirect_uri(): string | undefined;
|
|
468
|
+
/**
|
|
469
|
+
* Refreshes the access token using the refresh token.
|
|
470
|
+
* Can be used on oauth2, oidc or credentials auth providers.
|
|
471
|
+
*/
|
|
472
|
+
refresh(refreshToken: string, accessToken?: string): Promise<AccessTokenResponse>;
|
|
473
|
+
/**
|
|
474
|
+
* Extracts user information from the access token.
|
|
475
|
+
* This is used to create a user account from the access token.
|
|
476
|
+
*/
|
|
477
|
+
user(tokens: Tokens): Promise<UserAccount>;
|
|
478
|
+
protected getUserFromIdToken(idToken: string): OAuth2Profile;
|
|
479
|
+
prepare(): Promise<void>;
|
|
480
|
+
}
|
|
481
|
+
type AccessToken = string | {
|
|
482
|
+
token: () => Async<string>;
|
|
483
|
+
};
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/auth/descriptors/$authGithub.d.ts
|
|
486
|
+
/**
|
|
487
|
+
* Already configured GitHub authentication descriptor.
|
|
488
|
+
*
|
|
489
|
+
* Uses OAuth2 to authenticate users via their GitHub accounts.
|
|
490
|
+
* Upon successful authentication, it links the GitHub account to a user session.
|
|
491
|
+
*
|
|
492
|
+
* Environment Variables:
|
|
493
|
+
* - `GITHUB_CLIENT_ID`: The client ID obtained from the GitHub Developer Settings.
|
|
494
|
+
* - `GITHUB_CLIENT_SECRET`: The client secret obtained from the GitHub Developer Settings.
|
|
495
|
+
*/
|
|
496
|
+
declare const $authGithub: (realm: RealmDescriptor, options: Partial<OidcOptions>) => AuthDescriptor;
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/auth/descriptors/$authGoogle.d.ts
|
|
499
|
+
/**
|
|
500
|
+
* Already configured Google authentication descriptor.
|
|
501
|
+
*
|
|
502
|
+
* Uses OpenID Connect (OIDC) to authenticate users via their Google accounts.
|
|
503
|
+
* Upon successful authentication, it links the Google account to a user session.
|
|
504
|
+
*
|
|
505
|
+
* Environment Variables:
|
|
506
|
+
* - `GOOGLE_CLIENT_ID`: The client ID obtained from the Google Developer Console.
|
|
507
|
+
* - `GOOGLE_CLIENT_SECRET`: The client secret obtained from the Google Developer Console.
|
|
508
|
+
*/
|
|
509
|
+
declare const $authGoogle: (realm: RealmDescriptor, options: Partial<OidcOptions>) => AuthDescriptor;
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/auth/errors/SessionExpiredError.d.ts
|
|
512
|
+
declare class SessionExpiredError extends AlephaError {
|
|
513
|
+
readonly name = "SessionExpiredError";
|
|
514
|
+
readonly status = 401;
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/auth/hooks/useAuth.d.ts
|
|
518
|
+
declare const useAuth: <T extends object = any>() => {
|
|
519
|
+
user: {
|
|
520
|
+
name?: string | undefined;
|
|
521
|
+
email?: string | undefined;
|
|
522
|
+
username?: string | undefined;
|
|
523
|
+
picture?: string | undefined;
|
|
524
|
+
sessionId?: string | undefined;
|
|
525
|
+
organizations?: string[] | undefined;
|
|
526
|
+
roles?: string[] | undefined;
|
|
527
|
+
id: string;
|
|
528
|
+
} | undefined;
|
|
529
|
+
logout: () => void;
|
|
530
|
+
login: (provider: keyof T, options?: {
|
|
531
|
+
username?: string;
|
|
532
|
+
password?: string;
|
|
533
|
+
redirect?: string;
|
|
534
|
+
[extra: string]: any;
|
|
535
|
+
}) => Promise<void>;
|
|
536
|
+
can: <Api extends object = any>(name: keyof HttpVirtualClient<Api>) => boolean;
|
|
537
|
+
};
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region src/auth/index.d.ts
|
|
540
|
+
declare module "alepha" {
|
|
541
|
+
interface State {
|
|
542
|
+
/**
|
|
543
|
+
* The authenticated user account attached to the server request state.
|
|
544
|
+
*
|
|
545
|
+
* @internal
|
|
546
|
+
*/
|
|
547
|
+
"alepha.server.request.user"?: UserAccount;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
declare module "@alepha/react" {
|
|
551
|
+
interface ReactRouterState {
|
|
552
|
+
user?: UserAccount;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* The ReactAuthModule provides authentication services for React applications.
|
|
557
|
+
*
|
|
558
|
+
* @see {@link ReactAuthProvider}
|
|
559
|
+
* @module alepha.react.auth
|
|
560
|
+
*/
|
|
561
|
+
declare const AlephaReactAuth: alepha4.Service<alepha4.Module>;
|
|
562
|
+
//#endregion
|
|
563
|
+
export { $auth, $authGithub, $authGoogle, AccessToken, AlephaReactAuth, AuthDescriptor, AuthDescriptorOptions, AuthExternal, AuthInternal, CredentialsOptions, OAuth2Options, OAuth2Profile, OidcOptions, ReactAuth, ReactAuthProvider, SessionExpiredError, useAuth };
|
|
564
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/auth/schemas/tokensSchema.ts","../../src/auth/services/ReactAuth.ts","../../src/auth/providers/ReactAuthProvider.ts","../../src/auth/descriptors/$auth.ts","../../src/auth/descriptors/$authGithub.ts","../../src/auth/descriptors/$authGoogle.ts","../../src/auth/errors/SessionExpiredError.ts","../../src/auth/hooks/useAuth.ts","../../src/auth/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAGa,yBAAY;YAevB,UAAA,CAAA;;;;;;;;;;KAEU,MAAA,GAAS,cAAc;;;;;;cCRtB,SAAA;0BAAS,cAAA,CACE;6BACG;iCACI;;;;IDZlB,MAAA,EAAA,MAeX;IAAA,KAAA,EAAA,MAAA;;;;wCCH6B,OAAA,CAWO;qCAAA,OAAA,CAWH;;;;;;cAed;UAIF;;;YDrDM,CAAA,EAAA,MAAA,GAAA,SAAA;IAAA,OAAA,CAAA,EAAA,MAAA,GAAA,SAAA;IAiBb,SAAM,CAAA,EAAA,MAAiB,GAAA,SAAA;;;;ECRtB,CAAA,GAAA,SAAS,CAAA;EAAA,KAAA,CAAA,QACE,EAAA,MAAA,EAAA,OAAA,EAAA;IACG,QAAA,CAAA,EAAA,MAAA;IACI,QAAA,CAAA,EAAA,MAAA;IAAA,QAWO,CAAA,EAAA,MAAA;IAAA,QAWH,CAAA,EAAA,MAAA;IAed,CAAA,KAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAIF,CAAA,CAAA,EAoBd,OApBc,CAoBN,MApBM,CAAA;EAoBN,MAAA,CAAA,CAAA,EAAA,IAAA;;;;cCnDA,iBAAA;0BAAiB,cAAA,CACN;6BACG;4CACe;uCACL;0CACG;gCACV;EF5BjB,mBAeX,iBAAA,EEeoC,sBAAA,CAAA,wBFfpC,YEeoC,OFfpC,CAAA;IAA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