@outseta/react 0.3.0 → 0.3.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outseta/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "React hooks and components for the Outseta API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@tanstack/react-query": "^5.0.0",
|
|
22
|
-
"@outseta/api-client": "0.3.
|
|
22
|
+
"@outseta/api-client": "0.3.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -2633,11 +2633,163 @@ export const EmailListSubscriberStatus = {
|
|
|
2633
2633
|
Confirmed: 4,
|
|
2634
2634
|
} as const;
|
|
2635
2635
|
|
|
2636
|
+
export interface TokenPayload {
|
|
2637
|
+
/** @nullable */
|
|
2638
|
+
access_token?: string | null;
|
|
2639
|
+
/** @nullable */
|
|
2640
|
+
authentication_callback_url?: string | null;
|
|
2641
|
+
expires_in?: number;
|
|
2642
|
+
/** @nullable */
|
|
2643
|
+
id_token?: string | null;
|
|
2644
|
+
/** @nullable */
|
|
2645
|
+
token_type?: string | null;
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
/**
|
|
2649
|
+
* Returned when a login cannot complete with a password alone because the
|
|
2650
|
+
user has two-factor authentication enabled. Carries the opaque challenge
|
|
2651
|
+
token that must be echoed back to POST /api/v1/tokens/two-factor
|
|
2652
|
+
(or the recovery / resend / switch-mechanism endpoints) along with enough
|
|
2653
|
+
metadata for a client to render the verification step without a second
|
|
2654
|
+
round-trip. The property names are snake_case to match the wire format of
|
|
2655
|
+
the other token endpoints (see TokenPayload).
|
|
2656
|
+
*/
|
|
2657
|
+
export interface TwoFactorChallengePayload {
|
|
2658
|
+
/**
|
|
2659
|
+
* Present and true on the 202 response from POST /api/v1/tokens
|
|
2660
|
+
when the user has at least one verified 2FA method. Absent on the
|
|
2661
|
+
resend / switch-mechanism responses, which only ever follow an
|
|
2662
|
+
already-issued login challenge.
|
|
2663
|
+
* @nullable
|
|
2664
|
+
*/
|
|
2665
|
+
two_factor_required?: boolean | null;
|
|
2666
|
+
/**
|
|
2667
|
+
* Present and true instead of two_factor_required
|
|
2668
|
+
when the tenant forces 2FA but the user has not yet enrolled any
|
|
2669
|
+
method. In that case only challenge_token and
|
|
2670
|
+
expires_in are populated and the client must route the
|
|
2671
|
+
user through the mid-login enrollment endpoints
|
|
2672
|
+
(/api/v1/tokens/two-factor/enroll/...) before a token can be issued.
|
|
2673
|
+
* @nullable
|
|
2674
|
+
*/
|
|
2675
|
+
two_factor_enrollment_required?: boolean | null;
|
|
2676
|
+
/**
|
|
2677
|
+
* Short-lived signed JWT (audience outseta:2fa-challenge) that
|
|
2678
|
+
identifies this challenge. Echo it back verbatim to complete the login.
|
|
2679
|
+
* @nullable
|
|
2680
|
+
*/
|
|
2681
|
+
challenge_token?: string | null;
|
|
2682
|
+
/**
|
|
2683
|
+
* The mechanism this challenge was issued against: Email or
|
|
2684
|
+
Totp (authenticator app). For Email a code has already
|
|
2685
|
+
been sent to the user; for Totp the user reads the current
|
|
2686
|
+
code from their authenticator app and nothing is sent.
|
|
2687
|
+
* @nullable
|
|
2688
|
+
*/
|
|
2689
|
+
mechanism?: string | null;
|
|
2690
|
+
/**
|
|
2691
|
+
* A masked view of where an emailed code was sent (e.g. b***@outseta.com),
|
|
2692
|
+
suitable for display. Empty when mechanism is Totp.
|
|
2693
|
+
* @nullable
|
|
2694
|
+
*/
|
|
2695
|
+
masked_destination?: string | null;
|
|
2696
|
+
/** Seconds until the challenge expires (600). After this the
|
|
2697
|
+
challenge_token can no longer be verified and the login must restart. */
|
|
2698
|
+
expires_in?: number;
|
|
2699
|
+
/**
|
|
2700
|
+
* Every verified mechanism enrolled for this user (excluding recovery
|
|
2701
|
+
codes), e.g. ["Totp", "Email"]. A client can offer a
|
|
2702
|
+
"use a different method" option for any value other than the current
|
|
2703
|
+
mechanism via POST /api/v1/tokens/two-factor/switch-mechanism.
|
|
2704
|
+
* @nullable
|
|
2705
|
+
*/
|
|
2706
|
+
available_mechanisms?: string[] | null;
|
|
2707
|
+
/**
|
|
2708
|
+
* true when the user has a batch of recovery codes on file, in
|
|
2709
|
+
which case POST /api/v1/tokens/two-factor/recovery can be used
|
|
2710
|
+
as a fallback if they cannot produce a primary code.
|
|
2711
|
+
* @nullable
|
|
2712
|
+
*/
|
|
2713
|
+
recovery_codes_available?: boolean | null;
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2636
2716
|
export interface PasswordPayload {
|
|
2637
2717
|
/** @nullable */
|
|
2638
2718
|
Password?: string | null;
|
|
2639
2719
|
}
|
|
2640
2720
|
|
|
2721
|
+
/**
|
|
2722
|
+
* Returned from POST /api/v1/tokens/two-factor/enroll/totp/begin when a
|
|
2723
|
+
user forced into 2FA chooses to enroll an authenticator app. Carries the
|
|
2724
|
+
shared secret in the three forms a client may need to present it, plus the
|
|
2725
|
+
challenge token the user's first generated code is confirmed against. The
|
|
2726
|
+
property names are snake_case to match the wire format of the other token
|
|
2727
|
+
endpoints (see TokenPayload).
|
|
2728
|
+
*/
|
|
2729
|
+
export interface TwoFactorTotpEnrollmentPayload {
|
|
2730
|
+
/**
|
|
2731
|
+
* Short-lived signed JWT identifying the enrollment-test challenge.
|
|
2732
|
+
Echo it back to POST /api/v1/tokens/two-factor/enroll/totp/confirm
|
|
2733
|
+
along with the first code from the authenticator app.
|
|
2734
|
+
* @nullable
|
|
2735
|
+
*/
|
|
2736
|
+
challenge_token?: string | null;
|
|
2737
|
+
/**
|
|
2738
|
+
* The Base32-encoded shared secret. Offer this for manual entry by users
|
|
2739
|
+
who cannot scan the QR code.
|
|
2740
|
+
* @nullable
|
|
2741
|
+
*/
|
|
2742
|
+
secret?: string | null;
|
|
2743
|
+
/**
|
|
2744
|
+
* The full otpauth://totp/... URI encoding the secret, issuer and
|
|
2745
|
+
parameters. Most authenticator apps add an account directly from this.
|
|
2746
|
+
* @nullable
|
|
2747
|
+
*/
|
|
2748
|
+
otpauth_uri?: string | null;
|
|
2749
|
+
/**
|
|
2750
|
+
* A QR code rendering of otpauth_uri as a PNG, Base64
|
|
2751
|
+
encoded — render it as an <img> for the user to scan.
|
|
2752
|
+
* @nullable
|
|
2753
|
+
*/
|
|
2754
|
+
qr_code_png_base64?: string | null;
|
|
2755
|
+
/** Seconds until the enrollment-test challenge expires (600). */
|
|
2756
|
+
expires_in?: number;
|
|
2757
|
+
}
|
|
2758
|
+
|
|
2759
|
+
/**
|
|
2760
|
+
* Returned from the mid-login enrollment confirm endpoints
|
|
2761
|
+
(POST /api/v1/tokens/two-factor/enroll/{email|totp}/confirm) once the
|
|
2762
|
+
user has proven control of the new mechanism. Completes a forced-enrollment
|
|
2763
|
+
login: it both finalizes the JWT access token and surfaces the freshly
|
|
2764
|
+
generated recovery codes. The property names are snake_case to match the
|
|
2765
|
+
wire format of the other token endpoints (see TokenPayload).
|
|
2766
|
+
*/
|
|
2767
|
+
export interface TwoFactorEnrollmentConfirmationPayload {
|
|
2768
|
+
/** Always true on a success response; the enrollment is now active. */
|
|
2769
|
+
confirmed?: boolean;
|
|
2770
|
+
/**
|
|
2771
|
+
* The user's recovery codes, generated as part of first-time enrollment.
|
|
2772
|
+
These are shown once and never returned again — prompt the user
|
|
2773
|
+
to store them somewhere safe. Each code is single-use at
|
|
2774
|
+
POST /api/v1/tokens/two-factor/recovery.
|
|
2775
|
+
* @nullable
|
|
2776
|
+
*/
|
|
2777
|
+
recovery_codes?: string[] | null;
|
|
2778
|
+
/**
|
|
2779
|
+
* The JWT access token. Use it as Authorization: bearer {access_token}
|
|
2780
|
+
for subsequent API calls — login is complete.
|
|
2781
|
+
* @nullable
|
|
2782
|
+
*/
|
|
2783
|
+
access_token?: string | null;
|
|
2784
|
+
/**
|
|
2785
|
+
* Always Bearer.
|
|
2786
|
+
* @nullable
|
|
2787
|
+
*/
|
|
2788
|
+
token_type?: string | null;
|
|
2789
|
+
/** Seconds until the access token expires. */
|
|
2790
|
+
expires_in?: number;
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2641
2793
|
/**
|
|
2642
2794
|
* @nullable
|
|
2643
2795
|
*/
|
|
@@ -5658,6 +5810,69 @@ export interface PersonSegmentRemovedWebhookPayload {
|
|
|
5658
5810
|
ActivityEventData?: PersonSegmentRemovedActivityData;
|
|
5659
5811
|
}
|
|
5660
5812
|
|
|
5813
|
+
export type AuthGetTokenParams = {
|
|
5814
|
+
/**
|
|
5815
|
+
* @nullable
|
|
5816
|
+
*/
|
|
5817
|
+
data: unknown | null;
|
|
5818
|
+
};
|
|
5819
|
+
|
|
5820
|
+
export type AuthVerifyTwoFactorTokenParams = {
|
|
5821
|
+
/**
|
|
5822
|
+
* @nullable
|
|
5823
|
+
*/
|
|
5824
|
+
data: unknown | null;
|
|
5825
|
+
};
|
|
5826
|
+
|
|
5827
|
+
export type AuthResendTwoFactorParams = {
|
|
5828
|
+
/**
|
|
5829
|
+
* @nullable
|
|
5830
|
+
*/
|
|
5831
|
+
data: unknown | null;
|
|
5832
|
+
};
|
|
5833
|
+
|
|
5834
|
+
export type AuthSwitchTwoFactorMechanismParams = {
|
|
5835
|
+
/**
|
|
5836
|
+
* @nullable
|
|
5837
|
+
*/
|
|
5838
|
+
data: unknown | null;
|
|
5839
|
+
};
|
|
5840
|
+
|
|
5841
|
+
export type AuthVerifyTwoFactorRecoveryParams = {
|
|
5842
|
+
/**
|
|
5843
|
+
* @nullable
|
|
5844
|
+
*/
|
|
5845
|
+
data: unknown | null;
|
|
5846
|
+
};
|
|
5847
|
+
|
|
5848
|
+
export type TokenTwoFactorEnrollmentBeginEmailParams = {
|
|
5849
|
+
/**
|
|
5850
|
+
* @nullable
|
|
5851
|
+
*/
|
|
5852
|
+
data: unknown | null;
|
|
5853
|
+
};
|
|
5854
|
+
|
|
5855
|
+
export type TokenTwoFactorEnrollmentBeginTotpParams = {
|
|
5856
|
+
/**
|
|
5857
|
+
* @nullable
|
|
5858
|
+
*/
|
|
5859
|
+
data: unknown | null;
|
|
5860
|
+
};
|
|
5861
|
+
|
|
5862
|
+
export type TokenTwoFactorEnrollmentConfirmEmailParams = {
|
|
5863
|
+
/**
|
|
5864
|
+
* @nullable
|
|
5865
|
+
*/
|
|
5866
|
+
data: unknown | null;
|
|
5867
|
+
};
|
|
5868
|
+
|
|
5869
|
+
export type TokenTwoFactorEnrollmentConfirmTotpParams = {
|
|
5870
|
+
/**
|
|
5871
|
+
* @nullable
|
|
5872
|
+
*/
|
|
5873
|
+
data: unknown | null;
|
|
5874
|
+
};
|
|
5875
|
+
|
|
5661
5876
|
export type CaseGetAllCasesParams = {
|
|
5662
5877
|
/**
|
|
5663
5878
|
* Search string
|
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import {
|
|
3
|
+
useMutation
|
|
4
|
+
} from '@tanstack/react-query';
|
|
5
|
+
import type {
|
|
6
|
+
MutationFunction,
|
|
7
|
+
UseMutationOptions,
|
|
8
|
+
UseMutationResult
|
|
9
|
+
} from '@tanstack/react-query';
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
AuthGetTokenParams,
|
|
13
|
+
AuthResendTwoFactorParams,
|
|
14
|
+
AuthSwitchTwoFactorMechanismParams,
|
|
15
|
+
AuthVerifyTwoFactorRecoveryParams,
|
|
16
|
+
AuthVerifyTwoFactorTokenParams,
|
|
17
|
+
TokenPayload,
|
|
18
|
+
TokenTwoFactorEnrollmentBeginEmailParams,
|
|
19
|
+
TokenTwoFactorEnrollmentBeginTotpParams,
|
|
20
|
+
TokenTwoFactorEnrollmentConfirmEmailParams,
|
|
21
|
+
TokenTwoFactorEnrollmentConfirmTotpParams,
|
|
22
|
+
TwoFactorChallengePayload,
|
|
23
|
+
TwoFactorEnrollmentConfirmationPayload,
|
|
24
|
+
TwoFactorTotpEnrollmentPayload
|
|
25
|
+
} from '../outsetaAPI.schemas';
|
|
26
|
+
|
|
27
|
+
import { customFetch } from '../../mutator';
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Post a JSON body with the user's credentials:
|
|
36
|
+
|
|
37
|
+
{ "username": "user@example.com", "password": "their-password" }
|
|
38
|
+
|
|
39
|
+
On success the response is `200` with an access token:
|
|
40
|
+
|
|
41
|
+
{ "access_token": "eyJ...", "token_type": "Bearer", "expires_in": 31536000 }
|
|
42
|
+
|
|
43
|
+
**Two-factor authentication.** If the user has a verified 2FA method,
|
|
44
|
+
the password alone is not enough. After verifying the password this
|
|
45
|
+
endpoint instead returns `202 Accepted` with a challenge that must be
|
|
46
|
+
satisfied via `POST /api/v1/tokens/two-factor`:
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
"two_factor_required": true,
|
|
50
|
+
"challenge_token": "eyJ...",
|
|
51
|
+
"mechanism": "Totp",
|
|
52
|
+
"masked_destination": "",
|
|
53
|
+
"expires_in": 600,
|
|
54
|
+
"available_mechanisms": ["Totp", "Email"],
|
|
55
|
+
"recovery_codes_available": true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
`mechanism` is the method this challenge targets. When it is `Email`,
|
|
59
|
+
a one-time code has already been emailed to the user (see
|
|
60
|
+
`masked_destination`); when it is `Totp`, the user reads the current
|
|
61
|
+
code from their authenticator app and nothing is sent.
|
|
62
|
+
`available_mechanisms` lists every method the user has enrolled so a
|
|
63
|
+
client can offer a switch via `POST /api/v1/tokens/two-factor/switch-mechanism`.
|
|
64
|
+
|
|
65
|
+
If the tenant forces 2FA but the user has not enrolled yet, the `202`
|
|
66
|
+
body instead contains `"two_factor_enrollment_required": true` with a
|
|
67
|
+
`challenge_token` to drive the mid-login enrollment endpoints.
|
|
68
|
+
|
|
69
|
+
Invalid credentials return `400` with a body of `invalid_grant`.
|
|
70
|
+
* @summary Log a user in and obtain a JWT access token.
|
|
71
|
+
*/
|
|
72
|
+
export const authGetToken = (
|
|
73
|
+
params: AuthGetTokenParams,
|
|
74
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
75
|
+
) => {
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
return customFetch<TokenPayload | TwoFactorChallengePayload>(
|
|
79
|
+
{url: `/api/v1/tokens`, method: 'POST',
|
|
80
|
+
params, signal
|
|
81
|
+
},
|
|
82
|
+
options);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
export const getAuthGetTokenMutationOptions = <TError = string,
|
|
88
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authGetToken>>, TError,{params: AuthGetTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
89
|
+
): UseMutationOptions<Awaited<ReturnType<typeof authGetToken>>, TError,{params: AuthGetTokenParams}, TContext> => {
|
|
90
|
+
|
|
91
|
+
const mutationKey = ['authGetToken'];
|
|
92
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
93
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
94
|
+
options
|
|
95
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
96
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof authGetToken>>, {params: AuthGetTokenParams}> = (props) => {
|
|
102
|
+
const {params} = props ?? {};
|
|
103
|
+
|
|
104
|
+
return authGetToken(params,requestOptions)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
return { mutationFn, ...mutationOptions }}
|
|
111
|
+
|
|
112
|
+
export type AuthGetTokenMutationResult = NonNullable<Awaited<ReturnType<typeof authGetToken>>>
|
|
113
|
+
|
|
114
|
+
export type AuthGetTokenMutationError = string
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @summary Log a user in and obtain a JWT access token.
|
|
118
|
+
*/
|
|
119
|
+
export const useAuthGetToken = <TError = string,
|
|
120
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authGetToken>>, TError,{params: AuthGetTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
121
|
+
): UseMutationResult<
|
|
122
|
+
Awaited<ReturnType<typeof authGetToken>>,
|
|
123
|
+
TError,
|
|
124
|
+
{params: AuthGetTokenParams},
|
|
125
|
+
TContext
|
|
126
|
+
> => {
|
|
127
|
+
|
|
128
|
+
const mutationOptions = getAuthGetTokenMutationOptions(options);
|
|
129
|
+
|
|
130
|
+
return useMutation(mutationOptions);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Call this after `POST /api/v1/tokens` returns `two_factor_required`.
|
|
134
|
+
Post the challenge token from that response together with the user's
|
|
135
|
+
one-time code (the emailed code, or the current code from their
|
|
136
|
+
authenticator app):
|
|
137
|
+
|
|
138
|
+
{ "challenge_token": "eyJ...", "code": "123456" }
|
|
139
|
+
|
|
140
|
+
On success the response is `200` with the final access token, in the
|
|
141
|
+
same shape as `POST /api/v1/tokens`:
|
|
142
|
+
|
|
143
|
+
{ "access_token": "eyJ...", "token_type": "Bearer", "expires_in": 31536000 }
|
|
144
|
+
|
|
145
|
+
An incorrect code returns `400` (`invalid_grant`). A code has at most
|
|
146
|
+
five attempts before the challenge locks. An expired challenge returns
|
|
147
|
+
`410` (`challenge_expired`) — restart at `POST /api/v1/tokens`. The
|
|
148
|
+
endpoint is rate limited to 10 requests per minute (`429`).
|
|
149
|
+
* @summary Complete a two-factor login challenge and obtain a JWT access token.
|
|
150
|
+
*/
|
|
151
|
+
export const authVerifyTwoFactorToken = (
|
|
152
|
+
params: AuthVerifyTwoFactorTokenParams,
|
|
153
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
154
|
+
) => {
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
return customFetch<TokenPayload>(
|
|
158
|
+
{url: `/api/v1/tokens/two-factor`, method: 'POST',
|
|
159
|
+
params, signal
|
|
160
|
+
},
|
|
161
|
+
options);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
export const getAuthVerifyTwoFactorTokenMutationOptions = <TError = string,
|
|
167
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, TError,{params: AuthVerifyTwoFactorTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
168
|
+
): UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, TError,{params: AuthVerifyTwoFactorTokenParams}, TContext> => {
|
|
169
|
+
|
|
170
|
+
const mutationKey = ['authVerifyTwoFactorToken'];
|
|
171
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
172
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
173
|
+
options
|
|
174
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
175
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, {params: AuthVerifyTwoFactorTokenParams}> = (props) => {
|
|
181
|
+
const {params} = props ?? {};
|
|
182
|
+
|
|
183
|
+
return authVerifyTwoFactorToken(params,requestOptions)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
return { mutationFn, ...mutationOptions }}
|
|
190
|
+
|
|
191
|
+
export type AuthVerifyTwoFactorTokenMutationResult = NonNullable<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>>
|
|
192
|
+
|
|
193
|
+
export type AuthVerifyTwoFactorTokenMutationError = string
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @summary Complete a two-factor login challenge and obtain a JWT access token.
|
|
197
|
+
*/
|
|
198
|
+
export const useAuthVerifyTwoFactorToken = <TError = string,
|
|
199
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, TError,{params: AuthVerifyTwoFactorTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
200
|
+
): UseMutationResult<
|
|
201
|
+
Awaited<ReturnType<typeof authVerifyTwoFactorToken>>,
|
|
202
|
+
TError,
|
|
203
|
+
{params: AuthVerifyTwoFactorTokenParams},
|
|
204
|
+
TContext
|
|
205
|
+
> => {
|
|
206
|
+
|
|
207
|
+
const mutationOptions = getAuthVerifyTwoFactorTokenMutationOptions(options);
|
|
208
|
+
|
|
209
|
+
return useMutation(mutationOptions);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Post the challenge token from the original `POST /api/v1/tokens` response:
|
|
213
|
+
|
|
214
|
+
{ "challenge_token": "eyJ..." }
|
|
215
|
+
|
|
216
|
+
A fresh code is emailed and a new challenge is returned (superseding
|
|
217
|
+
the previous one), in the same shape as the `202` from
|
|
218
|
+
`POST /api/v1/tokens` minus `two_factor_required`. Only `Email`
|
|
219
|
+
challenges can be resent — there is nothing to resend for `Totp`
|
|
220
|
+
(the authenticator app generates codes locally), so a `Totp`
|
|
221
|
+
challenge returns `400` with a body of `not_supported`. Rate limited
|
|
222
|
+
to 3 requests per minute (`429`).
|
|
223
|
+
* @summary Re-send the one-time code for an in-progress email two-factor challenge.
|
|
224
|
+
*/
|
|
225
|
+
export const authResendTwoFactor = (
|
|
226
|
+
params: AuthResendTwoFactorParams,
|
|
227
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
228
|
+
) => {
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
return customFetch<TwoFactorChallengePayload>(
|
|
232
|
+
{url: `/api/v1/tokens/two-factor/resend`, method: 'POST',
|
|
233
|
+
params, signal
|
|
234
|
+
},
|
|
235
|
+
options);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
export const getAuthResendTwoFactorMutationOptions = <TError = string,
|
|
241
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authResendTwoFactor>>, TError,{params: AuthResendTwoFactorParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
242
|
+
): UseMutationOptions<Awaited<ReturnType<typeof authResendTwoFactor>>, TError,{params: AuthResendTwoFactorParams}, TContext> => {
|
|
243
|
+
|
|
244
|
+
const mutationKey = ['authResendTwoFactor'];
|
|
245
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
246
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
247
|
+
options
|
|
248
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
249
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof authResendTwoFactor>>, {params: AuthResendTwoFactorParams}> = (props) => {
|
|
255
|
+
const {params} = props ?? {};
|
|
256
|
+
|
|
257
|
+
return authResendTwoFactor(params,requestOptions)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
return { mutationFn, ...mutationOptions }}
|
|
264
|
+
|
|
265
|
+
export type AuthResendTwoFactorMutationResult = NonNullable<Awaited<ReturnType<typeof authResendTwoFactor>>>
|
|
266
|
+
|
|
267
|
+
export type AuthResendTwoFactorMutationError = string
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @summary Re-send the one-time code for an in-progress email two-factor challenge.
|
|
271
|
+
*/
|
|
272
|
+
export const useAuthResendTwoFactor = <TError = string,
|
|
273
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authResendTwoFactor>>, TError,{params: AuthResendTwoFactorParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
274
|
+
): UseMutationResult<
|
|
275
|
+
Awaited<ReturnType<typeof authResendTwoFactor>>,
|
|
276
|
+
TError,
|
|
277
|
+
{params: AuthResendTwoFactorParams},
|
|
278
|
+
TContext
|
|
279
|
+
> => {
|
|
280
|
+
|
|
281
|
+
const mutationOptions = getAuthResendTwoFactorMutationOptions(options);
|
|
282
|
+
|
|
283
|
+
return useMutation(mutationOptions);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* When a user has more than one method enrolled (see
|
|
287
|
+
`available_mechanisms` on the login response) they can switch the
|
|
288
|
+
active challenge — for example from `Totp` to `Email` when they have
|
|
289
|
+
lost access to their authenticator. Post the current challenge token
|
|
290
|
+
and the desired mechanism:
|
|
291
|
+
|
|
292
|
+
{ "challenge_token": "eyJ...", "mechanism": "Email" }
|
|
293
|
+
|
|
294
|
+
A fresh challenge for that mechanism is returned (and, for `Email`, a
|
|
295
|
+
code is sent), in the same shape as the `202` from `POST /api/v1/tokens`
|
|
296
|
+
minus `two_factor_required`. An unrecognized mechanism returns `400`
|
|
297
|
+
(`invalid_mechanism`); a mechanism the user has not enrolled returns
|
|
298
|
+
`400` (`not_enrolled`). Rate limited to 5 requests per minute (`429`).
|
|
299
|
+
* @summary Switch an in-progress login challenge to a different enrolled mechanism.
|
|
300
|
+
*/
|
|
301
|
+
export const authSwitchTwoFactorMechanism = (
|
|
302
|
+
params: AuthSwitchTwoFactorMechanismParams,
|
|
303
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
304
|
+
) => {
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
return customFetch<TwoFactorChallengePayload>(
|
|
308
|
+
{url: `/api/v1/tokens/two-factor/switch-mechanism`, method: 'POST',
|
|
309
|
+
params, signal
|
|
310
|
+
},
|
|
311
|
+
options);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
export const getAuthSwitchTwoFactorMechanismMutationOptions = <TError = string,
|
|
317
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, TError,{params: AuthSwitchTwoFactorMechanismParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
318
|
+
): UseMutationOptions<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, TError,{params: AuthSwitchTwoFactorMechanismParams}, TContext> => {
|
|
319
|
+
|
|
320
|
+
const mutationKey = ['authSwitchTwoFactorMechanism'];
|
|
321
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
322
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
323
|
+
options
|
|
324
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
325
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, {params: AuthSwitchTwoFactorMechanismParams}> = (props) => {
|
|
331
|
+
const {params} = props ?? {};
|
|
332
|
+
|
|
333
|
+
return authSwitchTwoFactorMechanism(params,requestOptions)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
return { mutationFn, ...mutationOptions }}
|
|
340
|
+
|
|
341
|
+
export type AuthSwitchTwoFactorMechanismMutationResult = NonNullable<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>>
|
|
342
|
+
|
|
343
|
+
export type AuthSwitchTwoFactorMechanismMutationError = string
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* @summary Switch an in-progress login challenge to a different enrolled mechanism.
|
|
347
|
+
*/
|
|
348
|
+
export const useAuthSwitchTwoFactorMechanism = <TError = string,
|
|
349
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, TError,{params: AuthSwitchTwoFactorMechanismParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
350
|
+
): UseMutationResult<
|
|
351
|
+
Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>,
|
|
352
|
+
TError,
|
|
353
|
+
{params: AuthSwitchTwoFactorMechanismParams},
|
|
354
|
+
TContext
|
|
355
|
+
> => {
|
|
356
|
+
|
|
357
|
+
const mutationOptions = getAuthSwitchTwoFactorMechanismMutationOptions(options);
|
|
358
|
+
|
|
359
|
+
return useMutation(mutationOptions);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* A fallback for users who cannot produce their primary code but still
|
|
363
|
+
have a recovery code on file (see `recovery_codes_available` on the
|
|
364
|
+
login response). Post the challenge token together with one recovery
|
|
365
|
+
code:
|
|
366
|
+
|
|
367
|
+
{ "challenge_token": "eyJ...", "recovery_code": "abcd-efgh-ijkl" }
|
|
368
|
+
|
|
369
|
+
On success the response is `200` with the final access token, in the
|
|
370
|
+
same shape as `POST /api/v1/tokens`. Each recovery code is single-use.
|
|
371
|
+
An incorrect code returns `400` (`invalid_grant`); an expired
|
|
372
|
+
challenge returns `410` (`challenge_expired`). Rate limited to 10
|
|
373
|
+
requests per minute (`429`).
|
|
374
|
+
|
|
375
|
+
Used by the embed login widget; the hosted Razor flow has its own
|
|
376
|
+
equivalent action on the AuthenticationController.
|
|
377
|
+
* @summary Complete a two-factor login challenge with a recovery code instead of
|
|
378
|
+
the primary one-time code, and obtain a JWT access token.
|
|
379
|
+
*/
|
|
380
|
+
export const authVerifyTwoFactorRecovery = (
|
|
381
|
+
params: AuthVerifyTwoFactorRecoveryParams,
|
|
382
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
383
|
+
) => {
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
return customFetch<TokenPayload>(
|
|
387
|
+
{url: `/api/v1/tokens/two-factor/recovery`, method: 'POST',
|
|
388
|
+
params, signal
|
|
389
|
+
},
|
|
390
|
+
options);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
export const getAuthVerifyTwoFactorRecoveryMutationOptions = <TError = string,
|
|
396
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, TError,{params: AuthVerifyTwoFactorRecoveryParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
397
|
+
): UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, TError,{params: AuthVerifyTwoFactorRecoveryParams}, TContext> => {
|
|
398
|
+
|
|
399
|
+
const mutationKey = ['authVerifyTwoFactorRecovery'];
|
|
400
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
401
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
402
|
+
options
|
|
403
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
404
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, {params: AuthVerifyTwoFactorRecoveryParams}> = (props) => {
|
|
410
|
+
const {params} = props ?? {};
|
|
411
|
+
|
|
412
|
+
return authVerifyTwoFactorRecovery(params,requestOptions)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
return { mutationFn, ...mutationOptions }}
|
|
419
|
+
|
|
420
|
+
export type AuthVerifyTwoFactorRecoveryMutationResult = NonNullable<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>>
|
|
421
|
+
|
|
422
|
+
export type AuthVerifyTwoFactorRecoveryMutationError = string
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* @summary Complete a two-factor login challenge with a recovery code instead of
|
|
426
|
+
the primary one-time code, and obtain a JWT access token.
|
|
427
|
+
*/
|
|
428
|
+
export const useAuthVerifyTwoFactorRecovery = <TError = string,
|
|
429
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, TError,{params: AuthVerifyTwoFactorRecoveryParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
430
|
+
): UseMutationResult<
|
|
431
|
+
Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>,
|
|
432
|
+
TError,
|
|
433
|
+
{params: AuthVerifyTwoFactorRecoveryParams},
|
|
434
|
+
TContext
|
|
435
|
+
> => {
|
|
436
|
+
|
|
437
|
+
const mutationOptions = getAuthVerifyTwoFactorRecoveryMutationOptions(options);
|
|
438
|
+
|
|
439
|
+
return useMutation(mutationOptions);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Call this when `POST /api/v1/tokens` returned
|
|
443
|
+
`two_factor_enrollment_required` and the user chooses email. Post the
|
|
444
|
+
enrollment token from that response:
|
|
445
|
+
|
|
446
|
+
{ "enrollment_token": "eyJ..." }
|
|
447
|
+
|
|
448
|
+
A verification code is emailed to the user and a challenge is returned:
|
|
449
|
+
|
|
450
|
+
{
|
|
451
|
+
"challenge_token": "eyJ...",
|
|
452
|
+
"mechanism": "Email",
|
|
453
|
+
"masked_destination": "b***@outseta.com",
|
|
454
|
+
"expires_in": 600
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
Confirm the code via `POST /api/v1/tokens/two-factor/enroll/email/confirm`.
|
|
458
|
+
Returns `401` if the enrollment token is invalid/expired and `403` if
|
|
459
|
+
forced enrollment does not apply to this user. Rate limited to 5
|
|
460
|
+
requests per minute (`429`).
|
|
461
|
+
* @summary Begin email enrollment during a forced-2FA login.
|
|
462
|
+
*/
|
|
463
|
+
export const tokenTwoFactorEnrollmentBeginEmail = (
|
|
464
|
+
params: TokenTwoFactorEnrollmentBeginEmailParams,
|
|
465
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
466
|
+
) => {
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
return customFetch<TwoFactorChallengePayload>(
|
|
470
|
+
{url: `/api/v1/tokens/two-factor/enroll/email/begin`, method: 'POST',
|
|
471
|
+
params, signal
|
|
472
|
+
},
|
|
473
|
+
options);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
export const getTokenTwoFactorEnrollmentBeginEmailMutationOptions = <TError = string,
|
|
479
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, TError,{params: TokenTwoFactorEnrollmentBeginEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
480
|
+
): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, TError,{params: TokenTwoFactorEnrollmentBeginEmailParams}, TContext> => {
|
|
481
|
+
|
|
482
|
+
const mutationKey = ['tokenTwoFactorEnrollmentBeginEmail'];
|
|
483
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
484
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
485
|
+
options
|
|
486
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
487
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, {params: TokenTwoFactorEnrollmentBeginEmailParams}> = (props) => {
|
|
493
|
+
const {params} = props ?? {};
|
|
494
|
+
|
|
495
|
+
return tokenTwoFactorEnrollmentBeginEmail(params,requestOptions)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
return { mutationFn, ...mutationOptions }}
|
|
502
|
+
|
|
503
|
+
export type TokenTwoFactorEnrollmentBeginEmailMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>>
|
|
504
|
+
|
|
505
|
+
export type TokenTwoFactorEnrollmentBeginEmailMutationError = string
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @summary Begin email enrollment during a forced-2FA login.
|
|
509
|
+
*/
|
|
510
|
+
export const useTokenTwoFactorEnrollmentBeginEmail = <TError = string,
|
|
511
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, TError,{params: TokenTwoFactorEnrollmentBeginEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
512
|
+
): UseMutationResult<
|
|
513
|
+
Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>,
|
|
514
|
+
TError,
|
|
515
|
+
{params: TokenTwoFactorEnrollmentBeginEmailParams},
|
|
516
|
+
TContext
|
|
517
|
+
> => {
|
|
518
|
+
|
|
519
|
+
const mutationOptions = getTokenTwoFactorEnrollmentBeginEmailMutationOptions(options);
|
|
520
|
+
|
|
521
|
+
return useMutation(mutationOptions);
|
|
522
|
+
}
|
|
523
|
+
export const tokenTwoFactorEnrollmentBeginTotp = (
|
|
524
|
+
params: TokenTwoFactorEnrollmentBeginTotpParams,
|
|
525
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
526
|
+
) => {
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
return customFetch<TwoFactorTotpEnrollmentPayload>(
|
|
530
|
+
{url: `/api/v1/tokens/two-factor/enroll/totp/begin`, method: 'POST',
|
|
531
|
+
params, signal
|
|
532
|
+
},
|
|
533
|
+
options);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
export const getTokenTwoFactorEnrollmentBeginTotpMutationOptions = <TError = string,
|
|
539
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, TError,{params: TokenTwoFactorEnrollmentBeginTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
540
|
+
): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, TError,{params: TokenTwoFactorEnrollmentBeginTotpParams}, TContext> => {
|
|
541
|
+
|
|
542
|
+
const mutationKey = ['tokenTwoFactorEnrollmentBeginTotp'];
|
|
543
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
544
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
545
|
+
options
|
|
546
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
547
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, {params: TokenTwoFactorEnrollmentBeginTotpParams}> = (props) => {
|
|
553
|
+
const {params} = props ?? {};
|
|
554
|
+
|
|
555
|
+
return tokenTwoFactorEnrollmentBeginTotp(params,requestOptions)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
return { mutationFn, ...mutationOptions }}
|
|
562
|
+
|
|
563
|
+
export type TokenTwoFactorEnrollmentBeginTotpMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>>
|
|
564
|
+
|
|
565
|
+
export type TokenTwoFactorEnrollmentBeginTotpMutationError = string
|
|
566
|
+
|
|
567
|
+
export const useTokenTwoFactorEnrollmentBeginTotp = <TError = string,
|
|
568
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, TError,{params: TokenTwoFactorEnrollmentBeginTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
569
|
+
): UseMutationResult<
|
|
570
|
+
Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>,
|
|
571
|
+
TError,
|
|
572
|
+
{params: TokenTwoFactorEnrollmentBeginTotpParams},
|
|
573
|
+
TContext
|
|
574
|
+
> => {
|
|
575
|
+
|
|
576
|
+
const mutationOptions = getTokenTwoFactorEnrollmentBeginTotpMutationOptions(options);
|
|
577
|
+
|
|
578
|
+
return useMutation(mutationOptions);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Post the enrollment token (from `POST /api/v1/tokens`), the challenge
|
|
582
|
+
token (from `.../enroll/email/begin`), and the emailed code:
|
|
583
|
+
|
|
584
|
+
{ "enrollment_token": "eyJ...", "challenge_token": "eyJ...", "code": "123456" }
|
|
585
|
+
|
|
586
|
+
On success email 2FA is enabled and login completes — the response
|
|
587
|
+
carries the final access token plus the user's one-time recovery codes:
|
|
588
|
+
|
|
589
|
+
{
|
|
590
|
+
"confirmed": true,
|
|
591
|
+
"recovery_codes": ["abcd-efgh-ijkl", "..."],
|
|
592
|
+
"access_token": "eyJ...",
|
|
593
|
+
"token_type": "Bearer",
|
|
594
|
+
"expires_in": 31536000
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
Show the `recovery_codes` to the user once — they are not returned
|
|
598
|
+
again. An incorrect code returns `400` (`invalid_grant`); an expired
|
|
599
|
+
challenge returns `410` (`challenge_expired`). Rate limited to 10
|
|
600
|
+
requests per minute (`429`).
|
|
601
|
+
* @summary Confirm email enrollment and complete a forced-2FA login.
|
|
602
|
+
*/
|
|
603
|
+
export const tokenTwoFactorEnrollmentConfirmEmail = (
|
|
604
|
+
params: TokenTwoFactorEnrollmentConfirmEmailParams,
|
|
605
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
606
|
+
) => {
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
return customFetch<TwoFactorEnrollmentConfirmationPayload>(
|
|
610
|
+
{url: `/api/v1/tokens/two-factor/enroll/email/confirm`, method: 'POST',
|
|
611
|
+
params, signal
|
|
612
|
+
},
|
|
613
|
+
options);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
export const getTokenTwoFactorEnrollmentConfirmEmailMutationOptions = <TError = string,
|
|
619
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, TError,{params: TokenTwoFactorEnrollmentConfirmEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
620
|
+
): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, TError,{params: TokenTwoFactorEnrollmentConfirmEmailParams}, TContext> => {
|
|
621
|
+
|
|
622
|
+
const mutationKey = ['tokenTwoFactorEnrollmentConfirmEmail'];
|
|
623
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
624
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
625
|
+
options
|
|
626
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
627
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, {params: TokenTwoFactorEnrollmentConfirmEmailParams}> = (props) => {
|
|
633
|
+
const {params} = props ?? {};
|
|
634
|
+
|
|
635
|
+
return tokenTwoFactorEnrollmentConfirmEmail(params,requestOptions)
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
return { mutationFn, ...mutationOptions }}
|
|
642
|
+
|
|
643
|
+
export type TokenTwoFactorEnrollmentConfirmEmailMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>>
|
|
644
|
+
|
|
645
|
+
export type TokenTwoFactorEnrollmentConfirmEmailMutationError = string
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* @summary Confirm email enrollment and complete a forced-2FA login.
|
|
649
|
+
*/
|
|
650
|
+
export const useTokenTwoFactorEnrollmentConfirmEmail = <TError = string,
|
|
651
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, TError,{params: TokenTwoFactorEnrollmentConfirmEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
652
|
+
): UseMutationResult<
|
|
653
|
+
Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>,
|
|
654
|
+
TError,
|
|
655
|
+
{params: TokenTwoFactorEnrollmentConfirmEmailParams},
|
|
656
|
+
TContext
|
|
657
|
+
> => {
|
|
658
|
+
|
|
659
|
+
const mutationOptions = getTokenTwoFactorEnrollmentConfirmEmailMutationOptions(options);
|
|
660
|
+
|
|
661
|
+
return useMutation(mutationOptions);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Post the enrollment token (from `POST /api/v1/tokens`), the challenge
|
|
665
|
+
token (from `.../enroll/totp/begin`), and the current code from the
|
|
666
|
+
user's authenticator app:
|
|
667
|
+
|
|
668
|
+
{ "enrollment_token": "eyJ...", "challenge_token": "eyJ...", "code": "123456" }
|
|
669
|
+
|
|
670
|
+
On success authenticator-app 2FA is enabled and login completes — the
|
|
671
|
+
response carries the final access token plus the user's one-time
|
|
672
|
+
recovery codes:
|
|
673
|
+
|
|
674
|
+
{
|
|
675
|
+
"confirmed": true,
|
|
676
|
+
"recovery_codes": ["abcd-efgh-ijkl", "..."],
|
|
677
|
+
"access_token": "eyJ...",
|
|
678
|
+
"token_type": "Bearer",
|
|
679
|
+
"expires_in": 31536000
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
Show the `recovery_codes` to the user once — they are not returned
|
|
683
|
+
again. An incorrect code returns `400` (`invalid_grant`); an expired
|
|
684
|
+
challenge returns `410` (`challenge_expired`). Rate limited to 10
|
|
685
|
+
requests per minute (`429`).
|
|
686
|
+
* @summary Confirm authenticator-app (TOTP) enrollment and complete a forced-2FA login.
|
|
687
|
+
*/
|
|
688
|
+
export const tokenTwoFactorEnrollmentConfirmTotp = (
|
|
689
|
+
params: TokenTwoFactorEnrollmentConfirmTotpParams,
|
|
690
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
691
|
+
) => {
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
return customFetch<TwoFactorEnrollmentConfirmationPayload>(
|
|
695
|
+
{url: `/api/v1/tokens/two-factor/enroll/totp/confirm`, method: 'POST',
|
|
696
|
+
params, signal
|
|
697
|
+
},
|
|
698
|
+
options);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
export const getTokenTwoFactorEnrollmentConfirmTotpMutationOptions = <TError = string,
|
|
704
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, TError,{params: TokenTwoFactorEnrollmentConfirmTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
705
|
+
): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, TError,{params: TokenTwoFactorEnrollmentConfirmTotpParams}, TContext> => {
|
|
706
|
+
|
|
707
|
+
const mutationKey = ['tokenTwoFactorEnrollmentConfirmTotp'];
|
|
708
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
709
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
710
|
+
options
|
|
711
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
712
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, {params: TokenTwoFactorEnrollmentConfirmTotpParams}> = (props) => {
|
|
718
|
+
const {params} = props ?? {};
|
|
719
|
+
|
|
720
|
+
return tokenTwoFactorEnrollmentConfirmTotp(params,requestOptions)
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
return { mutationFn, ...mutationOptions }}
|
|
727
|
+
|
|
728
|
+
export type TokenTwoFactorEnrollmentConfirmTotpMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>>
|
|
729
|
+
|
|
730
|
+
export type TokenTwoFactorEnrollmentConfirmTotpMutationError = string
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @summary Confirm authenticator-app (TOTP) enrollment and complete a forced-2FA login.
|
|
734
|
+
*/
|
|
735
|
+
export const useTokenTwoFactorEnrollmentConfirmTotp = <TError = string,
|
|
736
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, TError,{params: TokenTwoFactorEnrollmentConfirmTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
737
|
+
): UseMutationResult<
|
|
738
|
+
Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>,
|
|
739
|
+
TError,
|
|
740
|
+
{params: TokenTwoFactorEnrollmentConfirmTotpParams},
|
|
741
|
+
TContext
|
|
742
|
+
> => {
|
|
743
|
+
|
|
744
|
+
const mutationOptions = getTokenTwoFactorEnrollmentConfirmTotpMutationOptions(options);
|
|
745
|
+
|
|
746
|
+
return useMutation(mutationOptions);
|
|
747
|
+
}
|
|
748
|
+
|