authhero 9.38.0 → 9.40.0
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 +13 -3
- package/dist/assets/u/widget/authhero-widget.esm.js +1 -1
- package/dist/assets/u/widget/index.esm.js +1 -1
- package/dist/assets/u/widget/p-603aa8fa.entry.js +1 -0
- package/dist/assets/u/widget/p-d0eb5acc.entry.js +1 -0
- package/dist/authhero.cjs +175 -170
- package/dist/authhero.d.ts +381 -237
- package/dist/authhero.mjs +21363 -19930
- package/dist/mfa-BlaRHQgI.js +4 -0
- package/dist/mfa-Ddp9JT1l.mjs +406 -0
- package/dist/{mfa-attempts-BK-gWrgJ.mjs → mfa-attempts-YsmteBp0.mjs} +5188 -4601
- package/dist/mfa-attempts-bPJnyu2c.js +385 -0
- package/dist/{passkey-enrollment-CmKahPq7.js → passkey-enrollment-CLg7RteL.js} +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/authentication-flows/common.d.ts +4 -1
- package/dist/types/authentication-flows/mfa.d.ts +3 -1
- package/dist/types/authentication-flows/passwordless.d.ts +2 -2
- package/dist/types/emails/index.d.ts +33 -1
- package/dist/types/generated/locale-types.d.ts +39 -0
- package/dist/types/helpers/client.d.ts +1 -0
- package/dist/types/helpers/code-recipient.d.ts +37 -0
- package/dist/types/helpers/reserved-claims.d.ts +2 -2
- package/dist/types/helpers/response-type-grants.d.ts +8 -0
- package/dist/types/hooks/custom-notification-provider.d.ts +174 -0
- package/dist/types/hooks/helpers/action-users.d.ts +56 -0
- package/dist/types/hooks/helpers/post-login-account-linking.d.ts +18 -4
- package/dist/types/hooks/lifecycle-codehooks.d.ts +1 -1
- package/dist/types/hooks/pre-screen.d.ts +114 -0
- package/dist/types/index.d.ts +295 -217
- package/dist/types/routes/auth-api/device.d.ts +8 -8
- package/dist/types/routes/auth-api/index.d.ts +18 -18
- package/dist/types/routes/auth-api/passwordless.d.ts +12 -12
- package/dist/types/routes/auth-api/token.d.ts +10 -10
- package/dist/types/routes/management-api/action-executions.d.ts +2 -2
- package/dist/types/routes/management-api/action-triggers.d.ts +25 -25
- package/dist/types/routes/management-api/actions.d.ts +9 -9
- package/dist/types/routes/management-api/authentication-methods.d.ts +1 -1
- package/dist/types/routes/management-api/branding.d.ts +1 -1
- package/dist/types/routes/management-api/clients.d.ts +2 -0
- package/dist/types/routes/management-api/connections.d.ts +7 -1
- package/dist/types/routes/management-api/email-templates.d.ts +20 -20
- package/dist/types/routes/management-api/emails.d.ts +2 -2
- package/dist/types/routes/management-api/failed-events.d.ts +2 -2
- package/dist/types/routes/management-api/forms.d.ts +168 -144
- package/dist/types/routes/management-api/guardian.d.ts +5 -5
- package/dist/types/routes/management-api/helpers.d.ts +1 -1
- package/dist/types/routes/management-api/hooks.d.ts +25 -25
- package/dist/types/routes/management-api/index.d.ts +222 -190
- package/dist/types/routes/management-api/keys.d.ts +8 -8
- package/dist/types/routes/management-api/log-streams.d.ts +12 -12
- package/dist/types/routes/management-api/logs.d.ts +4 -4
- package/dist/types/routes/management-api/migration-sources.d.ts +6 -6
- package/dist/types/routes/management-api/organizations.d.ts +8 -8
- package/dist/types/routes/management-api/prompts.d.ts +8 -8
- package/dist/types/routes/management-api/roles.d.ts +1 -1
- package/dist/types/routes/management-api/self-service-profiles.d.ts +8 -8
- package/dist/types/routes/management-api/tenant-export-import.d.ts +5 -5
- package/dist/types/routes/management-api/tenants.d.ts +29 -29
- package/dist/types/routes/management-api/users.d.ts +29 -29
- package/dist/types/routes/universal-login/continue.d.ts +35 -0
- package/dist/types/routes/universal-login/flow-api.d.ts +12 -12
- package/dist/types/routes/universal-login/form-node.d.ts +4 -4
- package/dist/types/routes/universal-login/index.d.ts +4 -4
- package/dist/types/routes/universal-login/pre-screen-gates.d.ts +31 -0
- package/dist/types/routes/universal-login/screens/account-change-email.d.ts +52 -0
- package/dist/types/routes/universal-login/screens/account-helpers.d.ts +19 -24
- package/dist/types/routes/universal-login/screens/account.d.ts +6 -0
- package/dist/types/routes/universal-login/screens/connect-authz.d.ts +13 -1
- package/dist/types/routes/universal-login/screens/index.d.ts +4 -2
- package/dist/types/routes/universal-login/screens/invalid-session.d.ts +10 -0
- package/dist/types/routes/universal-login/screens/login-otp.d.ts +2 -2
- package/dist/types/routes/universal-login/screens/signup.d.ts +0 -3
- package/dist/types/routes/universal-login/screens/social-connections.d.ts +31 -0
- package/dist/types/routes/universal-login/screens/types.d.ts +3 -0
- package/dist/types/routes/universal-login/u2-form-node.d.ts +2 -2
- package/dist/types/routes/universal-login/u2-index.d.ts +50 -5
- package/dist/types/routes/universal-login/u2-routes.d.ts +5 -5
- package/dist/types/routes/universal-login/u2-widget-page.d.ts +1 -4
- package/dist/types/routes/universal-login/widget-assets.d.ts +20 -0
- package/dist/types/state-machines/login-session.d.ts +12 -0
- package/dist/types/types/AuthHeroConfig.d.ts +9 -1
- package/dist/types/types/Hooks.d.ts +62 -17
- package/dist/types/utils/embedded-browser.d.ts +4 -0
- package/package.json +6 -6
- package/dist/assets/u/widget/p-32247347.entry.js +0 -1
- package/dist/assets/u/widget/p-3f908508.entry.js +0 -1
- package/dist/mfa-DBhvi2B5.js +0 -1
- package/dist/mfa-DnCary4g.mjs +0 -128
- package/dist/mfa-attempts-C5kobAHS.js +0 -275
|
@@ -246,7 +246,10 @@ export declare function completeLoginSessionContinuation(ctx: Context<{
|
|
|
246
246
|
Variables: Variables;
|
|
247
247
|
}>, tenantId: string, loginSession: LoginSession): Promise<string | undefined>;
|
|
248
248
|
/**
|
|
249
|
-
* Check if a login session allows access to a given scope during continuation
|
|
249
|
+
* Check if a login session allows access to a given scope during continuation.
|
|
250
|
+
* The scope stands in for a signed-in session, so it ends when the login
|
|
251
|
+
* session expires: adapters return expired rows and nothing else on the
|
|
252
|
+
* continuation paths checks `expires_at`.
|
|
250
253
|
*/
|
|
251
254
|
export declare function hasValidContinuationScope(loginSession: LoginSession, requiredScope: string): boolean;
|
|
252
255
|
export interface CreateAuthResponseParams {
|
|
@@ -39,7 +39,9 @@ export declare function checkMfaRequired(ctx: Context<{
|
|
|
39
39
|
export declare function sendMfaOtp(ctx: Context<{
|
|
40
40
|
Bindings: Bindings;
|
|
41
41
|
Variables: Variables;
|
|
42
|
-
}>, client: EnrichedClient, loginSession: LoginSession, phoneNumber: string, userId?: string
|
|
42
|
+
}>, client: EnrichedClient, loginSession: LoginSession, phoneNumber: string, userId?: string,
|
|
43
|
+
/** Auth0 `message_type` for the `custom-phone-provider` trigger. */
|
|
44
|
+
messageType?: "otp_verify" | "otp_enroll"): Promise<void>;
|
|
43
45
|
/**
|
|
44
46
|
* Verify an MFA OTP code against the stored code.
|
|
45
47
|
* Returns true if valid, false otherwise.
|
|
@@ -175,8 +175,8 @@ export declare function passwordlessGrantUser(ctx: Context<{
|
|
|
175
175
|
authenticated_at?: string | undefined;
|
|
176
176
|
tenant_id?: string | undefined;
|
|
177
177
|
};
|
|
178
|
-
connectionType: "username" | "
|
|
179
|
-
authConnection: "username" | "
|
|
178
|
+
connectionType: "username" | "email" | "sms";
|
|
179
|
+
authConnection: "username" | "email" | "sms";
|
|
180
180
|
session_id: string | undefined;
|
|
181
181
|
authParams: {
|
|
182
182
|
audience?: string | undefined;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
import { Bindings, RequestContext, Variables } from "../types";
|
|
3
|
-
import { AuthParams, EmailTemplateName, User } from "@authhero/adapter-interfaces";
|
|
3
|
+
import { AuthParams, CustomEmailProviderMessageType, CustomPhoneProviderMessageType, EmailTemplateName, User } from "@authhero/adapter-interfaces";
|
|
4
|
+
/**
|
|
5
|
+
* Email provider name Auth0 tooling sets to hand all email to the action bound
|
|
6
|
+
* to `custom-email-provider` (`{ "name": "custom", "credentials": {} }`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const CUSTOM_EMAIL_PROVIDER_NAME = "custom";
|
|
4
9
|
export type SendEmailParams = {
|
|
5
10
|
to: string;
|
|
6
11
|
subject: string;
|
|
@@ -9,14 +14,41 @@ export type SendEmailParams = {
|
|
|
9
14
|
template: string;
|
|
10
15
|
data: Record<string, string>;
|
|
11
16
|
from?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Auth0 `message_type` for the `custom-email-provider` trigger. Without it
|
|
19
|
+
* the message goes straight to the provider (unless the provider is named
|
|
20
|
+
* `custom`, in which case `template` is reported as the type).
|
|
21
|
+
*/
|
|
22
|
+
message_type?: CustomEmailProviderMessageType;
|
|
23
|
+
/** Values that must never be logged: the one-time code, tokenized links. */
|
|
24
|
+
secrets?: string[];
|
|
25
|
+
/** The recipient user, or a loader, exposed to the action as `event.user`. */
|
|
26
|
+
user?: User | (() => Promise<User | undefined>);
|
|
27
|
+
/** `event.notification.locale`. */
|
|
28
|
+
locale?: string;
|
|
12
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Send an email. When an action is bound to `custom-email-provider` for this
|
|
32
|
+
* message type the action delivers it; otherwise the tenant's provider does,
|
|
33
|
+
* as before.
|
|
34
|
+
*/
|
|
13
35
|
export declare function sendEmail(ctx: RequestContext, params: SendEmailParams, tenantIdOverride?: string): Promise<void>;
|
|
14
36
|
export type SendSmsParams = {
|
|
15
37
|
to: string;
|
|
16
38
|
from?: string;
|
|
17
39
|
text: string;
|
|
18
40
|
code: string;
|
|
41
|
+
/** Auth0 `message_type` for the `custom-phone-provider` trigger. */
|
|
42
|
+
message_type?: CustomPhoneProviderMessageType;
|
|
43
|
+
/** Extra values that must never be logged, e.g. a magic link. */
|
|
44
|
+
secrets?: string[];
|
|
45
|
+
locale?: string;
|
|
19
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Send a text message. When an action is bound to `custom-phone-provider` for
|
|
49
|
+
* this message type the action delivers it; otherwise the SMS connection's
|
|
50
|
+
* provider does, as before.
|
|
51
|
+
*/
|
|
20
52
|
export declare function sendSms(ctx: Context<{
|
|
21
53
|
Bindings: Bindings;
|
|
22
54
|
Variables: Variables;
|
|
@@ -59,6 +59,8 @@ export interface CommonAccountScreen {
|
|
|
59
59
|
deleteAccountLabel: () => string;
|
|
60
60
|
deleteAccountDetail: () => string;
|
|
61
61
|
logoutText: () => string;
|
|
62
|
+
changeEmailLabel: () => string;
|
|
63
|
+
continueText: () => string;
|
|
62
64
|
}
|
|
63
65
|
export interface CommonAccountProfileScreen {
|
|
64
66
|
title: () => string;
|
|
@@ -71,6 +73,7 @@ export interface CommonAccountProfileScreen {
|
|
|
71
73
|
buttonText: () => string;
|
|
72
74
|
backToAccountText: () => string;
|
|
73
75
|
updateFailed: () => string;
|
|
76
|
+
changeEmailText: () => string;
|
|
74
77
|
}
|
|
75
78
|
export interface CommonAccountDeleteScreen {
|
|
76
79
|
title: () => string;
|
|
@@ -186,6 +189,39 @@ export interface CommonAccountMfaTotpEnrollmentScreen {
|
|
|
186
189
|
verificationFailedText: () => string;
|
|
187
190
|
tooManyFailuresText: () => string;
|
|
188
191
|
}
|
|
192
|
+
export interface CommonInvalidSessionScreen {
|
|
193
|
+
title: () => string;
|
|
194
|
+
description: () => string;
|
|
195
|
+
backText: () => string;
|
|
196
|
+
}
|
|
197
|
+
export interface CommonAccountChangeEmailScreen {
|
|
198
|
+
title: () => string;
|
|
199
|
+
description: () => string;
|
|
200
|
+
currentEmailLabel: () => string;
|
|
201
|
+
emailLabel: () => string;
|
|
202
|
+
invalidEmail: () => string;
|
|
203
|
+
buttonText: () => string;
|
|
204
|
+
sendFailed: () => string;
|
|
205
|
+
backToAccountText: () => string;
|
|
206
|
+
}
|
|
207
|
+
export interface CommonAccountChangeEmailVerifyScreen {
|
|
208
|
+
title: () => string;
|
|
209
|
+
description: (vars: {
|
|
210
|
+
email: string;
|
|
211
|
+
}) => string;
|
|
212
|
+
codeLabel: () => string;
|
|
213
|
+
buttonText: () => string;
|
|
214
|
+
noCode: () => string;
|
|
215
|
+
invalidCode: () => string;
|
|
216
|
+
tooManyAttempts: () => string;
|
|
217
|
+
emailTaken: () => string;
|
|
218
|
+
successTitle: () => string;
|
|
219
|
+
successDescription: (vars: {
|
|
220
|
+
email: string;
|
|
221
|
+
}) => string;
|
|
222
|
+
continueText: () => string;
|
|
223
|
+
backText: () => string;
|
|
224
|
+
}
|
|
189
225
|
export interface ConsentScreen {
|
|
190
226
|
buttonText: () => string;
|
|
191
227
|
cancelButtonText: () => string;
|
|
@@ -1057,6 +1093,9 @@ export interface ScreenMap {
|
|
|
1057
1093
|
"common.account-passkeys": CommonAccountPasskeysScreen;
|
|
1058
1094
|
"common.account-mfa-phone-enrollment": CommonAccountMfaPhoneEnrollmentScreen;
|
|
1059
1095
|
"common.account-mfa-totp-enrollment": CommonAccountMfaTotpEnrollmentScreen;
|
|
1096
|
+
"common.invalid-session": CommonInvalidSessionScreen;
|
|
1097
|
+
"common.account-change-email": CommonAccountChangeEmailScreen;
|
|
1098
|
+
"common.account-change-email-verify": CommonAccountChangeEmailVerifyScreen;
|
|
1060
1099
|
"consent.consent": ConsentScreen;
|
|
1061
1100
|
"consent.connect-consent": ConsentConnectConsentScreen;
|
|
1062
1101
|
"consent.connect-tenant-select": ConsentConnectTenantSelectScreen;
|
|
@@ -541,6 +541,7 @@ export declare const enrichedClientSchema: z.ZodObject<{
|
|
|
541
541
|
max: z.ZodOptional<z.ZodNumber>;
|
|
542
542
|
}, z.core.$strip>>;
|
|
543
543
|
}, z.core.$strip>>;
|
|
544
|
+
allow_action_users: z.ZodOptional<z.ZodBoolean>;
|
|
544
545
|
set_user_root_attributes: z.ZodOptional<z.ZodEnum<{
|
|
545
546
|
on_each_login: "on_each_login";
|
|
546
547
|
on_first_login: "on_first_login";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Context } from "hono";
|
|
2
|
+
import type { Code, CodesAdapter } from "@authhero/adapter-interfaces";
|
|
3
|
+
import type { CountryCode } from "libphonenumber-js";
|
|
4
|
+
/**
|
|
5
|
+
* Login and pre-signup codes are delivered to one address, and only that
|
|
6
|
+
* address may redeem them. The address is stored on the code when it is
|
|
7
|
+
* created (`state.recipient`), normalized like the identifier it is later
|
|
8
|
+
* compared with, because the login session's username can change after the
|
|
9
|
+
* code was sent.
|
|
10
|
+
*
|
|
11
|
+
* Codes without a stored recipient (minted before the recipient was stored)
|
|
12
|
+
* are not accepted: login codes expire within 30 minutes and are simply
|
|
13
|
+
* requested again, and a pre-signup code without one only means the signup
|
|
14
|
+
* continues unverified and a verification email is sent instead.
|
|
15
|
+
*/
|
|
16
|
+
/** `state.purpose` of a pre-signup `email_verification` code. */
|
|
17
|
+
export declare const PRE_SIGNUP_CODE_PURPOSE = "pre_signup";
|
|
18
|
+
export declare function normalizeCodeRecipient(identifier: string, countryCode?: CountryCode): string;
|
|
19
|
+
export declare function codeRecipientState(recipient: string, countryCode?: CountryCode, extra?: Record<string, unknown>): string;
|
|
20
|
+
export declare function parseCodeState(code: Pick<Code, "state">): Record<string, unknown>;
|
|
21
|
+
/** The address the code was sent to, if it was stored when it was created. */
|
|
22
|
+
export declare function getCodeRecipient(code: Pick<Code, "state">): string | undefined;
|
|
23
|
+
/** Whether `identifier` is the address the code was sent to. */
|
|
24
|
+
export declare function isCodeRecipient(code: Pick<Code, "state">, identifier: string | undefined, countryCode?: CountryCode): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Retire a login session's unused login codes that were sent to another
|
|
27
|
+
* address than `recipient`, for when the session's username changes. Best
|
|
28
|
+
* effort: redemption checks the recipient regardless, so a failure here is
|
|
29
|
+
* logged and ignored.
|
|
30
|
+
*/
|
|
31
|
+
export declare function invalidateOtherLoginCodes(ctx: Context<any>, codes: CodesAdapter, tenantId: string, loginId: string, recipient: string): Promise<void>;
|
|
32
|
+
export declare function preSignupCodeState(recipient: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Whether `stored` is an unexpired, unused pre-signup code minted for this
|
|
35
|
+
* login session and sent to `email`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isPreSignupCodeFor(stored: Code | null | undefined, loginId: string, email: string | undefined): stored is Code;
|
|
@@ -14,9 +14,9 @@ export declare const USERINFO_RESERVED_CLAIMS: readonly ["iss", "sub", "aud", "e
|
|
|
14
14
|
* vendor/tenant for downstream APIs while `sub` stays `auth-service`.
|
|
15
15
|
* Client-bound mints keep `azp` locked (see below).
|
|
16
16
|
*/
|
|
17
|
-
export declare const SERVICE_TOKEN_RESERVED_CLAIMS: ("
|
|
17
|
+
export declare const SERVICE_TOKEN_RESERVED_CLAIMS: ("client_id" | "scope" | "sub" | "tenant_id" | "org_name" | "jti" | "sid" | "org_id" | "iss" | "exp" | "iat" | "aud" | "auth_time" | "acr" | "amr" | "gty" | "nbf" | "act" | "permissions" | "requested_userinfo_claims")[];
|
|
18
18
|
/** Client-bound mints: `azp` must stay the registered client id. */
|
|
19
|
-
export declare const CLIENT_SERVICE_TOKEN_RESERVED_CLAIMS: ("
|
|
19
|
+
export declare const CLIENT_SERVICE_TOKEN_RESERVED_CLAIMS: ("client_id" | "scope" | "sub" | "tenant_id" | "org_name" | "jti" | "sid" | "org_id" | "iss" | "exp" | "iat" | "aud" | "auth_time" | "acr" | "amr" | "azp" | "gty" | "nbf" | "act" | "permissions" | "requested_userinfo_claims")[];
|
|
20
20
|
export type AccessTokenReservedClaim = (typeof ACCESS_TOKEN_RESERVED_CLAIMS)[number];
|
|
21
21
|
export type IdTokenReservedClaim = (typeof ID_TOKEN_RESERVED_CLAIMS)[number];
|
|
22
22
|
/**
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The grant type a response type needs that the client's `grant_types` lacks,
|
|
3
|
+
* or undefined. A `code` response needs `authorization_code`; a response that
|
|
4
|
+
* returns `token` or `id_token` from the authorization endpoint needs
|
|
5
|
+
* `implicit`, so hybrid responses need both. A client without `grant_types`
|
|
6
|
+
* is unrestricted, as at the token endpoint.
|
|
7
|
+
*/
|
|
8
|
+
export declare function missingGrantTypeForResponseType(grantTypes: string[] | undefined, responseType: string | undefined): string | undefined;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { HTTPException } from "hono/http-exception";
|
|
2
|
+
import { Hook, User } from "@authhero/adapter-interfaces";
|
|
3
|
+
import { RequestContext } from "../types";
|
|
4
|
+
import { CodeHookEventInput } from "./codehooks";
|
|
5
|
+
/**
|
|
6
|
+
* Auth0's custom provider triggers. A tenant binds an action to one of them to
|
|
7
|
+
* deliver outgoing emails / text messages from its own system. With nothing
|
|
8
|
+
* bound, messages go to the tenant's normal provider exactly as before.
|
|
9
|
+
*
|
|
10
|
+
* - https://auth0.com/docs/customize/email/smtp-email-providers/custom/configure-action
|
|
11
|
+
* - https://auth0.com/docs/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider
|
|
12
|
+
*/
|
|
13
|
+
export declare const CUSTOM_EMAIL_PROVIDER_TRIGGER = "custom-email-provider";
|
|
14
|
+
export declare const CUSTOM_PHONE_PROVIDER_TRIGGER = "custom-phone-provider";
|
|
15
|
+
export type NotificationTrigger = typeof CUSTOM_EMAIL_PROVIDER_TRIGGER | typeof CUSTOM_PHONE_PROVIDER_TRIGGER;
|
|
16
|
+
/** Auth0 truncates `drop` / `retry` reasons to 1024 characters. */
|
|
17
|
+
export declare const NOTIFICATION_REASON_MAX_LENGTH = 1024;
|
|
18
|
+
/**
|
|
19
|
+
* Background retries after `api.notification.retry()`: Auth0 retries "up to 5
|
|
20
|
+
* times in the next minutes". AuthHero retries from the request's background
|
|
21
|
+
* window (`waitUntil`), which is about 30 seconds on Workers, so the delays are
|
|
22
|
+
* kept short. The message is held in memory only and never persisted.
|
|
23
|
+
*/
|
|
24
|
+
export declare const NOTIFICATION_RETRY_DELAYS_MS: readonly number[];
|
|
25
|
+
/**
|
|
26
|
+
* Workers cancels `waitUntil` work 30 seconds after the response. Retries stop
|
|
27
|
+
* (and log `fn`) once another delay plus a full action timeout would no longer
|
|
28
|
+
* fit in this budget, so the terminal log is always written inside the window.
|
|
29
|
+
*/
|
|
30
|
+
export declare const NOTIFICATION_RETRY_BUDGET_MS = 25000;
|
|
31
|
+
/** `event.notification` for `custom-email-provider`, Auth0's shape. */
|
|
32
|
+
export type EmailNotification = {
|
|
33
|
+
message_type: string;
|
|
34
|
+
to: string;
|
|
35
|
+
from: string;
|
|
36
|
+
subject: string;
|
|
37
|
+
html: string;
|
|
38
|
+
text: string;
|
|
39
|
+
locale: string;
|
|
40
|
+
};
|
|
41
|
+
/** `event.notification` for `custom-phone-provider`, Auth0's shape. */
|
|
42
|
+
export type PhoneNotification = {
|
|
43
|
+
message_type: string;
|
|
44
|
+
recipient: string;
|
|
45
|
+
from: string;
|
|
46
|
+
as_text: string;
|
|
47
|
+
as_voice: string;
|
|
48
|
+
code?: string;
|
|
49
|
+
delivery_method: "text" | "voice";
|
|
50
|
+
locale: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Thrown when a message could not be delivered by the custom provider action:
|
|
54
|
+
* it was dropped, threw, timed out, or no action could take it. The message is
|
|
55
|
+
* generic on purpose: the one-time code and message content must never end up
|
|
56
|
+
* in an error message.
|
|
57
|
+
*/
|
|
58
|
+
export declare class NotificationDeliveryError extends HTTPException {
|
|
59
|
+
readonly trigger: NotificationTrigger;
|
|
60
|
+
constructor(trigger: NotificationTrigger);
|
|
61
|
+
}
|
|
62
|
+
type CodeHook = Extract<Hook, {
|
|
63
|
+
code_id: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** The outcome of one run of the bound action. */
|
|
66
|
+
export type NotificationAttempt = {
|
|
67
|
+
type: "delivered";
|
|
68
|
+
} | {
|
|
69
|
+
type: "use_default_provider";
|
|
70
|
+
} | {
|
|
71
|
+
type: "dropped";
|
|
72
|
+
reason: string;
|
|
73
|
+
} | {
|
|
74
|
+
type: "retry";
|
|
75
|
+
reason: string;
|
|
76
|
+
} | {
|
|
77
|
+
type: "failed";
|
|
78
|
+
reason: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Replace every occurrence of a secret (the one-time code, a link carrying a
|
|
82
|
+
* token, the rendered message) with a marker. Longest first, so a rendered
|
|
83
|
+
* body is removed whole before the code inside it is looked for. Values
|
|
84
|
+
* shorter than 4 characters are skipped: they would match unrelated text.
|
|
85
|
+
*/
|
|
86
|
+
export declare function redactNotificationSecrets(value: string, secrets: readonly string[]): string;
|
|
87
|
+
/**
|
|
88
|
+
* Build the scrubber applied to everything an action reports back (console
|
|
89
|
+
* lines, error messages, drop/retry reasons):
|
|
90
|
+
*
|
|
91
|
+
* 1. Exact secrets (and their JSON-escaped forms, as `JSON.stringify(event)`
|
|
92
|
+
* would print them) are replaced by `[REDACTED]`.
|
|
93
|
+
* 2. A value that still shares a run of 20 characters with a long secret (the
|
|
94
|
+
* rendered message, a link) is withheld entirely. Executors truncate console
|
|
95
|
+
* lines, so an echoed message often survives only as a fragment that exact
|
|
96
|
+
* matching can't catch.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createNotificationScrubber(secrets: readonly string[]): (value: string) => string;
|
|
99
|
+
/**
|
|
100
|
+
* The enabled action bound to `trigger` that handles `messageType`, highest
|
|
101
|
+
* priority first. A binding whose `metadata.message_types` (AuthHero
|
|
102
|
+
* extension) doesn't list the type is skipped, so that message stays with the
|
|
103
|
+
* tenant's normal provider. No list means every type, as in Auth0.
|
|
104
|
+
*/
|
|
105
|
+
export declare function findNotificationHook(ctx: RequestContext, tenantId: string, trigger: NotificationTrigger, messageType: string): Promise<CodeHook | undefined>;
|
|
106
|
+
/**
|
|
107
|
+
* Run the bound action once and read what it decided. Everything the action
|
|
108
|
+
* reports back (error messages, console output, reasons) is redacted before it
|
|
109
|
+
* is persisted or returned.
|
|
110
|
+
*/
|
|
111
|
+
export declare function runNotificationAction(ctx: RequestContext, params: {
|
|
112
|
+
trigger: NotificationTrigger;
|
|
113
|
+
tenantId: string;
|
|
114
|
+
hook: CodeHook;
|
|
115
|
+
event: CodeHookEventInput;
|
|
116
|
+
secrets: readonly string[];
|
|
117
|
+
}): Promise<NotificationAttempt>;
|
|
118
|
+
export type DeliverNotificationParams = {
|
|
119
|
+
trigger: NotificationTrigger;
|
|
120
|
+
tenantId: string;
|
|
121
|
+
messageType: string;
|
|
122
|
+
/**
|
|
123
|
+
* Builds `event.notification` (already rendered). Only called when an
|
|
124
|
+
* action is bound, so plain sends don't pay for it.
|
|
125
|
+
*/
|
|
126
|
+
buildNotification: () => Promise<EmailNotification | PhoneNotification>;
|
|
127
|
+
/** The recipient's address or number, recorded in the tenant logs. */
|
|
128
|
+
recipient: string;
|
|
129
|
+
/**
|
|
130
|
+
* Values that must never reach logs, execution records or errors: the
|
|
131
|
+
* one-time code, links carrying a token, and the rendered content. The
|
|
132
|
+
* rendered content in `notification` is added automatically.
|
|
133
|
+
*/
|
|
134
|
+
secrets?: string[];
|
|
135
|
+
/** The user the message is for, or a loader for it (runs only when an action is bound). */
|
|
136
|
+
user?: User | (() => Promise<User | undefined>);
|
|
137
|
+
/** Send with the tenant's normal provider, unchanged from before. */
|
|
138
|
+
sendDefault: () => Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* There is no normal provider to fall back to (the email provider is named
|
|
141
|
+
* `custom`, as Auth0 tooling configures it): the message must go to an
|
|
142
|
+
* action, and `useDefaultProvider()` is an error.
|
|
143
|
+
*/
|
|
144
|
+
requireAction?: boolean;
|
|
145
|
+
/** Override the background retry delays (tests). */
|
|
146
|
+
retryDelaysMs?: readonly number[];
|
|
147
|
+
/** Override the background retry budget (tests). */
|
|
148
|
+
retryBudgetMs?: number;
|
|
149
|
+
/**
|
|
150
|
+
* Whether this message is still worth delivering, checked before each
|
|
151
|
+
* background retry. A resend that replaced the one-time code makes an older
|
|
152
|
+
* pending delivery stale: delivering it later would show the user a code
|
|
153
|
+
* that no longer works.
|
|
154
|
+
*/
|
|
155
|
+
isCurrent?: () => Promise<boolean>;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Deliver one outgoing message: through the action bound to the custom
|
|
159
|
+
* provider trigger when there is one for this message type, otherwise through
|
|
160
|
+
* the tenant's normal provider (`sendDefault`), unchanged.
|
|
161
|
+
*
|
|
162
|
+
* - Delivered: returns; the caller logs the send as it always has.
|
|
163
|
+
* - `useDefaultProvider()`: sends with the normal provider.
|
|
164
|
+
* - `drop()`, a throw, a timeout or a missing executor: logs `fn` and throws
|
|
165
|
+
* `NotificationDeliveryError`, so the user sees that sending failed rather
|
|
166
|
+
* than waiting for a message that never comes. It never falls back to the
|
|
167
|
+
* normal provider on its own.
|
|
168
|
+
* - `retry()`: logs `wn`, returns as accepted, and retries in the background
|
|
169
|
+
* up to 5 times; `fn` if every retry fails.
|
|
170
|
+
*/
|
|
171
|
+
export declare function deliverNotification(ctx: RequestContext, params: DeliverNotificationParams): Promise<void>;
|
|
172
|
+
/** A rough plain-text rendering of an HTML email for `event.notification.text`. */
|
|
173
|
+
export declare function htmlToText(html: string): string;
|
|
174
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Context } from "hono";
|
|
2
|
+
import { Connection, DataAdapters, User } from "@authhero/adapter-interfaces";
|
|
3
|
+
import { Bindings, Variables } from "../../types";
|
|
4
|
+
/** Most `api.users.ensure` calls one action execution may make. */
|
|
5
|
+
export declare const MAX_ENSURED_USERS_PER_EXECUTION = 5;
|
|
6
|
+
/**
|
|
7
|
+
* Lazily loads the tenant's connections once per execution. Used to resolve
|
|
8
|
+
* the connection `ensure` writes to and to tell whether a user is an anchor
|
|
9
|
+
* (a primary whose connection is an external connection) without a lookup
|
|
10
|
+
* per call.
|
|
11
|
+
*
|
|
12
|
+
* `injectedStrategies` are the names of strategies supplied through
|
|
13
|
+
* `env.STRATEGIES`: a login connection using one stores its users under that
|
|
14
|
+
* name, so an external connection must not reuse it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createExternalConnectionLookup(data: DataAdapters, tenantId: string, injectedStrategies?: Iterable<string>): {
|
|
17
|
+
/**
|
|
18
|
+
* The external connection named `name` if actions may create users in it:
|
|
19
|
+
* opted in with `allow_action_users`, and not named like a prefix that
|
|
20
|
+
* login identities use.
|
|
21
|
+
*/
|
|
22
|
+
getActionUsersConnection: (name: string) => Promise<Connection | undefined>;
|
|
23
|
+
/** True when `user` lives in one of the tenant's external connections. */
|
|
24
|
+
isExternalUser: (user: Pick<User, "connection" | "provider">) => Promise<boolean>;
|
|
25
|
+
};
|
|
26
|
+
export type ExternalConnectionLookup = ReturnType<typeof createExternalConnectionLookup>;
|
|
27
|
+
/**
|
|
28
|
+
* Builds the host implementation of `api.users.ensure` (issue #1802).
|
|
29
|
+
*
|
|
30
|
+
* The isolate only records the call; this runs when it is replayed. It
|
|
31
|
+
* creates `<connection>|<id>` if missing, otherwise merges the profile and
|
|
32
|
+
* `app_metadata` into it. Every refusal logs `FAILED_HOOK` and writes nothing.
|
|
33
|
+
*
|
|
34
|
+
* Writes go through the transaction's adapters, which are undecorated: no
|
|
35
|
+
* registration or update hooks, no built-in email linking (which would demote
|
|
36
|
+
* a new anchor under an older same-email user), and no post-registration
|
|
37
|
+
* webhook or outbox event — the user is a record, not a signup.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createActionUsersApi(params: {
|
|
40
|
+
ctx: Context<{
|
|
41
|
+
Bindings: Bindings;
|
|
42
|
+
Variables: Variables;
|
|
43
|
+
}>;
|
|
44
|
+
data: DataAdapters;
|
|
45
|
+
tenantId: string;
|
|
46
|
+
triggerId: string;
|
|
47
|
+
externalConnections: ExternalConnectionLookup;
|
|
48
|
+
}): {
|
|
49
|
+
api: {
|
|
50
|
+
users: {
|
|
51
|
+
ensure: (raw: unknown) => Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** user_ids that `ensure` created or updated during this execution. */
|
|
55
|
+
ensuredUserIds: Set<string>;
|
|
56
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
import { DataAdapters, User } from "@authhero/adapter-interfaces";
|
|
3
3
|
import { Bindings, Variables } from "../../types";
|
|
4
|
+
import { ExternalConnectionLookup } from "./action-users";
|
|
4
5
|
/**
|
|
5
6
|
* The `user` namespace exposed to `post-user-login` code hooks. `setLinkedTo`
|
|
6
7
|
* is the programmable account-linking verb (issue #1184): an action reads
|
|
@@ -28,10 +29,16 @@ export type PostLoginUserApi = {
|
|
|
28
29
|
* - **Verified-email gate.** When `requireVerifiedEmail` (the default), the
|
|
29
30
|
* logging-in user must have a verified email, regardless of what the action
|
|
30
31
|
* asserts.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* Users created by `api.users.ensure` in the same execution are also
|
|
33
|
+
* allowed (issue #1802); they skip the verified-email gate because the
|
|
34
|
+
* action resolved the person against its own system of record.
|
|
35
|
+
* - **Direction.** A primary in an `external` connection (an anchor) always
|
|
36
|
+
* stays primary. Otherwise the older account wins (`compareUsersByAge`):
|
|
37
|
+
* if the logging-in user pre-dates the target, the target is demoted
|
|
38
|
+
* instead. Either way the write goes through the update decorator's
|
|
39
|
+
* `linkUserTo` chokepoint, which keeps the cluster a single hop deep.
|
|
40
|
+
* - **No re-anchoring.** A user already under one anchor is never moved
|
|
41
|
+
* under a different one by a login; that is an admin operation.
|
|
35
42
|
* - **Idempotency.** A no-op when the user is already linked to the target.
|
|
36
43
|
*/
|
|
37
44
|
export declare function createPostLoginUserApi(params: {
|
|
@@ -46,6 +53,13 @@ export declare function createPostLoginUserApi(params: {
|
|
|
46
53
|
candidates: User[];
|
|
47
54
|
/** @default true */
|
|
48
55
|
requireVerifiedEmail?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* user_ids created or updated by `api.users.ensure` earlier in the same
|
|
58
|
+
* execution. Read at replay time, so it must be the live set.
|
|
59
|
+
*/
|
|
60
|
+
ensuredUserIds?: ReadonlySet<string>;
|
|
61
|
+
/** Tells anchors (users in an `external` connection) apart. */
|
|
62
|
+
externalConnections?: ExternalConnectionLookup;
|
|
49
63
|
}): {
|
|
50
64
|
api: PostLoginUserApi;
|
|
51
65
|
/** The user id of the primary after linking, or null if nothing linked. */
|
|
@@ -10,7 +10,7 @@ export declare function listEnabledCodeHooks(ctx: Context<{
|
|
|
10
10
|
Bindings: Bindings;
|
|
11
11
|
Variables: Variables;
|
|
12
12
|
}>, tenantId: string, triggerId: string): Promise<{
|
|
13
|
-
trigger_id: "
|
|
13
|
+
trigger_id: "post-user-login" | "credentials-exchange" | "pre-user-registration" | "post-user-registration" | "post-user-update" | "validate-registration-username" | "pre-user-deletion" | "post-user-deletion" | "pre-user-update" | "pre-screen" | "custom-email-provider" | "custom-phone-provider";
|
|
14
14
|
enabled: boolean;
|
|
15
15
|
synchronous: boolean;
|
|
16
16
|
created_at: string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Context } from "hono";
|
|
2
|
+
import { Hook, LoginSession, PreScreenOperation, PreScreenPhase, User } from "@authhero/adapter-interfaces";
|
|
3
|
+
import { Bindings, Variables } from "../types";
|
|
4
|
+
import { EnrichedClient } from "../helpers/client";
|
|
5
|
+
type Ctx = Context<{
|
|
6
|
+
Bindings: Bindings;
|
|
7
|
+
Variables: Variables;
|
|
8
|
+
}>;
|
|
9
|
+
type CodeHook = Extract<Hook, {
|
|
10
|
+
code_id: string;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const PRE_SCREEN_TRIGGER = "pre-screen";
|
|
13
|
+
/**
|
|
14
|
+
* Host wait for the `onExecutePreScreen` config callback, matching the bound
|
|
15
|
+
* on code Actions. A callback that never settles must not leave the screen
|
|
16
|
+
* hanging.
|
|
17
|
+
*/
|
|
18
|
+
export declare const PRE_SCREEN_TIMEOUT_MS = 5000;
|
|
19
|
+
/** Shown when an action denies without a reason, or fails closed. */
|
|
20
|
+
export declare const DEFAULT_PRE_SCREEN_DENIAL = "This isn't available for your account.";
|
|
21
|
+
export type PreScreenDecision = {
|
|
22
|
+
type: "continue";
|
|
23
|
+
} | {
|
|
24
|
+
type: "redirect";
|
|
25
|
+
url: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "deny";
|
|
28
|
+
reason: string;
|
|
29
|
+
};
|
|
30
|
+
/** What a submission does, for the submit phase's `event.operation`. */
|
|
31
|
+
export type PreScreenSubmission = {
|
|
32
|
+
operation: PreScreenOperation;
|
|
33
|
+
details?: Record<string, string>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Thrown when a `pre-screen` Action denies a screen or its submission. The
|
|
37
|
+
* universal-login error handler renders `reason` on the branded error page
|
|
38
|
+
* (other error messages are replaced by a generic text there, which would
|
|
39
|
+
* hide the tenant's explanation).
|
|
40
|
+
*/
|
|
41
|
+
export declare class ScreenDeniedError extends Error {
|
|
42
|
+
readonly reason: string;
|
|
43
|
+
readonly status = 403;
|
|
44
|
+
constructor(reason: string);
|
|
45
|
+
}
|
|
46
|
+
/** A loader that only runs when something is bound to the screen. */
|
|
47
|
+
type Lazy<T> = () => Promise<T>;
|
|
48
|
+
export interface PreScreenParams {
|
|
49
|
+
tenantId: string;
|
|
50
|
+
/** Screen name from `PRE_SCREEN_SCREENS`, e.g. `login-id`. */
|
|
51
|
+
screen: string;
|
|
52
|
+
phase: PreScreenPhase;
|
|
53
|
+
/**
|
|
54
|
+
* Everything below is only loaded when something is bound to the screen,
|
|
55
|
+
* so unbound screens pay nothing beyond the (cached) hook list.
|
|
56
|
+
*/
|
|
57
|
+
client?: Lazy<EnrichedClient | undefined>;
|
|
58
|
+
loginSession?: Lazy<LoginSession | undefined>;
|
|
59
|
+
user?: Lazy<User | undefined>;
|
|
60
|
+
/** Submit phase: the operation the submission performs, if any. */
|
|
61
|
+
submission?: Lazy<PreScreenSubmission | undefined>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The enabled code hooks bound to `pre-screen` that run for `screen`, highest
|
|
65
|
+
* priority first. Reads the unparameterized hook list, which the client bundle
|
|
66
|
+
* serves from cache, and only queries when that page is full.
|
|
67
|
+
*/
|
|
68
|
+
export declare function findPreScreenHooks(ctx: Ctx, tenantId: string, screen: string): Promise<CodeHook[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a redirect target from an Action. Only the URL and query the Action
|
|
71
|
+
* returned are used: relative URLs resolve against the current request and
|
|
72
|
+
* anything other than http(s) is rejected, so an Action can't send the
|
|
73
|
+
* browser to `javascript:` or `data:` URLs. Nothing from the request (its
|
|
74
|
+
* query, `redirect_uri`, the login session) is added, so the trigger can't be
|
|
75
|
+
* used as an open redirect. No `state` is appended: the user leaves this
|
|
76
|
+
* transaction, which stays resumable until the login session expires.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildPreScreenRedirectUrl(requestUrl: string, url: unknown, options: unknown): string;
|
|
79
|
+
/**
|
|
80
|
+
* Run the `pre-screen` trigger: the `onExecutePreScreen` config hook first,
|
|
81
|
+
* then the code Actions bound to the screen in priority order. The first one
|
|
82
|
+
* that redirects or denies decides and later ones don't run.
|
|
83
|
+
*
|
|
84
|
+
* An Action that throws, times out or fails denies a submission (fail
|
|
85
|
+
* closed). In the render phase it is logged and the screen is shown, unless
|
|
86
|
+
* the binding set `metadata.fail_closed`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function runPreScreen(ctx: Ctx, params: PreScreenParams): Promise<PreScreenDecision>;
|
|
89
|
+
/**
|
|
90
|
+
* Run the trigger and act on the result: throws `RedirectException` to send
|
|
91
|
+
* the user elsewhere and `ScreenDeniedError` to stop. Both are rendered by the
|
|
92
|
+
* universal-login error handler. Returns normally when the screen may go on.
|
|
93
|
+
*/
|
|
94
|
+
export declare function enforcePreScreen(ctx: Ctx, params: PreScreenParams): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* The user an identifier (email, phone number or username) entered on a
|
|
97
|
+
* login, signup or password-reset screen belongs to, resolved to the primary
|
|
98
|
+
* user. Undefined when no user matches.
|
|
99
|
+
*/
|
|
100
|
+
export declare function findUserByIdentifier(ctx: Ctx, tenantId: string, identifier: unknown): Promise<User | undefined>;
|
|
101
|
+
/**
|
|
102
|
+
* The user of a login-flow screen: the identifier just submitted (pass it
|
|
103
|
+
* only for screens where the user enters one), then the user the transaction
|
|
104
|
+
* already authenticated (MFA, consent, passkey enrollment), then the
|
|
105
|
+
* identifier entered earlier in the flow.
|
|
106
|
+
*/
|
|
107
|
+
export declare function findLoginScreenUser(ctx: Ctx, tenantId: string, loginSession: LoginSession | undefined, submittedIdentifier?: unknown): Promise<User | undefined>;
|
|
108
|
+
/**
|
|
109
|
+
* The user of an account screen: the signed-in session's user, or, mid-login
|
|
110
|
+
* (a form hook sent the user to an account page), the user the transaction
|
|
111
|
+
* authenticated. The screen still enforces its own access rules afterwards.
|
|
112
|
+
*/
|
|
113
|
+
export declare function findAccountScreenUser(ctx: Ctx, tenantId: string, loginSession: LoginSession | undefined): Promise<User | undefined>;
|
|
114
|
+
export {};
|