@absolutejs/auth 0.27.0-beta.0 → 0.27.0-beta.10
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/dist/abuse/captcha.d.ts +11 -0
- package/dist/abuse/config.d.ts +29 -0
- package/dist/adaptive/config.d.ts +34 -0
- package/dist/adaptive/fingerprint.d.ts +2 -0
- package/dist/adaptive/inMemoryStores.d.ts +3 -0
- package/dist/adaptive/postgresStores.d.ts +293 -0
- package/dist/adaptive/types.d.ts +62 -0
- package/dist/apikeys/config.d.ts +64 -0
- package/dist/apikeys/inMemoryStores.d.ts +4 -0
- package/dist/apikeys/postgresStores.d.ts +507 -0
- package/dist/apikeys/routes.d.ts +83 -0
- package/dist/apikeys/types.d.ts +53 -0
- package/dist/audit/export.d.ts +2 -0
- package/dist/audit/integrity.d.ts +19 -0
- package/dist/audit/siem.d.ts +11 -0
- package/dist/audit/types.d.ts +2 -1
- package/dist/credentials/config.d.ts +1 -0
- package/dist/credentials/emailValidation.d.ts +9 -0
- package/dist/credentials/login.d.ts +2 -1
- package/dist/credentials/passwordPolicy.d.ts +1 -0
- package/dist/credentials/routes.d.ts +1 -0
- package/dist/fga/config.d.ts +53 -0
- package/dist/fga/inMemoryStores.d.ts +3 -0
- package/dist/fga/postgresStores.d.ts +144 -0
- package/dist/fga/schema.d.ts +2 -0
- package/dist/fga/types.d.ts +28 -0
- package/dist/index.d.ts +6311 -3
- package/dist/index.js +4000 -1652
- package/dist/index.js.map +52 -24
- package/dist/mfa/rotation.d.ts +17 -0
- package/dist/mfa/types.d.ts +1 -0
- package/dist/oidc/config.d.ts +71 -0
- package/dist/oidc/dpop.d.ts +12 -0
- package/dist/oidc/inMemoryStores.d.ts +4 -0
- package/dist/oidc/keys.d.ts +21 -0
- package/dist/oidc/postgresStores.d.ts +573 -0
- package/dist/oidc/routes.d.ts +142 -0
- package/dist/oidc/types.d.ts +42 -0
- package/dist/portal/routes.d.ts +1 -1
- package/dist/session/anonymous.d.ts +11 -0
- package/dist/session/impersonation.d.ts +29 -0
- package/dist/session/multiSession.d.ts +25 -0
- package/dist/session/promote.d.ts +3 -1
- package/dist/types.d.ts +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Elysia } from 'elysia';
|
|
2
|
+
import type { AuthSessionStore } from '../session/types';
|
|
3
|
+
import { type OidcProviderConfig } from './config';
|
|
4
|
+
export declare const oidcProviderRoutes: <UserType>(config: OidcProviderConfig<UserType> & {
|
|
5
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
6
|
+
}) => Elysia<"", {
|
|
7
|
+
decorator: {};
|
|
8
|
+
store: {
|
|
9
|
+
session: import("..").SessionRecord<UserType>;
|
|
10
|
+
unregisteredSession: import("..").UnregisteredSessionRecord;
|
|
11
|
+
};
|
|
12
|
+
derive: {};
|
|
13
|
+
resolve: {};
|
|
14
|
+
}, {
|
|
15
|
+
typebox: {};
|
|
16
|
+
error: {};
|
|
17
|
+
}, {
|
|
18
|
+
schema: {};
|
|
19
|
+
standaloneSchema: {};
|
|
20
|
+
macro: {};
|
|
21
|
+
macroFn: {};
|
|
22
|
+
parser: {};
|
|
23
|
+
response: {};
|
|
24
|
+
}, {
|
|
25
|
+
[x: string]: {
|
|
26
|
+
get: {
|
|
27
|
+
body: unknown;
|
|
28
|
+
params: {};
|
|
29
|
+
query: {
|
|
30
|
+
nonce?: string | undefined;
|
|
31
|
+
client_id?: string | undefined;
|
|
32
|
+
scope?: string | undefined;
|
|
33
|
+
code_challenge?: string | undefined;
|
|
34
|
+
code_challenge_method?: string | undefined;
|
|
35
|
+
redirect_uri?: string | undefined;
|
|
36
|
+
response_type?: string | undefined;
|
|
37
|
+
state?: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
headers: unknown;
|
|
40
|
+
response: {
|
|
41
|
+
200: Response;
|
|
42
|
+
422: {
|
|
43
|
+
type: "validation";
|
|
44
|
+
on: string;
|
|
45
|
+
summary?: string;
|
|
46
|
+
message?: string;
|
|
47
|
+
found?: unknown;
|
|
48
|
+
property?: string;
|
|
49
|
+
expected?: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
} & {
|
|
55
|
+
[x: string]: {
|
|
56
|
+
post: {
|
|
57
|
+
body: {
|
|
58
|
+
audience?: string | undefined;
|
|
59
|
+
resource?: string | undefined;
|
|
60
|
+
client_id?: string | undefined;
|
|
61
|
+
scope?: string | undefined;
|
|
62
|
+
refresh_token?: string | undefined;
|
|
63
|
+
client_secret?: string | undefined;
|
|
64
|
+
grant_type?: string | undefined;
|
|
65
|
+
code?: string | undefined;
|
|
66
|
+
redirect_uri?: string | undefined;
|
|
67
|
+
code_verifier?: string | undefined;
|
|
68
|
+
subject_token?: string | undefined;
|
|
69
|
+
subject_token_type?: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
params: {};
|
|
72
|
+
query: unknown;
|
|
73
|
+
headers: unknown;
|
|
74
|
+
response: {
|
|
75
|
+
200: Response;
|
|
76
|
+
422: {
|
|
77
|
+
type: "validation";
|
|
78
|
+
on: string;
|
|
79
|
+
summary?: string;
|
|
80
|
+
message?: string;
|
|
81
|
+
found?: unknown;
|
|
82
|
+
property?: string;
|
|
83
|
+
expected?: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
} & {
|
|
89
|
+
[x: string]: {
|
|
90
|
+
get: {
|
|
91
|
+
body: unknown;
|
|
92
|
+
params: {};
|
|
93
|
+
query: unknown;
|
|
94
|
+
headers: unknown;
|
|
95
|
+
response: {
|
|
96
|
+
200: {
|
|
97
|
+
keys: {
|
|
98
|
+
alg: string;
|
|
99
|
+
crv: string | undefined;
|
|
100
|
+
kid: string;
|
|
101
|
+
kty: string | undefined;
|
|
102
|
+
use: string;
|
|
103
|
+
x: string | undefined;
|
|
104
|
+
y: string | undefined;
|
|
105
|
+
}[];
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
} & {
|
|
111
|
+
".well-known": {
|
|
112
|
+
"openid-configuration": {
|
|
113
|
+
get: {
|
|
114
|
+
body: unknown;
|
|
115
|
+
params: {};
|
|
116
|
+
query: unknown;
|
|
117
|
+
headers: unknown;
|
|
118
|
+
response: {
|
|
119
|
+
200: Record<string, string | string[]>;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
}, {
|
|
125
|
+
derive: {};
|
|
126
|
+
resolve: {};
|
|
127
|
+
schema: {};
|
|
128
|
+
standaloneSchema: {};
|
|
129
|
+
response: {};
|
|
130
|
+
}, {
|
|
131
|
+
derive: {};
|
|
132
|
+
resolve: {};
|
|
133
|
+
schema: {};
|
|
134
|
+
standaloneSchema: {};
|
|
135
|
+
response: {};
|
|
136
|
+
} & {
|
|
137
|
+
derive: {};
|
|
138
|
+
resolve: {};
|
|
139
|
+
schema: {};
|
|
140
|
+
standaloneSchema: {};
|
|
141
|
+
response: {};
|
|
142
|
+
}>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type OAuthClient = {
|
|
2
|
+
clientId: string;
|
|
3
|
+
hashedSecret?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
redirectUris: string[];
|
|
6
|
+
scopes: string[];
|
|
7
|
+
};
|
|
8
|
+
export type OAuthClientStore = {
|
|
9
|
+
findClient: (clientId: string) => Promise<OAuthClient | undefined>;
|
|
10
|
+
};
|
|
11
|
+
export type AuthorizationCode = {
|
|
12
|
+
claims?: Record<string, unknown>;
|
|
13
|
+
clientId: string;
|
|
14
|
+
codeChallenge: string;
|
|
15
|
+
codeHash: string;
|
|
16
|
+
createdAt: number;
|
|
17
|
+
dpopJkt?: string;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
nonce?: string;
|
|
20
|
+
redirectUri: string;
|
|
21
|
+
scopes: string[];
|
|
22
|
+
userId: string;
|
|
23
|
+
};
|
|
24
|
+
export type AuthorizationCodeStore = {
|
|
25
|
+
consumeCode: (codeHash: string) => Promise<AuthorizationCode | undefined>;
|
|
26
|
+
saveCode: (code: AuthorizationCode) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
export type OidcRefreshToken = {
|
|
29
|
+
claims?: Record<string, unknown>;
|
|
30
|
+
clientId: string;
|
|
31
|
+
createdAt: number;
|
|
32
|
+
dpopJkt?: string;
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
scopes: string[];
|
|
35
|
+
tokenHash: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
};
|
|
38
|
+
export type OidcRefreshTokenStore = {
|
|
39
|
+
consumeToken: (tokenHash: string) => Promise<OidcRefreshToken | undefined>;
|
|
40
|
+
deleteForUser: (userId: string) => Promise<void>;
|
|
41
|
+
saveToken: (token: OidcRefreshToken) => Promise<void>;
|
|
42
|
+
};
|
package/dist/portal/routes.d.ts
CHANGED
|
@@ -91,8 +91,8 @@ export declare const portalRoutes: ({ emit, onScimTokenCreated, onSsoConnectionC
|
|
|
91
91
|
oidc: {
|
|
92
92
|
put: {
|
|
93
93
|
body: {
|
|
94
|
-
redirectUri?: string | undefined;
|
|
95
94
|
scopes?: string[] | undefined;
|
|
95
|
+
redirectUri?: string | undefined;
|
|
96
96
|
issuer: string;
|
|
97
97
|
clientId: string;
|
|
98
98
|
clientSecret: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Cookie } from 'elysia';
|
|
2
|
+
import type { SessionData, SessionRecord, UserSessionId } from '../types';
|
|
3
|
+
import type { AuthSessionStore } from './types';
|
|
4
|
+
export declare const createAnonymousSession: <UserType>({ authSessionStore, cookie, guestUser, inMemorySession, sessionDurationMs }: {
|
|
5
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
6
|
+
cookie: Cookie<UserSessionId | undefined>;
|
|
7
|
+
guestUser: UserType;
|
|
8
|
+
inMemorySession: SessionRecord<UserType>;
|
|
9
|
+
sessionDurationMs?: number;
|
|
10
|
+
}) => Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
11
|
+
export declare const isAnonymousSession: <UserType>(session: SessionData<UserType> | undefined) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Cookie } from 'elysia';
|
|
2
|
+
import type { AuditEvent } from '../audit/types';
|
|
3
|
+
import type { SessionData, SessionRecord, UserSessionId } from '../types';
|
|
4
|
+
import type { AuthSessionStore } from './types';
|
|
5
|
+
type Emit = (event: AuditEvent) => Promise<void> | void;
|
|
6
|
+
export declare const endImpersonation: <UserType>({ authSessionStore, cookie, emit, inMemorySession }: {
|
|
7
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
8
|
+
cookie: Cookie<UserSessionId | undefined>;
|
|
9
|
+
emit?: Emit;
|
|
10
|
+
inMemorySession: SessionRecord<UserType>;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
restored: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const isImpersonating: <UserType>(session: SessionData<UserType> | undefined) => boolean;
|
|
15
|
+
export declare const startImpersonation: <UserType>({ authSessionStore, cookie, emit, getUserId, impersonator, inMemorySession, sessionDurationMs, user }: {
|
|
16
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
17
|
+
cookie: Cookie<UserSessionId | undefined>;
|
|
18
|
+
emit?: Emit;
|
|
19
|
+
getUserId?: (user: UserType) => string;
|
|
20
|
+
impersonator: {
|
|
21
|
+
actorEmail?: string;
|
|
22
|
+
actorId: string;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
inMemorySession: SessionRecord<UserType>;
|
|
26
|
+
sessionDurationMs?: number;
|
|
27
|
+
user: UserType;
|
|
28
|
+
}) => Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Cookie } from 'elysia';
|
|
2
|
+
import type { SessionRecord, UserSessionId } from '../types';
|
|
3
|
+
import type { AuthSessionStore } from './types';
|
|
4
|
+
export declare const addToSessionRing: (ring: Cookie<string | undefined>, sessionId: UserSessionId) => Cookie<string | undefined>;
|
|
5
|
+
export declare const listRingSessions: <UserType>({ authSessionStore, inMemorySession, ring }: {
|
|
6
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
7
|
+
inMemorySession?: SessionRecord<UserType>;
|
|
8
|
+
ring: Cookie<string | undefined>;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
sessionId: UserSessionId;
|
|
11
|
+
user: UserType;
|
|
12
|
+
}[]>;
|
|
13
|
+
export declare const readSessionRing: (ring: Cookie<string | undefined>) => `${string}-${string}-${string}-${string}-${string}`[];
|
|
14
|
+
export declare const removeFromSessionRing: <UserType>({ activeCookie, authSessionStore, inMemorySession, ring, sessionId }: {
|
|
15
|
+
activeCookie?: Cookie<UserSessionId | undefined>;
|
|
16
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
17
|
+
inMemorySession?: SessionRecord<UserType>;
|
|
18
|
+
ring: Cookie<string | undefined>;
|
|
19
|
+
sessionId: UserSessionId;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
export declare const switchActiveSession: ({ activeCookie, ring, sessionId }: {
|
|
22
|
+
activeCookie: Cookie<UserSessionId | undefined>;
|
|
23
|
+
ring: Cookie<string | undefined>;
|
|
24
|
+
sessionId: UserSessionId;
|
|
25
|
+
}) => boolean;
|
|
@@ -9,12 +9,14 @@ type ClearSessionProps<UserType> = {
|
|
|
9
9
|
export declare const clearSession: <UserType>({ authSessionStore, cookie, inMemorySession }: ClearSessionProps<UserType>) => Promise<void>;
|
|
10
10
|
export declare const persistWhen: (shouldPersist: boolean, persist: () => Promise<void>) => Promise<void>;
|
|
11
11
|
type PromoteToSessionProps<UserType> = {
|
|
12
|
+
anonymous?: boolean;
|
|
12
13
|
authSessionStore?: AuthSessionStore<UserType>;
|
|
13
14
|
cookie: Cookie<UserSessionId | undefined>;
|
|
15
|
+
impersonator?: SessionData<UserType>['impersonator'];
|
|
14
16
|
inMemorySession: SessionRecord<UserType>;
|
|
15
17
|
samlLogout?: SessionData<UserType>['samlLogout'];
|
|
16
18
|
sessionDurationMs: number;
|
|
17
19
|
user: UserType;
|
|
18
20
|
};
|
|
19
|
-
export declare const promoteToSession: <UserType>({ authSessionStore, cookie, inMemorySession, samlLogout, sessionDurationMs, user }: PromoteToSessionProps<UserType>) => Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
21
|
+
export declare const promoteToSession: <UserType>({ anonymous, authSessionStore, cookie, impersonator, inMemorySession, samlLogout, sessionDurationMs, user }: PromoteToSessionProps<UserType>) => Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
20
22
|
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CredentialsFor, NonEmptyArray, OAuth2Client, OAuth2TokenResponse, ProviderOption, ProvidersMap } from 'citra';
|
|
2
2
|
import { Cookie, status as statusType, redirect as redirectType } from 'elysia';
|
|
3
3
|
import { ElysiaCustomStatusResponse } from 'elysia/error';
|
|
4
|
+
import type { ApiKeysConfig } from './apikeys/config';
|
|
4
5
|
import type { AuditConfig } from './audit/config';
|
|
5
6
|
import type { AuthorizationConfig } from './authorization/config';
|
|
6
7
|
import type { ComplianceConfig } from './compliance/config';
|
|
@@ -9,6 +10,7 @@ import type { AuthIdentityConflict } from './errors';
|
|
|
9
10
|
import type { AuthHtmxConfig, AuthHtmxUser } from './htmx/types';
|
|
10
11
|
import type { LockoutConfig } from './lockout/config';
|
|
11
12
|
import type { MfaConfig } from './mfa/config';
|
|
13
|
+
import type { OidcProviderConfig } from './oidc/config';
|
|
12
14
|
import type { OrganizationsConfig } from './organizations/config';
|
|
13
15
|
import type { PasswordlessConfig } from './passwordless/config';
|
|
14
16
|
import type { PortalConfig } from './portal/config';
|
|
@@ -33,6 +35,17 @@ export type OAuth2ConfigurationOptions = {
|
|
|
33
35
|
[Provider in ProviderOption]?: OAuth2ProviderConfiguration<Provider>;
|
|
34
36
|
};
|
|
35
37
|
export type UserSessionId = `${string}-${string}-${string}-${string}-${string}`;
|
|
38
|
+
/** Stamped on a session created via admin impersonation (`startImpersonation`). RFC 8693
|
|
39
|
+
* actor semantics: `actorId`/`actorEmail` are the admin acting as the user, `reason` is
|
|
40
|
+
* required and audited, `returnToSessionId` is the admin's own session to restore on exit.
|
|
41
|
+
* Surfaced by userStatus so your UI can show an "impersonating" banner. */
|
|
42
|
+
export type Impersonator = {
|
|
43
|
+
actorEmail?: string;
|
|
44
|
+
actorId: string;
|
|
45
|
+
reason: string;
|
|
46
|
+
returnToSessionId?: UserSessionId;
|
|
47
|
+
startedAt: number;
|
|
48
|
+
};
|
|
36
49
|
export type SessionData<UserType> = {
|
|
37
50
|
user: UserType;
|
|
38
51
|
/** OAuth provider access token. Optional: credential / SSO sessions are not backed
|
|
@@ -52,6 +65,11 @@ export type SessionData<UserType> = {
|
|
|
52
65
|
nameId: string;
|
|
53
66
|
sessionIndex?: string;
|
|
54
67
|
};
|
|
68
|
+
/** Present only when this session was created via admin impersonation. */
|
|
69
|
+
impersonator?: Impersonator;
|
|
70
|
+
/** True for a guest/anonymous session (createAnonymousSession) that can later be
|
|
71
|
+
* upgraded by a real login. */
|
|
72
|
+
anonymous?: boolean;
|
|
55
73
|
};
|
|
56
74
|
export type SessionRecord<UserType> = Record<UserSessionId, SessionData<UserType>>;
|
|
57
75
|
export type UnregisteredSessionData = {
|
|
@@ -213,6 +231,20 @@ export type AuthConfig<UserType> = {
|
|
|
213
231
|
* mounts `{scimRoute}/Users` (+ `/ServiceProviderConfig`) with per-org bearer-token auth via
|
|
214
232
|
* `scimTokenStore`, and maps SCIM resources to the consumer's user store through hooks. */
|
|
215
233
|
scim?: ScimConfig;
|
|
234
|
+
/** Machine-to-machine authentication: static API keys (`sk_…`) + the OAuth2
|
|
235
|
+
* client_credentials grant. When `apiClientStore` + `accessTokenStore` are set,
|
|
236
|
+
* mounts `{tokenRoute}` (defaults `/oauth2/token`) so registered clients can
|
|
237
|
+
* exchange `client_id`/`client_secret` for short-lived `at_…` access tokens.
|
|
238
|
+
* Pair with the exported `createApiKey` / `resolveApiPrincipal` / `hasScopes`
|
|
239
|
+
* helpers to issue and guard with static keys. */
|
|
240
|
+
apikeys?: ApiKeysConfig;
|
|
241
|
+
/** OAuth2 / OIDC provider — makes your app an identity provider ("Sign in with
|
|
242
|
+
* <yourapp>"). Mounts `{oidcRoute}/authorize` + `/token` + `/jwks` and
|
|
243
|
+
* `/.well-known/openid-configuration`: authorization_code + mandatory PKCE, ES256
|
|
244
|
+
* JWTs signed by a key you own (self-hosted JWKS), refresh-token rotation, and
|
|
245
|
+
* optional DPoP (RFC 9449) sender-constrained tokens. The authorize endpoint reuses
|
|
246
|
+
* the package session, so the IdP login gets passkeys / MFA / SSO for free. */
|
|
247
|
+
oidc?: OidcProviderConfig<UserType>;
|
|
216
248
|
/** First-class multi-tenancy (the WorkOS model). When present, mounts organization +
|
|
217
249
|
* membership + invitation routes under `{organizationsRoute}`: list the caller's orgs, create
|
|
218
250
|
* one (caller becomes owner), invite/accept/revoke by email, and list/remove members. Ties the
|
package/package.json
CHANGED