@absolutejs/auth 0.65.1 → 0.65.2
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/actions.d.ts +27 -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 +245 -0
- package/dist/adaptive/types.d.ts +62 -0
- package/dist/agents/config.d.ts +49 -0
- package/dist/agents/context.d.ts +46 -0
- package/dist/agents/idJag.d.ts +49 -0
- package/dist/agents/inMemoryStores.d.ts +4 -0
- package/dist/agents/index.d.ts +13 -0
- package/dist/agents/oauthGuide.d.ts +18 -0
- package/dist/agents/oidcAdapter.d.ts +20 -0
- package/dist/agents/postgresStores.d.ts +1176 -0
- package/dist/agents/principal.d.ts +4 -0
- package/dist/agents/registration.d.ts +162 -0
- package/dist/agents/registrationClient.d.ts +50 -0
- package/dist/agents/routes.d.ts +256 -0
- package/dist/agents/types.d.ts +129 -0
- package/dist/apikeys/config.d.ts +64 -0
- package/dist/apikeys/inMemoryStores.d.ts +4 -0
- package/dist/apikeys/postgresStores.d.ts +359 -0
- package/dist/apikeys/routes.d.ts +83 -0
- package/dist/apikeys/types.d.ts +53 -0
- package/dist/audit/config.d.ts +9 -0
- package/dist/audit/export.d.ts +2 -0
- package/dist/audit/inMemoryAuditStore.d.ts +2 -0
- package/dist/audit/integrity.d.ts +19 -0
- package/dist/audit/postgresAuditStore.d.ts +116 -0
- package/dist/audit/siem.d.ts +11 -0
- package/dist/audit/types.d.ts +21 -0
- package/dist/audit/wrap.d.ts +11 -0
- package/dist/authContext.d.ts +193 -0
- package/dist/authorization/config.d.ts +19 -0
- package/dist/authorization/protectPermission.d.ts +52 -0
- package/dist/cli/import/auth0.d.ts +2 -0
- package/dist/cli/import/clerk.d.ts +2 -0
- package/dist/cli/import/index.d.ts +10 -0
- package/dist/cli/import/lucia.d.ts +2 -0
- package/dist/cli/import/nextauth.d.ts +2 -0
- package/dist/cli/import/supabase.d.ts +2 -0
- package/dist/cli/import/types.d.ts +27 -0
- package/dist/cli/migrate.d.ts +2 -0
- package/dist/client/components/react/SignIn.d.ts +32 -0
- package/dist/client/components/react/SignUp.d.ts +29 -0
- package/dist/client/components/react/UserButton.d.ts +36 -0
- package/dist/client/createAuthClient.d.ts +285 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/passkeyHelpers.d.ts +19 -0
- package/dist/client/react.d.ts +87 -0
- package/dist/client/sessionExpiry.d.ts +37 -0
- package/dist/client/solid.d.ts +86 -0
- package/dist/client/svelte.d.ts +86 -0
- package/dist/client/vue.d.ts +88 -0
- package/dist/compliance/cipher.d.ts +11 -0
- package/dist/compliance/config.d.ts +18 -0
- package/dist/compliance/redaction.d.ts +8 -0
- package/dist/compliance/routes.d.ts +89 -0
- package/dist/constants.d.ts +10 -0
- package/dist/credentials/backgroundOps.d.ts +45 -0
- package/dist/credentials/config.d.ts +94 -0
- package/dist/credentials/emailValidation.d.ts +9 -0
- package/dist/credentials/emailVerification.d.ts +83 -0
- package/dist/credentials/import.d.ts +49 -0
- package/dist/credentials/inMemoryCredentialStore.d.ts +2 -0
- package/dist/credentials/legacyHashers.d.ts +3 -0
- package/dist/credentials/login.d.ts +76 -0
- package/dist/credentials/passwordPolicy.d.ts +15 -0
- package/dist/credentials/passwordReset.d.ts +87 -0
- package/dist/credentials/postgresCredentialStore.d.ts +235 -0
- package/dist/credentials/register.d.ts +54 -0
- package/dist/credentials/routes.d.ts +201 -0
- package/dist/credentials/types.d.ts +26 -0
- package/dist/crypto.d.ts +32 -0
- package/dist/csrf.d.ts +10 -0
- package/dist/errors.d.ts +12 -0
- package/dist/federation/tokenStore.d.ts +29 -0
- package/dist/fga/config.d.ts +53 -0
- package/dist/fga/inMemoryStores.d.ts +3 -0
- package/dist/fga/postgresStores.d.ts +116 -0
- package/dist/fga/redisCheckCache.d.ts +11 -0
- package/dist/fga/schema.d.ts +2 -0
- package/dist/fga/types.d.ts +28 -0
- package/dist/fingerprint-client/index.d.ts +26 -0
- package/dist/htmx/configuredRoutes.d.ts +542 -0
- package/dist/htmx/index.d.ts +2 -0
- package/dist/htmx/renderers.d.ts +8 -0
- package/dist/htmx/routes.d.ts +514 -0
- package/dist/htmx/types.d.ts +129 -0
- package/dist/index.d.ts +3647 -0
- package/dist/linkedProviders/inMemoryStores.d.ts +9 -0
- package/dist/linkedProviders/index.d.ts +3 -0
- package/dist/linkedProviders/neonStores.d.ts +484 -0
- package/dist/linkedProviders/oauthAccountResolver.d.ts +28 -0
- package/dist/linkedProviders/oauthResolver.d.ts +9 -0
- package/dist/linkedProviders/resolver.d.ts +22 -0
- package/dist/lockout/config.d.ts +17 -0
- package/dist/lockout/inMemoryLockoutStore.d.ts +2 -0
- package/dist/lockout/postgresLockoutStore.d.ts +71 -0
- package/dist/lockout/redisLockoutStore.d.ts +3 -0
- package/dist/lockout/types.d.ts +12 -0
- package/dist/manifest.d.ts +18 -0
- package/dist/manifest.json +373 -0
- package/dist/mfa/backupCodes.d.ts +5 -0
- package/dist/mfa/challenge.d.ts +72 -0
- package/dist/mfa/config.d.ts +59 -0
- package/dist/mfa/gate.d.ts +2 -0
- package/dist/mfa/inMemoryMfaStore.d.ts +2 -0
- package/dist/mfa/management.d.ts +106 -0
- package/dist/mfa/postgresMfaStore.d.ts +266 -0
- package/dist/mfa/recentAuth.d.ts +2 -0
- package/dist/mfa/rotation.d.ts +17 -0
- package/dist/mfa/routes.d.ts +239 -0
- package/dist/mfa/secret.d.ts +2 -0
- package/dist/mfa/sms.d.ts +143 -0
- package/dist/mfa/totp.d.ts +91 -0
- package/dist/mfa/types.d.ts +58 -0
- package/dist/migrations/generate.d.ts +2 -0
- package/dist/migrations/index.d.ts +6 -0
- package/dist/migrations/runner.d.ts +22 -0
- package/dist/migrations/types.d.ts +14 -0
- package/dist/oidc/clientAuth.d.ts +19 -0
- package/dist/oidc/clientIdMetadata.d.ts +28 -0
- package/dist/oidc/config.d.ts +307 -0
- package/dist/oidc/dpop.d.ts +23 -0
- package/dist/oidc/inMemoryStores.d.ts +11 -0
- package/dist/oidc/inMemoryVciStores.d.ts +3 -0
- package/dist/oidc/index.d.ts +12 -0
- package/dist/oidc/jar.d.ts +14 -0
- package/dist/oidc/keys.d.ts +50 -0
- package/dist/oidc/logout.d.ts +38 -0
- package/dist/oidc/mtls.d.ts +11 -0
- package/dist/oidc/operator.d.ts +14 -0
- package/dist/oidc/par.d.ts +28 -0
- package/dist/oidc/postgresStores.d.ts +1217 -0
- package/dist/oidc/registration.d.ts +138 -0
- package/dist/oidc/routes.d.ts +569 -0
- package/dist/oidc/types.d.ts +157 -0
- package/dist/oidc/userinfo.d.ts +21 -0
- package/dist/oidc/vci.d.ts +159 -0
- package/dist/oidc/vciRoutes.d.ts +92 -0
- package/dist/organizations/config.d.ts +46 -0
- package/dist/organizations/inMemoryOrganizationStore.d.ts +2 -0
- package/dist/organizations/operations.d.ts +39 -0
- package/dist/organizations/postgresOrganizationStore.d.ts +340 -0
- package/dist/organizations/routes.d.ts +299 -0
- package/dist/organizations/types.d.ts +45 -0
- package/dist/passwordless/config.d.ts +43 -0
- package/dist/passwordless/inMemoryPasswordlessTokenStore.d.ts +2 -0
- package/dist/passwordless/postgresPasswordlessTokenStore.d.ts +56 -0
- package/dist/passwordless/routes.d.ts +163 -0
- package/dist/passwordless/types.d.ts +9 -0
- package/dist/pluginIdentity.d.ts +2 -0
- package/dist/plugins/denyDisposableEmail.d.ts +7 -0
- package/dist/plugins/discordAlert.d.ts +7 -0
- package/dist/plugins/geoBlock.d.ts +8 -0
- package/dist/plugins/index.d.ts +12 -0
- package/dist/plugins/pagerdutyAlert.d.ts +9 -0
- package/dist/plugins/posthogIdentify.d.ts +7 -0
- package/dist/plugins/slackAlert.d.ts +7 -0
- package/dist/portal/config.d.ts +34 -0
- package/dist/portal/inMemorySetupSessionStore.d.ts +2 -0
- package/dist/portal/operations.d.ts +10 -0
- package/dist/portal/postgresSetupSessionStore.d.ts +116 -0
- package/dist/portal/routes.d.ts +160 -0
- package/dist/portal/types.d.ts +16 -0
- package/dist/providers/clients.d.ts +1831 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providersFromEnv.d.ts +19 -0
- package/dist/redirect.d.ts +2 -0
- package/dist/roles/config.d.ts +27 -0
- package/dist/roles/inMemoryRoleStore.d.ts +2 -0
- package/dist/roles/operations.d.ts +8 -0
- package/dist/roles/postgresRoleStore.d.ts +86 -0
- package/dist/roles/resolver.d.ts +17 -0
- package/dist/roles/routes.d.ts +106 -0
- package/dist/roles/types.d.ts +14 -0
- package/dist/routes/authorize.d.ts +102 -0
- package/dist/routes/callback.d.ts +64 -0
- package/dist/routes/profile.d.ts +73 -0
- package/dist/routes/protectRoute.d.ts +51 -0
- package/dist/routes/refresh.d.ts +74 -0
- package/dist/routes/requireAuth.d.ts +43 -0
- package/dist/routes/revoke.d.ts +73 -0
- package/dist/routes/sessions.d.ts +103 -0
- package/dist/routes/signout.d.ts +70 -0
- package/dist/routes/stepUp.d.ts +48 -0
- package/dist/routes/userStatus.d.ts +72 -0
- package/dist/saml.d.ts +1 -0
- package/dist/scim/config.d.ts +57 -0
- package/dist/scim/extensions.d.ts +30 -0
- package/dist/scim/inMemoryScimTokenStore.d.ts +2 -0
- package/dist/scim/postgresScimTokenStore.d.ts +86 -0
- package/dist/scim/routes.d.ts +366 -0
- package/dist/scim/serialize.d.ts +83 -0
- package/dist/scim/types.d.ts +54 -0
- package/dist/server.d.ts +34 -0
- package/dist/session/access.d.ts +33 -0
- package/dist/session/anonymous.d.ts +12 -0
- package/dist/session/cleanup.d.ts +45 -0
- package/dist/session/cookieReader.d.ts +10 -0
- package/dist/session/impersonation.d.ts +34 -0
- package/dist/session/inMemoryStore.d.ts +7 -0
- package/dist/session/multiSession.d.ts +27 -0
- package/dist/session/neonStore.d.ts +573 -0
- package/dist/session/promote.d.ts +23 -0
- package/dist/session/redisStore.d.ts +6 -0
- package/dist/session/sessionsConfig.d.ts +9 -0
- package/dist/session/state.d.ts +33 -0
- package/dist/session/types.d.ts +23 -0
- package/dist/session/userSessions.d.ts +19 -0
- package/dist/sso/config.d.ts +149 -0
- package/dist/sso/discoveryRoute.d.ts +63 -0
- package/dist/sso/inMemorySamlServiceProviderStore.d.ts +2 -0
- package/dist/sso/inMemorySsoConnectionStore.d.ts +2 -0
- package/dist/sso/nodeSamlAdapter.d.ts +8 -0
- package/dist/sso/oidcRoutes.d.ts +98 -0
- package/dist/sso/postgresSamlServiceProviderStore.d.ts +101 -0
- package/dist/sso/postgresSsoConnectionStore.d.ts +117 -0
- package/dist/sso/samlIdpRoutes.d.ts +139 -0
- package/dist/sso/samlRoutes.d.ts +179 -0
- package/dist/sso/types.d.ts +53 -0
- package/dist/stores/postgres.d.ts +5 -0
- package/dist/stores/redis.d.ts +5 -0
- package/dist/telemetry/tracing.d.ts +15 -0
- package/dist/tenancy.d.ts +9 -0
- package/dist/typeGuards.d.ts +6 -0
- package/dist/typebox.d.ts +4 -0
- package/dist/types.d.ts +431 -0
- package/dist/utils.d.ts +45 -0
- package/dist/vault/config.d.ts +20 -0
- package/dist/vault/inMemoryVaultStore.d.ts +2 -0
- package/dist/vault/index.d.ts +5 -0
- package/dist/vault/postgresVaultStore.d.ts +86 -0
- package/dist/vault/types.d.ts +14 -0
- package/dist/vc/inMemoryVpStores.d.ts +2 -0
- package/dist/vc/openid4vp.d.ts +82 -0
- package/dist/vc/postgresVcStores.d.ts +300 -0
- package/dist/vc/sdJwt.d.ts +37 -0
- package/dist/vc/statusList.d.ts +29 -0
- package/dist/vc/statusListRoutes.d.ts +63 -0
- package/dist/vc/vpRoutes.d.ts +120 -0
- package/dist/verification/types.d.ts +58 -0
- package/dist/webauthn/adapter.d.ts +59 -0
- package/dist/webauthn/config.d.ts +36 -0
- package/dist/webauthn/inMemoryWebAuthnCredentialStore.d.ts +2 -0
- package/dist/webauthn/postgresWebAuthnCredentialStore.d.ts +146 -0
- package/dist/webauthn/routes.d.ts +155 -0
- package/dist/webauthn/simpleWebAuthnAdapter.d.ts +3 -0
- package/dist/webauthn/types.d.ts +17 -0
- package/dist/webauthn.d.ts +1 -0
- package/dist/webhooks/config.d.ts +34 -0
- package/dist/webhooks/dispatcher.d.ts +3 -0
- package/dist/webhooks/inMemoryStore.d.ts +2 -0
- package/dist/webhooks/postgresStore.d.ts +116 -0
- package/dist/webhooks/sign.d.ts +11 -0
- package/dist/webhooks/types.d.ts +25 -0
- package/package.json +1 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { CredentialsFor, CustomProviderCredentials, NonEmptyArray, OAuth2Client, OAuth2TokenResponse, ProviderConfig, ProviderOption, ProvidersMap } from 'citra';
|
|
2
|
+
import { Cookie, status as statusType, redirect as redirectType } from 'elysia';
|
|
3
|
+
import { ElysiaCustomStatusResponse } from 'elysia/error';
|
|
4
|
+
import type { StatusMap } from 'elysia/utils';
|
|
5
|
+
import type { ApiKeysConfig } from './apikeys/config';
|
|
6
|
+
import type { AgentAuthConfig } from './agents/config';
|
|
7
|
+
import type { AuditConfig } from './audit/config';
|
|
8
|
+
import type { AuthorizationConfig } from './authorization/config';
|
|
9
|
+
import type { ComplianceConfig } from './compliance/config';
|
|
10
|
+
import type { CredentialsConfig } from './credentials/config';
|
|
11
|
+
import type { AuthIdentityConflict } from './errors';
|
|
12
|
+
import type { AuthHtmxConfig, AuthHtmxUser } from './htmx/types';
|
|
13
|
+
import type { LockoutConfig } from './lockout/config';
|
|
14
|
+
import type { MfaConfig } from './mfa/config';
|
|
15
|
+
import type { VerificationProvider } from './verification/types';
|
|
16
|
+
import type { OidcProviderConfig } from './oidc/config';
|
|
17
|
+
import type { OrganizationsConfig } from './organizations/config';
|
|
18
|
+
import type { PasswordlessConfig } from './passwordless/config';
|
|
19
|
+
import type { PortalConfig } from './portal/config';
|
|
20
|
+
import type { RolesConfig } from './roles/config';
|
|
21
|
+
import type { ScimConfig } from './scim/config';
|
|
22
|
+
import type { SessionsConfig } from './session/sessionsConfig';
|
|
23
|
+
import type { AuthSessionStore } from './session/types';
|
|
24
|
+
import type { SSOConfig } from './sso/config';
|
|
25
|
+
import type { TracingConfig } from './telemetry/tracing';
|
|
26
|
+
import type { WebAuthnConfig } from './webauthn/config';
|
|
27
|
+
import type { WebhooksConfig } from './webhooks/config';
|
|
28
|
+
export type AuthIntent = 'login' | 'link_identity' | 'link_connector';
|
|
29
|
+
export type OAuth2ProviderClientConfiguration<Provider extends ProviderOption> = {
|
|
30
|
+
credentials: CredentialsFor<Provider>;
|
|
31
|
+
searchParams?: [string, string][];
|
|
32
|
+
} & (ProvidersMap[Provider]['scopeRequired'] extends true ? {
|
|
33
|
+
scope: NonEmptyArray<string>;
|
|
34
|
+
} : {
|
|
35
|
+
scope?: string[];
|
|
36
|
+
});
|
|
37
|
+
export type OAuth2ProviderConfiguration<Provider extends ProviderOption> = OAuth2ProviderClientConfiguration<Provider> | Record<string, OAuth2ProviderClientConfiguration<Provider>>;
|
|
38
|
+
export type OAuth2ConfigurationOptions = {
|
|
39
|
+
[Provider in ProviderOption]?: OAuth2ProviderConfiguration<Provider>;
|
|
40
|
+
};
|
|
41
|
+
/** One client of a caller-defined (custom) OAuth provider: the full citra
|
|
42
|
+
* ProviderConfig plus this app's credentials. Same optional scope /
|
|
43
|
+
* searchParams knobs as built-in provider clients. */
|
|
44
|
+
export type CustomProviderClientConfiguration = {
|
|
45
|
+
credentials: CustomProviderCredentials;
|
|
46
|
+
providerConfig: ProviderConfig;
|
|
47
|
+
scope?: string[];
|
|
48
|
+
searchParams?: [string, string][];
|
|
49
|
+
};
|
|
50
|
+
/** Caller-defined providers keyed by YOUR provider name (any key that isn't a
|
|
51
|
+
* built-in citra provider). Single client or named client variants — the same
|
|
52
|
+
* shape as providersConfiguration. Registered providers get the full route
|
|
53
|
+
* set (authorize/callback/refresh/revoke/linked-providers) like built-ins. */
|
|
54
|
+
export type CustomProvidersConfiguration = Record<string, CustomProviderClientConfiguration | Record<string, CustomProviderClientConfiguration>>;
|
|
55
|
+
export type UserSessionId = `${string}-${string}-${string}-${string}-${string}`;
|
|
56
|
+
/** Stamped on a session created via admin impersonation (`startImpersonation`). RFC 8693
|
|
57
|
+
* actor semantics: `actorId`/`actorEmail` are the admin acting as the user, `reason` is
|
|
58
|
+
* required and audited, `returnToSessionId` is the admin's own session to restore on exit.
|
|
59
|
+
* Surfaced by userStatus so your UI can show an "impersonating" banner.
|
|
60
|
+
*
|
|
61
|
+
* `readOnly` is the RFC 8693 §6 "down-scope the delegated session" lever, surfaced for the
|
|
62
|
+
* app to enforce: when true this is a GHOST/observe-only session — the app should reject
|
|
63
|
+
* writes (and suppress side-effects) so an admin can watch a member's account without
|
|
64
|
+
* disturbing them. The package only CARRIES the flag (it can't know your routes); enforce
|
|
65
|
+
* it in your own request guard. Absent/false = full-access acting session. */
|
|
66
|
+
export type Impersonator = {
|
|
67
|
+
actorEmail?: string;
|
|
68
|
+
actorId: string;
|
|
69
|
+
readOnly?: boolean;
|
|
70
|
+
reason: string;
|
|
71
|
+
returnToSessionId?: UserSessionId;
|
|
72
|
+
startedAt: number;
|
|
73
|
+
/** Sandbox lever, surfaced for the app to enforce: when true, the app should
|
|
74
|
+
* suppress outbound side-effects (emails / SMS / push / notifications)
|
|
75
|
+
* triggered while acting as the member — so an admin can run a flow and watch
|
|
76
|
+
* the behavior WITHOUT the member or their partners being contacted. Like
|
|
77
|
+
* `readOnly`, the package only carries it; enforce it at your emitters.
|
|
78
|
+
* Independent of `readOnly` (a session can act AND suppress = "sandbox"). */
|
|
79
|
+
suppressSideEffects?: boolean;
|
|
80
|
+
};
|
|
81
|
+
export type SessionData<UserType> = {
|
|
82
|
+
/** Snapshot of your user, serialized into the session at login and handed to
|
|
83
|
+
* `protectRoute`/`userStatus` as-is — it is NOT re-read from your user table per
|
|
84
|
+
* request. Mutations made after login (role grants, bans, tier changes) stay
|
|
85
|
+
* invisible to existing sessions until you rewrite the snapshot with
|
|
86
|
+
* `refreshUserSessions`. */
|
|
87
|
+
user: UserType;
|
|
88
|
+
/** OAuth provider access token. Optional: credential / SSO sessions are not backed
|
|
89
|
+
* by a provider token, so they omit it. Only the OAuth routes (profile, refresh,
|
|
90
|
+
* revoke) read it, and they are all gated on an `auth_provider`. */
|
|
91
|
+
accessToken?: string;
|
|
92
|
+
refreshToken?: string;
|
|
93
|
+
/** Normalized OAuth subject retained for provider operations that target an
|
|
94
|
+
* account identifier instead of a token, such as Withings revocation. */
|
|
95
|
+
oauthSubject?: string | number;
|
|
96
|
+
expiresAt: number;
|
|
97
|
+
/** When the session was last established by an actual authentication (login, OAuth
|
|
98
|
+
* callback, or MFA challenge — NOT a token refresh). Drives step-up `requireRecentAuth`. */
|
|
99
|
+
authenticatedAt?: number;
|
|
100
|
+
/** SAML SP-initiated Single Logout context, captured at the SAML ACS. Lets
|
|
101
|
+
* `{ssoRoute}/saml/:org/logout` build a signed LogoutRequest (the IdP needs the original
|
|
102
|
+
* NameID + SessionIndex) for the connection the session was created from. */
|
|
103
|
+
samlLogout?: {
|
|
104
|
+
connectionId: string;
|
|
105
|
+
nameId: string;
|
|
106
|
+
sessionIndex?: string;
|
|
107
|
+
};
|
|
108
|
+
/** Present only when this session was created via admin impersonation. */
|
|
109
|
+
impersonator?: Impersonator;
|
|
110
|
+
/** True for a guest/anonymous session (createAnonymousSession) that can later be
|
|
111
|
+
* upgraded by a real login. */
|
|
112
|
+
anonymous?: boolean;
|
|
113
|
+
};
|
|
114
|
+
export type SessionRecord<UserType> = Record<UserSessionId, SessionData<UserType>>;
|
|
115
|
+
export type UnregisteredSessionData = {
|
|
116
|
+
userIdentity?: Record<string, unknown>;
|
|
117
|
+
sessionInformation?: Record<string, unknown>;
|
|
118
|
+
expiresAt: number;
|
|
119
|
+
accessToken?: string;
|
|
120
|
+
refreshToken?: string;
|
|
121
|
+
oauthSubject?: string | number;
|
|
122
|
+
};
|
|
123
|
+
export type UnregisteredSessionRecord = Record<UserSessionId, UnregisteredSessionData>;
|
|
124
|
+
export type ResolvedOAuthAuthorization = {
|
|
125
|
+
userIdentity: Record<string, unknown>;
|
|
126
|
+
accessToken: string;
|
|
127
|
+
oauthSubject?: string | number;
|
|
128
|
+
refreshToken?: string;
|
|
129
|
+
expiresAt?: number;
|
|
130
|
+
tokenType?: string;
|
|
131
|
+
};
|
|
132
|
+
export type StatusReturn = Pick<ElysiaCustomStatusResponse<number | keyof StatusMap, unknown>, 'code' | 'response'>;
|
|
133
|
+
export type OnNewUser<UserType> = (userIdentity: Record<string, unknown>) => UserType | StatusReturn | Response | Promise<UserType | StatusReturn | Response>;
|
|
134
|
+
export type GetUser<UserType> = (userIdentity: Record<string, unknown>) => UserType | StatusReturn | Response | null | undefined | Promise<UserType | StatusReturn | Response | null | undefined>;
|
|
135
|
+
export type CallbackCookie = Record<string, Cookie<unknown>> & {
|
|
136
|
+
auth_client: Cookie<string | undefined>;
|
|
137
|
+
auth_intent: Cookie<AuthIntent | undefined>;
|
|
138
|
+
user_session_id: Cookie<UserSessionId | undefined>;
|
|
139
|
+
};
|
|
140
|
+
export type CallbackContext<UserType> = {
|
|
141
|
+
providerInstance: OAuth2Client<ProviderOption>;
|
|
142
|
+
/** Configured provider name — a built-in citra key or a customProviders key. */
|
|
143
|
+
authProvider: string;
|
|
144
|
+
/** The provider's citra config — pass to instantiateUserSession so identity
|
|
145
|
+
* extraction works for custom providers too. */
|
|
146
|
+
providerConfiguration: ProviderConfig;
|
|
147
|
+
authClient?: string;
|
|
148
|
+
authIntent: AuthIntent;
|
|
149
|
+
tokenResponse: OAuth2TokenResponse;
|
|
150
|
+
session: SessionRecord<UserType>;
|
|
151
|
+
unregisteredSession: UnregisteredSessionRecord;
|
|
152
|
+
userSessionId: UserSessionId;
|
|
153
|
+
originUrl: string;
|
|
154
|
+
cookie: CallbackCookie;
|
|
155
|
+
currentUser?: UserType;
|
|
156
|
+
status: typeof statusType;
|
|
157
|
+
redirect: typeof redirectType;
|
|
158
|
+
};
|
|
159
|
+
export type ResolveAuthIntent<UserType> = (({ authProvider, authClient, originUrl, session, userSessionId, currentUser }: {
|
|
160
|
+
authProvider: string;
|
|
161
|
+
authClient?: string;
|
|
162
|
+
originUrl: string;
|
|
163
|
+
session: SessionRecord<UserType>;
|
|
164
|
+
userSessionId?: UserSessionId;
|
|
165
|
+
currentUser?: UserType;
|
|
166
|
+
}) => AuthIntent | Promise<AuthIntent>) | undefined;
|
|
167
|
+
export type OnCallbackSuccess<UserType> = ((context: CallbackContext<UserType>) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
168
|
+
export type OnLinkIdentity<UserType> = ((context: CallbackContext<UserType>) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
169
|
+
export type OnLinkIdentityConflict<UserType> = ((context: CallbackContext<UserType> & {
|
|
170
|
+
conflict: AuthIdentityConflict;
|
|
171
|
+
}) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
172
|
+
export type OnLinkConnector<UserType> = ((context: CallbackContext<UserType>) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
173
|
+
export type OnCallbackError = (({ error, authProvider, originUrl }: {
|
|
174
|
+
authProvider: string;
|
|
175
|
+
authClient?: string;
|
|
176
|
+
error: unknown;
|
|
177
|
+
originUrl: string;
|
|
178
|
+
}) => void | Promise<void>) | undefined;
|
|
179
|
+
export type OnAuthorizeSuccess = (({ authProvider, authClient, authIntent, authorizationUrl }: {
|
|
180
|
+
authProvider: string;
|
|
181
|
+
authClient?: string;
|
|
182
|
+
authIntent?: AuthIntent;
|
|
183
|
+
authorizationUrl: URL;
|
|
184
|
+
}) => void | Promise<void>) | undefined;
|
|
185
|
+
export type OnAuthorizeError = (({ error, authProvider }: {
|
|
186
|
+
authProvider: string;
|
|
187
|
+
authClient?: string;
|
|
188
|
+
error: unknown;
|
|
189
|
+
}) => void | Promise<void>) | undefined;
|
|
190
|
+
export type OnRefreshSuccess = (({ tokenResponse, authProvider }: {
|
|
191
|
+
tokenResponse: OAuth2TokenResponse;
|
|
192
|
+
authProvider: string;
|
|
193
|
+
authClient?: string;
|
|
194
|
+
}) => void | Promise<void>) | undefined;
|
|
195
|
+
export type OnRefreshError = (({ error, authProvider }: {
|
|
196
|
+
authProvider: string;
|
|
197
|
+
authClient?: string;
|
|
198
|
+
error: unknown;
|
|
199
|
+
}) => void | Promise<void>) | undefined;
|
|
200
|
+
export type OnProfileSuccess = (({ userProfile, authProvider }: {
|
|
201
|
+
userProfile: Record<string, unknown>;
|
|
202
|
+
authProvider: string;
|
|
203
|
+
authClient?: string;
|
|
204
|
+
}) => void | Promise<void>) | undefined;
|
|
205
|
+
export type OnProfileError = (({ error, authProvider }: {
|
|
206
|
+
authProvider: string;
|
|
207
|
+
authClient?: string;
|
|
208
|
+
error: unknown;
|
|
209
|
+
}) => void | Promise<void>) | undefined;
|
|
210
|
+
export type OnRevocationSuccess = (({ tokenToRevoke, authProvider }: {
|
|
211
|
+
tokenToRevoke: string | number;
|
|
212
|
+
authProvider: string;
|
|
213
|
+
authClient?: string;
|
|
214
|
+
}) => void | Promise<void>) | undefined;
|
|
215
|
+
export type OnRevocationError = (({ error, authProvider }: {
|
|
216
|
+
authProvider: string;
|
|
217
|
+
authClient?: string;
|
|
218
|
+
error: unknown;
|
|
219
|
+
}) => void | Promise<void>) | undefined;
|
|
220
|
+
export type OnStatus<UserType> = (({ impersonator, user }: {
|
|
221
|
+
impersonator?: Impersonator;
|
|
222
|
+
user: UserType | null;
|
|
223
|
+
}) => void | Promise<void>) | undefined;
|
|
224
|
+
export type OnSignOut<UserType> = (({ authProvider, userSessionId, session }: {
|
|
225
|
+
/** Set only when the session was minted by the OAuth2 `/authorize` flow —
|
|
226
|
+
* credentials, MFA, passwordless, SSO, WebAuthn, and impersonation-minted
|
|
227
|
+
* sessions sign out without one. Use it to revoke the upstream provider
|
|
228
|
+
* token when present; ignore when undefined. */
|
|
229
|
+
authProvider: string | undefined;
|
|
230
|
+
userSessionId: UserSessionId;
|
|
231
|
+
session: SessionRecord<UserType>;
|
|
232
|
+
}) => void | Promise<void>) | undefined;
|
|
233
|
+
export type OnSessionCleanup<UserType> = (({ removedSessionCount, removedSessions, removedUnregisteredSessionCount, removedUnregisteredSessions }: {
|
|
234
|
+
/** Total removed, including SQL fast-path rows whose values were never loaded. */
|
|
235
|
+
removedSessionCount: number;
|
|
236
|
+
removedSessions: Map<UserSessionId, SessionData<UserType>>;
|
|
237
|
+
/** Total unregistered sessions removed, including SQL fast-path rows. */
|
|
238
|
+
removedUnregisteredSessionCount: number;
|
|
239
|
+
removedUnregisteredSessions: Map<UserSessionId, UnregisteredSessionData>;
|
|
240
|
+
}) => void | Promise<void>) | undefined;
|
|
241
|
+
export type RouteString = `/${string}`;
|
|
242
|
+
export type AuthorizeRoute = `${string}/:provider${'' | `/${string}`}`;
|
|
243
|
+
export type AuthConfig<UserType> = {
|
|
244
|
+
/** Canonical user resolver: load the application user for a session subject
|
|
245
|
+
* (`sub`). REQUIRED, and the single source of truth for `UserType` — every
|
|
246
|
+
* other user-typed callback (`credentials.getUserByEmail`,
|
|
247
|
+
* `sso.getSsoUser`, `onCallbackSuccess`, …) is checked against the shape
|
|
248
|
+
* `getUser` returns (via `NoInfer`), so they cannot disagree. This is also
|
|
249
|
+
* the resolver the package uses to hydrate the typed `user` in
|
|
250
|
+
* `protectRoute`'s context. */
|
|
251
|
+
getUser: (sub: string) => UserType | null | Promise<UserType | null>;
|
|
252
|
+
providersConfiguration: OAuth2ConfigurationOptions;
|
|
253
|
+
/** Bring-your-own OAuth providers (citra createCustomOAuth2Client) — keys
|
|
254
|
+
* must not collide with built-in provider names. */
|
|
255
|
+
customProviders?: CustomProvidersConfiguration;
|
|
256
|
+
/** Override the `Secure` attribute on every cookie the package sets (session, OAuth state,
|
|
257
|
+
* code_verifier, SSO nonce, ring, etc.). When omitted, defaults to
|
|
258
|
+
* `process.env.NODE_ENV === 'production'` — matching the convention used by
|
|
259
|
+
* express-session / iron-session / lucia / better-auth, and the only way non-browser
|
|
260
|
+
* HTTP clients (curl, SSR fetch, test runners) can round-trip cookies on a plain-HTTP
|
|
261
|
+
* dev server. If you run prod without setting `NODE_ENV=production`, set
|
|
262
|
+
* `cookieSecure: true` explicitly. */
|
|
263
|
+
cookieSecure?: boolean;
|
|
264
|
+
/** OpenTelemetry instrumentation. Pass your configured `TracerProvider` (from
|
|
265
|
+
* `@opentelemetry/sdk-trace-node` / `-web` / `-bun`) and the package emits spans for
|
|
266
|
+
* every key flow: `auth.credentials.login`, `auth.oauth.callback`, `auth.mfa.challenge`,
|
|
267
|
+
* `auth.webhook.deliver`, etc. Pipe the spans into Datadog / Honeycomb / Grafana Tempo /
|
|
268
|
+
* Sentry / Jaeger / whichever APM you already pay for. `@opentelemetry/api` is an
|
|
269
|
+
* OPTIONAL peer dep — consumers that leave `tracing` unset never load it. */
|
|
270
|
+
tracing?: TracingConfig;
|
|
271
|
+
authorizeRoute?: AuthorizeRoute;
|
|
272
|
+
profileRoute?: RouteString;
|
|
273
|
+
callbackRoute?: RouteString;
|
|
274
|
+
refreshRoute?: RouteString;
|
|
275
|
+
revokeRoute?: RouteString;
|
|
276
|
+
signoutRoute?: RouteString;
|
|
277
|
+
statusRoute?: RouteString;
|
|
278
|
+
cleanupIntervalMs?: number;
|
|
279
|
+
maxSessions?: number;
|
|
280
|
+
sessionDurationMs?: number;
|
|
281
|
+
authSessionStore?: AuthSessionStore<NoInfer<UserType>>;
|
|
282
|
+
/** Append-only audit logging. When present, `auth()` emits structured events
|
|
283
|
+
* (register, login, mfa_*, password_reset, logout, …) from every flow into the
|
|
284
|
+
* `auditStore` and/or `onAuditEvent` hook. SOC 2 prerequisite. */
|
|
285
|
+
audit?: AuditConfig<NoInfer<UserType>>;
|
|
286
|
+
/** Local email/password (credentials) block. Additive and optional — when present,
|
|
287
|
+
* mounts register / verify-email / login / reset-password routes that produce the
|
|
288
|
+
* same `SessionData<UserType>` as OAuth, transparent to `protectRoute`. */
|
|
289
|
+
credentials?: CredentialsConfig<NoInfer<UserType>>;
|
|
290
|
+
/** Passwordless login: magic links + email OTP. When present, mounts the magic-link flow
|
|
291
|
+
* (if `onSendMagicLink` is set) and/or the OTP flow (if `onSendOtp` is set) under
|
|
292
|
+
* `{passwordlessRoute}`; each verify route resolves the email to a user and mints the same
|
|
293
|
+
* `SessionData<UserType>` as every other flow. */
|
|
294
|
+
passwordless?: PasswordlessConfig<NoInfer<UserType>>;
|
|
295
|
+
/** Multi-factor auth (TOTP + backup codes). When present alongside `credentials`,
|
|
296
|
+
* `auth()` auto-wires the login MFA gate, mounts the enroll/challenge routes, and
|
|
297
|
+
* promotes the parked session once a factor is verified. */
|
|
298
|
+
mfa?: MfaConfig<NoInfer<UserType>>;
|
|
299
|
+
/** Provider-managed phone verification (Twilio Verify, etc.). When absent,
|
|
300
|
+
* MFA can use the built-in locally generated code flow through onSendSmsCode. */
|
|
301
|
+
verificationProvider?: VerificationProvider;
|
|
302
|
+
/** Per-identity attempt throttling + account lockout on the credential login route
|
|
303
|
+
* (progressive: locks after `maxAttempts` failures within `windowMs`). */
|
|
304
|
+
lockout?: LockoutConfig;
|
|
305
|
+
/** Self-service session management: `GET /auth/sessions` (list the caller's active
|
|
306
|
+
* sessions) and `DELETE /auth/sessions/:id` (remote revoke). Requires an
|
|
307
|
+
* `authSessionStore` that can enumerate sessions. */
|
|
308
|
+
sessions?: SessionsConfig<NoInfer<UserType>>;
|
|
309
|
+
/** Per-organization enterprise SSO (the WorkOS-style model). When present, mounts
|
|
310
|
+
* `GET {ssoRoute}/oidc/:organizationId/authorize` + `.../callback`, resolves the org's
|
|
311
|
+
* OIDC connection from `ssoConnectionStore`, verifies the id_token in-house against the
|
|
312
|
+
* issuer's JWKS, and mints the same `SessionData<UserType>` as every other flow. */
|
|
313
|
+
sso?: SSOConfig<NoInfer<UserType>>;
|
|
314
|
+
/** SCIM 2.0 auto-provisioning for enterprise directory sync (Okta / Azure AD). When present,
|
|
315
|
+
* mounts `{scimRoute}/Users` (+ `/ServiceProviderConfig`) with per-org bearer-token auth via
|
|
316
|
+
* `scimTokenStore`, and maps SCIM resources to the consumer's user store through hooks. */
|
|
317
|
+
scim?: ScimConfig;
|
|
318
|
+
/** Machine-to-machine authentication: static API keys (`sk_…`) + the OAuth2
|
|
319
|
+
* client_credentials grant. When `apiClientStore` + `accessTokenStore` are set,
|
|
320
|
+
* mounts `{tokenRoute}` (defaults `/oauth2/token`) so registered clients can
|
|
321
|
+
* exchange `client_id`/`client_secret` for short-lived `at_…` access tokens.
|
|
322
|
+
* Pair with the exported `createApiKey` / `resolveApiPrincipal` / `hasScopes`
|
|
323
|
+
* helpers to issue and guard with static keys. */
|
|
324
|
+
apikeys?: ApiKeysConfig;
|
|
325
|
+
/** Standards-first delegated agent authorization. Mounts RFC 9728 protected-resource
|
|
326
|
+
* metadata and contributes `protectAgent`, while protocol adapters normalize verified
|
|
327
|
+
* credentials into durable agent registrations + user delegations. */
|
|
328
|
+
agentAuth?: AgentAuthConfig;
|
|
329
|
+
/** OAuth2 / OIDC provider — makes your app an identity provider ("Sign in with
|
|
330
|
+
* <yourapp>"). Mounts `{oidcRoute}/authorize` + `/token` + `/jwks` and
|
|
331
|
+
* `/.well-known/openid-configuration`: authorization_code + mandatory PKCE, ES256
|
|
332
|
+
* JWTs signed by a key you own (self-hosted JWKS), refresh-token rotation, and
|
|
333
|
+
* optional DPoP (RFC 9449) sender-constrained tokens. The authorize endpoint reuses
|
|
334
|
+
* the package session, so the IdP login gets passkeys / MFA / SSO for free. */
|
|
335
|
+
oidc?: OidcProviderConfig<NoInfer<UserType>>;
|
|
336
|
+
/** First-class multi-tenancy (the WorkOS model). When present, mounts organization +
|
|
337
|
+
* membership + invitation routes under `{organizationsRoute}`: list the caller's orgs, create
|
|
338
|
+
* one (caller becomes owner), invite/accept/revoke by email, and list/remove members. Ties the
|
|
339
|
+
* bare `organizationId` used by SSO/SCIM/RBAC into a real tenant model with org-scoped roles. */
|
|
340
|
+
organizations?: OrganizationsConfig<NoInfer<UserType>>;
|
|
341
|
+
/** Admin portal — the WorkOS self-serve "setup link" model, headless. When present, mounts
|
|
342
|
+
* `{portalRoute}` endpoints a customer's IT admin (holding a scoped setup token from
|
|
343
|
+
* `createSetupSession`) calls to read the service-provider URLs and configure their own SSO
|
|
344
|
+
* connection / SCIM token. JSON contract, so the portal UI can be built in any framework. */
|
|
345
|
+
portal?: PortalConfig;
|
|
346
|
+
/** Org-scoped roles & permissions (builds on `organizations`). When present, mounts routes to
|
|
347
|
+
* list an org's role definitions and set a member's roles. Pair with
|
|
348
|
+
* `createMembershipPermissionResolver` to make `authorization.hasPermission` turnkey. */
|
|
349
|
+
roles?: RolesConfig<NoInfer<UserType>>;
|
|
350
|
+
/** Role-based / attribute-based access control (E4). When present, `auth()` exposes a
|
|
351
|
+
* `protectPermission(check, handler)` derive (alongside `protectRoute`) that delegates the
|
|
352
|
+
* decision to your `hasPermission` hook — the package stays schema-agnostic about roles. */
|
|
353
|
+
authorization?: AuthorizationConfig<NoInfer<UserType>>;
|
|
354
|
+
/** GDPR/CCPA self-service compliance (E5). When present, mounts `GET {complianceRoute}/export`
|
|
355
|
+
* (right to access) and `DELETE {complianceRoute}` (right to erasure — runs your delete hook,
|
|
356
|
+
* revokes the user's sessions, clears the cookie). Pair with `audit.redact` for PII redaction. */
|
|
357
|
+
compliance?: ComplianceConfig<NoInfer<UserType>>;
|
|
358
|
+
/** Passwordless / passkey auth (WebAuthn). When present, mounts the registration ceremony
|
|
359
|
+
* (`{webauthnRoute}/register/options` + `/verify`, adds a passkey to the authenticated caller)
|
|
360
|
+
* and the authentication ceremony (`.../authenticate/options` + `/verify`, passwordless sign-in
|
|
361
|
+
* → mints the same `SessionData<UserType>`). A `webauthnAdapter` wraps a vetted library (e.g.
|
|
362
|
+
* `@simplewebauthn/server`); the package never bundles the WebAuthn crypto. */
|
|
363
|
+
webauthn?: WebAuthnConfig<NoInfer<UserType>>;
|
|
364
|
+
/** Signed outbound webhooks. When present, every emitted auth event (the audit taxonomy) is
|
|
365
|
+
* HMAC-signed (Standard Webhooks scheme) and POSTed to each endpoint. Delivery is best-effort
|
|
366
|
+
* and isolated per endpoint; configuring this alone (without `audit`) is enough to turn on
|
|
367
|
+
* event emission. PII redaction (`audit.redact`) applies before delivery. */
|
|
368
|
+
webhooks?: WebhooksConfig;
|
|
369
|
+
/** Enable the built-in HTMX fragment routes (login, identities, connectors,
|
|
370
|
+
* account, signout, delete-account). Supply provider display data + the
|
|
371
|
+
* identity/connector data actions; the package owns the route wiring and
|
|
372
|
+
* renderers. See @absolutejs/auth/ui to override individual fragments.
|
|
373
|
+
*
|
|
374
|
+
* Only available when `UserType` has the fields the fragments render
|
|
375
|
+
* (`sub` + optional email/name); users that don't enable HTMX are never
|
|
376
|
+
* constrained. */
|
|
377
|
+
htmx?: NoInfer<UserType> extends AuthHtmxUser ? AuthHtmxConfig : never;
|
|
378
|
+
unregisteredSessionDurationMs?: number;
|
|
379
|
+
resolveAuthIntent?: ResolveAuthIntent<NoInfer<UserType>>;
|
|
380
|
+
onAuthorizeSuccess?: OnAuthorizeSuccess;
|
|
381
|
+
onAuthorizeError?: OnAuthorizeError;
|
|
382
|
+
onCallbackSuccess?: OnCallbackSuccess<NoInfer<UserType>>;
|
|
383
|
+
onLinkIdentity?: OnLinkIdentity<NoInfer<UserType>>;
|
|
384
|
+
onLinkIdentityConflict?: OnLinkIdentityConflict<NoInfer<UserType>>;
|
|
385
|
+
onLinkConnector?: OnLinkConnector<NoInfer<UserType>>;
|
|
386
|
+
onCallbackError?: OnCallbackError;
|
|
387
|
+
onStatus?: OnStatus<NoInfer<UserType>>;
|
|
388
|
+
onRefreshSuccess?: OnRefreshSuccess;
|
|
389
|
+
onRefreshError?: OnRefreshError;
|
|
390
|
+
onSignOut?: OnSignOut<NoInfer<UserType>>;
|
|
391
|
+
onRevocationSuccess?: OnRevocationSuccess;
|
|
392
|
+
onRevocationError?: OnRevocationError;
|
|
393
|
+
onProfileSuccess?: OnProfileSuccess;
|
|
394
|
+
onProfileError?: OnProfileError;
|
|
395
|
+
onSessionCleanup?: OnSessionCleanup<NoInfer<UserType>>;
|
|
396
|
+
};
|
|
397
|
+
/** The serializable subset of `AuthConfig` — the route paths, session durations, and
|
|
398
|
+
* limits that can live in a data file (`auth.config.ts` via `defineAuthSettings`) and
|
|
399
|
+
* be edited from tooling, separate from the code wiring (stores, hooks, callbacks)
|
|
400
|
+
* that stays in the `auth()` call. Spread alongside the rest:
|
|
401
|
+
* `auth({ ...defineAuthSettings({...}), authSessionStore, providersConfiguration })`. */
|
|
402
|
+
export type AuthSettings = Pick<AuthConfig<unknown>, 'authorizeRoute' | 'callbackRoute' | 'cleanupIntervalMs' | 'maxSessions' | 'profileRoute' | 'refreshRoute' | 'revokeRoute' | 'sessionDurationMs' | 'signoutRoute' | 'statusRoute' | 'unregisteredSessionDurationMs'>;
|
|
403
|
+
export type ClientProviderEntry = {
|
|
404
|
+
providerConfiguration: ProviderConfig;
|
|
405
|
+
requiresPKCE: boolean;
|
|
406
|
+
clientName?: string;
|
|
407
|
+
providerInstance: OAuth2Client<ProviderOption>;
|
|
408
|
+
scope?: string[];
|
|
409
|
+
searchParams?: [string, string][];
|
|
410
|
+
};
|
|
411
|
+
export type ClientProviderGroup = {
|
|
412
|
+
entries: Record<string, ClientProviderEntry>;
|
|
413
|
+
isSingleClient: boolean;
|
|
414
|
+
};
|
|
415
|
+
export type ClientProviders = Record<string, ClientProviderGroup>;
|
|
416
|
+
export type InsantiateUserSessionProps<UserType> = {
|
|
417
|
+
authProvider: string;
|
|
418
|
+
/** Required for custom providers (names outside the citra registry). */
|
|
419
|
+
providerConfiguration?: ProviderConfig;
|
|
420
|
+
tokenResponse: OAuth2TokenResponse;
|
|
421
|
+
session: SessionRecord<UserType>;
|
|
422
|
+
unregisteredSession: UnregisteredSessionRecord;
|
|
423
|
+
providerInstance: OAuth2Client<ProviderOption>;
|
|
424
|
+
user_session_id: Cookie<UserSessionId | undefined>;
|
|
425
|
+
onNewUser: OnNewUser<NoInfer<UserType>>;
|
|
426
|
+
getUser: GetUser<NoInfer<UserType>>;
|
|
427
|
+
cookieSecure?: boolean;
|
|
428
|
+
resolvedAuthorization?: ResolvedOAuthAuthorization;
|
|
429
|
+
sessionDurationMs?: number;
|
|
430
|
+
unregisteredSessionDurationMs?: number;
|
|
431
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { OAuth2Client, OAuth2TokenResponse, ProviderConfig, ProviderOption } from 'citra';
|
|
2
|
+
import { Cookie } from 'elysia';
|
|
3
|
+
import { AuthHtmxConfig } from './htmx/types';
|
|
4
|
+
import { AuthConfig, AuthSettings, InsantiateUserSessionProps, OAuth2ConfigurationOptions, ResolvedOAuthAuthorization, SessionRecord, UnregisteredSessionRecord, UserSessionId } from './types';
|
|
5
|
+
export declare const defineAuthConfig: <UserType>(configuration: AuthConfig<UserType>) => AuthConfig<UserType>;
|
|
6
|
+
export declare const defineAuthHtmxConfig: (htmxConfig: AuthHtmxConfig) => AuthHtmxConfig;
|
|
7
|
+
export declare const defineAuthSettings: (settings: AuthSettings) => AuthSettings;
|
|
8
|
+
export declare const defineProvidersConfiguration: (providersConfiguration: OAuth2ConfigurationOptions) => OAuth2ConfigurationOptions;
|
|
9
|
+
export declare const getStatus: <UserType>(session: SessionRecord<UserType>, user_session_id: Cookie<UserSessionId | undefined>) => Promise<{
|
|
10
|
+
error: {
|
|
11
|
+
readonly code: "Bad Request";
|
|
12
|
+
readonly message: "Cookies are missing";
|
|
13
|
+
};
|
|
14
|
+
user: null;
|
|
15
|
+
} | {
|
|
16
|
+
error: null;
|
|
17
|
+
user: NonNullable<UserType> | null;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const instantiateUserSession: <UserType>({ authProvider, providerConfiguration, cookieSecure, session, user_session_id, unregisteredSession, tokenResponse, providerInstance, getUser, onNewUser, resolvedAuthorization, sessionDurationMs, unregisteredSessionDurationMs }: InsantiateUserSessionProps<UserType>) => Promise<Response | import("./types").StatusReturn | undefined>;
|
|
20
|
+
export declare const resolveCookieSecure: (override?: boolean) => boolean;
|
|
21
|
+
export declare const resolveOAuthAuthorization: ({ authProvider, providerConfiguration, providerInstance, tokenResponse, now }: {
|
|
22
|
+
authProvider: string;
|
|
23
|
+
providerConfiguration?: ProviderConfig;
|
|
24
|
+
providerInstance: OAuth2Client<ProviderOption>;
|
|
25
|
+
tokenResponse: OAuth2TokenResponse;
|
|
26
|
+
now?: number;
|
|
27
|
+
}) => Promise<ResolvedOAuthAuthorization>;
|
|
28
|
+
export declare const resolveOAuthTokenExpiresAt: (tokenResponse: OAuth2TokenResponse, now?: number) => number | undefined;
|
|
29
|
+
type ValidateSessionProps<SessionType extends Record<string, unknown> & {
|
|
30
|
+
expiresAt: number;
|
|
31
|
+
}> = {
|
|
32
|
+
user_session_id: Cookie<UserSessionId | undefined>;
|
|
33
|
+
session: Record<UserSessionId, SessionType>;
|
|
34
|
+
};
|
|
35
|
+
export declare const validateSession: <SessionType extends Record<string, unknown> & {
|
|
36
|
+
expiresAt: number;
|
|
37
|
+
}>({ user_session_id, session }: ValidateSessionProps<SessionType>) => SessionType | undefined;
|
|
38
|
+
type GetUserSessionIdProps<UserType> = {
|
|
39
|
+
cookieSecure?: boolean;
|
|
40
|
+
user_session_id: Cookie<UserSessionId | undefined>;
|
|
41
|
+
session?: SessionRecord<UserType>;
|
|
42
|
+
unregisteredSession?: UnregisteredSessionRecord;
|
|
43
|
+
};
|
|
44
|
+
export declare const getUserSessionId: <UserType>({ cookieSecure, user_session_id, session, unregisteredSession }: GetUserSessionIdProps<UserType>) => `${string}-${string}-${string}-${string}-${string}`;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type SecretCipher } from '../compliance/cipher';
|
|
2
|
+
import type { VaultStore } from './types';
|
|
3
|
+
export type Vault = {
|
|
4
|
+
delete: (ownerId: string, name: string) => Promise<void>;
|
|
5
|
+
get: (ownerId: string, name: string) => Promise<string | undefined>;
|
|
6
|
+
list: (ownerId: string) => Promise<string[]>;
|
|
7
|
+
put: (ownerId: string, name: string, value: string) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export declare const createVault: ({ cipher, store }: {
|
|
10
|
+
cipher: SecretCipher;
|
|
11
|
+
store: VaultStore;
|
|
12
|
+
}) => Vault;
|
|
13
|
+
export type VaultKeyRotationResult = {
|
|
14
|
+
rotated: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const rotateVaultKey: ({ newKey, oldKey, store }: {
|
|
17
|
+
newKey: string;
|
|
18
|
+
oldKey: string;
|
|
19
|
+
store: VaultStore;
|
|
20
|
+
}) => Promise<VaultKeyRotationResult>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createSecretCipher, createVersionedSecretCipher, type SecretCipher } from '../compliance/cipher';
|
|
2
|
+
export { createVault, rotateVaultKey, type Vault } from './config';
|
|
3
|
+
export { createInMemoryVaultStore } from './inMemoryVaultStore';
|
|
4
|
+
export { createNeonVaultStore, createPostgresVaultStore, vaultEntriesTable } from './postgresVaultStore';
|
|
5
|
+
export type { VaultEntry, VaultStore } from './types';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type AnyPgDatabase } from '../stores/postgres';
|
|
2
|
+
import type { VaultStore } from './types';
|
|
3
|
+
export declare const vaultEntriesTable: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
4
|
+
name: "auth_vault_entries";
|
|
5
|
+
schema: undefined;
|
|
6
|
+
columns: {
|
|
7
|
+
created_at_ms: import("drizzle-orm/pg-core").PgBuildColumn<"auth_vault_entries", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgBigInt53Builder>, {
|
|
8
|
+
name: string;
|
|
9
|
+
tableName: "auth_vault_entries";
|
|
10
|
+
dataType: "number int53";
|
|
11
|
+
data: number;
|
|
12
|
+
driverParam: string | number;
|
|
13
|
+
notNull: true;
|
|
14
|
+
hasDefault: false;
|
|
15
|
+
isPrimaryKey: false;
|
|
16
|
+
isAutoincrement: false;
|
|
17
|
+
hasRuntimeDefault: false;
|
|
18
|
+
enumValues: undefined;
|
|
19
|
+
identity: undefined;
|
|
20
|
+
generated: undefined;
|
|
21
|
+
}>;
|
|
22
|
+
encrypted_value: import("drizzle-orm/pg-core").PgBuildColumn<"auth_vault_entries", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
|
|
23
|
+
name: string;
|
|
24
|
+
tableName: "auth_vault_entries";
|
|
25
|
+
dataType: "string";
|
|
26
|
+
data: string;
|
|
27
|
+
driverParam: string;
|
|
28
|
+
notNull: true;
|
|
29
|
+
hasDefault: false;
|
|
30
|
+
isPrimaryKey: false;
|
|
31
|
+
isAutoincrement: false;
|
|
32
|
+
hasRuntimeDefault: false;
|
|
33
|
+
enumValues: undefined;
|
|
34
|
+
identity: undefined;
|
|
35
|
+
generated: undefined;
|
|
36
|
+
}>;
|
|
37
|
+
name: import("drizzle-orm/pg-core").PgBuildColumn<"auth_vault_entries", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>>, {
|
|
38
|
+
name: string;
|
|
39
|
+
tableName: "auth_vault_entries";
|
|
40
|
+
dataType: "string";
|
|
41
|
+
data: string;
|
|
42
|
+
driverParam: string;
|
|
43
|
+
notNull: true;
|
|
44
|
+
hasDefault: false;
|
|
45
|
+
isPrimaryKey: false;
|
|
46
|
+
isAutoincrement: false;
|
|
47
|
+
hasRuntimeDefault: false;
|
|
48
|
+
enumValues: undefined;
|
|
49
|
+
identity: undefined;
|
|
50
|
+
generated: undefined;
|
|
51
|
+
}>;
|
|
52
|
+
owner_id: import("drizzle-orm/pg-core").PgBuildColumn<"auth_vault_entries", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>>, {
|
|
53
|
+
name: string;
|
|
54
|
+
tableName: "auth_vault_entries";
|
|
55
|
+
dataType: "string";
|
|
56
|
+
data: string;
|
|
57
|
+
driverParam: string;
|
|
58
|
+
notNull: true;
|
|
59
|
+
hasDefault: false;
|
|
60
|
+
isPrimaryKey: false;
|
|
61
|
+
isAutoincrement: false;
|
|
62
|
+
hasRuntimeDefault: false;
|
|
63
|
+
enumValues: undefined;
|
|
64
|
+
identity: undefined;
|
|
65
|
+
generated: undefined;
|
|
66
|
+
}>;
|
|
67
|
+
updated_at_ms: import("drizzle-orm/pg-core").PgBuildColumn<"auth_vault_entries", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgBigInt53Builder>, {
|
|
68
|
+
name: string;
|
|
69
|
+
tableName: "auth_vault_entries";
|
|
70
|
+
dataType: "number int53";
|
|
71
|
+
data: number;
|
|
72
|
+
driverParam: string | number;
|
|
73
|
+
notNull: true;
|
|
74
|
+
hasDefault: false;
|
|
75
|
+
isPrimaryKey: false;
|
|
76
|
+
isAutoincrement: false;
|
|
77
|
+
hasRuntimeDefault: false;
|
|
78
|
+
enumValues: undefined;
|
|
79
|
+
identity: undefined;
|
|
80
|
+
generated: undefined;
|
|
81
|
+
}>;
|
|
82
|
+
};
|
|
83
|
+
dialect: "pg";
|
|
84
|
+
}>;
|
|
85
|
+
export declare const createNeonVaultStore: (databaseUrl: string) => VaultStore;
|
|
86
|
+
export declare const createPostgresVaultStore: <DB extends AnyPgDatabase>(db: DB) => VaultStore;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type VaultEntry = {
|
|
2
|
+
createdAt: number;
|
|
3
|
+
encryptedValue: string;
|
|
4
|
+
name: string;
|
|
5
|
+
ownerId: string;
|
|
6
|
+
updatedAt: number;
|
|
7
|
+
};
|
|
8
|
+
export type VaultStore = {
|
|
9
|
+
deleteEntry: (ownerId: string, name: string) => Promise<void>;
|
|
10
|
+
getEntry: (ownerId: string, name: string) => Promise<VaultEntry | undefined>;
|
|
11
|
+
listAllEntries: () => Promise<VaultEntry[]>;
|
|
12
|
+
listEntries: (ownerId: string) => Promise<VaultEntry[]>;
|
|
13
|
+
saveEntry: (entry: VaultEntry) => Promise<void>;
|
|
14
|
+
};
|