@draftlab/auth 0.14.0 → 0.15.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/dist/adapters/node.d.mts +0 -1
- package/dist/client.d.mts +293 -287
- package/dist/client.mjs +1 -0
- package/dist/core.d.mts +23 -24
- package/dist/core.mjs +6 -6
- package/dist/error.d.mts +53 -53
- package/dist/keys.d.mts +0 -1
- package/dist/mutex.d.mts +14 -14
- package/dist/provider/apple.d.mts +34 -35
- package/dist/provider/code.d.mts +75 -85
- package/dist/provider/code.mjs +83 -0
- package/dist/provider/discord.d.mts +49 -50
- package/dist/provider/facebook.d.mts +49 -50
- package/dist/provider/github.d.mts +50 -51
- package/dist/provider/gitlab.d.mts +34 -35
- package/dist/provider/google.d.mts +49 -50
- package/dist/provider/linkedin.d.mts +47 -48
- package/dist/provider/magiclink.d.mts +28 -38
- package/dist/provider/magiclink.mjs +57 -0
- package/dist/provider/microsoft.d.mts +67 -68
- package/dist/provider/oauth2.d.mts +75 -76
- package/dist/provider/oauth2.mjs +57 -0
- package/dist/provider/passkey.d.mts +20 -21
- package/dist/provider/password.d.mts +174 -202
- package/dist/provider/provider.d.mts +107 -109
- package/dist/provider/reddit.d.mts +33 -34
- package/dist/provider/slack.d.mts +34 -35
- package/dist/provider/spotify.d.mts +34 -35
- package/dist/provider/totp.d.mts +43 -44
- package/dist/provider/twitch.d.mts +33 -34
- package/dist/provider/vercel.d.mts +65 -66
- package/dist/revocation.d.mts +29 -30
- package/dist/router/context.d.mts +21 -0
- package/dist/router/context.mjs +193 -0
- package/dist/router/cookies.d.mts +8 -0
- package/dist/router/cookies.mjs +13 -0
- package/dist/router/index.d.mts +21 -0
- package/dist/router/index.mjs +107 -0
- package/dist/router/matcher.d.mts +15 -0
- package/dist/router/matcher.mjs +76 -0
- package/dist/router/middleware/cors.d.mts +15 -0
- package/dist/router/middleware/cors.mjs +114 -0
- package/dist/router/safe-request.d.mts +52 -0
- package/dist/router/safe-request.mjs +160 -0
- package/dist/router/types.d.mts +67 -0
- package/dist/router/types.mjs +1 -0
- package/dist/router/variables.d.mts +12 -0
- package/dist/router/variables.mjs +20 -0
- package/dist/storage/memory.d.mts +11 -12
- package/dist/storage/storage.d.mts +110 -110
- package/dist/storage/turso.d.mts +0 -1
- package/dist/storage/unstorage.d.mts +0 -1
- package/dist/subject.d.mts +0 -1
- package/dist/themes/theme.d.mts +101 -101
- package/dist/toolkit/client.d.mts +56 -57
- package/dist/toolkit/providers/facebook.d.mts +0 -1
- package/dist/toolkit/providers/github.d.mts +0 -1
- package/dist/toolkit/providers/google.d.mts +0 -1
- package/dist/toolkit/storage.d.mts +8 -8
- package/dist/ui/base.d.mts +0 -1
- package/dist/ui/code.d.mts +5 -6
- package/dist/ui/form.d.mts +6 -7
- package/dist/ui/icon.d.mts +0 -1
- package/dist/ui/magiclink.d.mts +5 -6
- package/dist/ui/passkey.d.mts +0 -1
- package/dist/ui/password.d.mts +2 -3
- package/dist/ui/select.d.mts +0 -1
- package/dist/ui/totp.d.mts +0 -1
- package/dist/util.d.mts +1 -2
- package/package.json +6 -7
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { RouterContext } from "../router/types.mjs";
|
|
2
|
+
import { Router } from "../router/index.mjs";
|
|
1
3
|
import { StorageAdapter } from "../storage/storage.mjs";
|
|
2
|
-
import { Router } from "@draftlab/auth-router";
|
|
3
|
-
import { RouterContext } from "@draftlab/auth-router/types";
|
|
4
4
|
|
|
5
5
|
//#region src/provider/provider.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* OAuth provider system for Draft Auth.
|
|
9
8
|
* Defines the interfaces and utilities for implementing authentication providers
|
|
@@ -54,35 +53,35 @@ type ProviderRoute = Router;
|
|
|
54
53
|
*/
|
|
55
54
|
interface Provider<Properties = Record<string, unknown>> {
|
|
56
55
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
* Unique identifier for this provider type.
|
|
57
|
+
* Used in URLs and provider selection UI.
|
|
58
|
+
*
|
|
59
|
+
* @example "github", "google", "steam"
|
|
60
|
+
*/
|
|
62
61
|
readonly type: string;
|
|
63
62
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
* Initializes the provider by registering required routes.
|
|
64
|
+
* Called during issuer setup to configure authorization and callback endpoints.
|
|
65
|
+
*
|
|
66
|
+
* @param route - Router instance for registering provider endpoints
|
|
67
|
+
* @param options - Provider utilities and configuration
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* init(routes, ctx) {
|
|
72
|
+
* routes.get("/authorize", async (c) => {
|
|
73
|
+
* // Redirect to OAuth provider
|
|
74
|
+
* return c.redirect(buildAuthUrl())
|
|
75
|
+
* })
|
|
76
|
+
*
|
|
77
|
+
* routes.get("/callback", async (c) => {
|
|
78
|
+
* // Process callback and return user data
|
|
79
|
+
* const userData = await handleCallback(c)
|
|
80
|
+
* return await ctx.success(c, userData)
|
|
81
|
+
* })
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
86
85
|
init: (route: ProviderRoute, options: ProviderOptions<Properties>) => void;
|
|
87
86
|
}
|
|
88
87
|
/**
|
|
@@ -93,100 +92,99 @@ interface Provider<Properties = Record<string, unknown>> {
|
|
|
93
92
|
*/
|
|
94
93
|
interface ProviderOptions<Properties> {
|
|
95
94
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
* Name of the provider instance as configured in the issuer.
|
|
96
|
+
* Corresponds to the key used in the providers object.
|
|
97
|
+
*/
|
|
99
98
|
readonly name: string;
|
|
100
99
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
* Completes the authentication flow with user data.
|
|
101
|
+
* Called when the provider successfully authenticates a user.
|
|
102
|
+
*
|
|
103
|
+
* @param ctx - Router request context
|
|
104
|
+
* @param properties - User data extracted from the provider
|
|
105
|
+
* @param opts - Optional utilities for session management
|
|
106
|
+
* @returns Response that completes the OAuth flow
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const userData = { userId: "123", email: "user@example.com" }
|
|
111
|
+
* return await ctx.success(c, userData)
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
115
114
|
success: (ctx: RouterContext, properties: Properties, opts?: {
|
|
116
|
-
/** Function to invalidate existing user sessions */
|
|
117
|
-
readonly invalidate?: (subject: string) => Promise<void>;
|
|
115
|
+
/** Function to invalidate existing user sessions */readonly invalidate?: (subject: string) => Promise<void>;
|
|
118
116
|
}) => Promise<Response>;
|
|
119
117
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
* Forwards a response through the provider context.
|
|
119
|
+
* Used for redirects and custom responses within the OAuth flow.
|
|
120
|
+
*
|
|
121
|
+
* @param ctx - Router request context
|
|
122
|
+
* @param response - Response to forward
|
|
123
|
+
* @returns Forwarded response
|
|
124
|
+
*/
|
|
127
125
|
forward: (ctx: RouterContext, response: Response) => Response;
|
|
128
126
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
127
|
+
* Stores a temporary value with expiration for the current session.
|
|
128
|
+
* Useful for storing OAuth state, PKCE verifiers, and other temporary data.
|
|
129
|
+
*
|
|
130
|
+
* @param ctx - Router request context
|
|
131
|
+
* @param key - Storage key identifier
|
|
132
|
+
* @param maxAge - TTL in seconds
|
|
133
|
+
* @param value - Value to store
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* // Store OAuth state for 10 minutes
|
|
138
|
+
* await ctx.set(c, "oauth_state", 600, { state, redirectUri })
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
143
141
|
set: <T>(ctx: RouterContext, key: string, maxAge: number, value: T) => Promise<void>;
|
|
144
142
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
143
|
+
* Retrieves a previously stored temporary value.
|
|
144
|
+
*
|
|
145
|
+
* @param ctx - Router request context
|
|
146
|
+
* @param key - Storage key identifier
|
|
147
|
+
* @returns Promise resolving to the stored value or undefined if not found/expired
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const oauthState = await ctx.get<OAuthState>(c, "oauth_state")
|
|
152
|
+
* if (!oauthState) {
|
|
153
|
+
* throw new Error("OAuth state expired")
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
159
157
|
get: <T>(ctx: RouterContext, key: string) => Promise<T | undefined>;
|
|
160
158
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
159
|
+
* Removes a stored temporary value.
|
|
160
|
+
*
|
|
161
|
+
* @param ctx - Router request context
|
|
162
|
+
* @param key - Storage key identifier
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* // Clean up OAuth state after use
|
|
167
|
+
* await ctx.unset(c, "oauth_state")
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
172
170
|
unset: (ctx: RouterContext, key: string) => Promise<void>;
|
|
173
171
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
172
|
+
* Invalidates all sessions for a given subject (user).
|
|
173
|
+
* Forces logout across all devices and applications.
|
|
174
|
+
*
|
|
175
|
+
* @param subject - Subject identifier to invalidate
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* // Force logout on password change
|
|
180
|
+
* await ctx.invalidate(userId)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
185
183
|
invalidate: (subject: string) => Promise<void>;
|
|
186
184
|
/**
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
* Storage adapter for persistent data operations.
|
|
186
|
+
* Provides access to the configured storage backend.
|
|
187
|
+
*/
|
|
190
188
|
readonly storage: StorageAdapter;
|
|
191
189
|
}
|
|
192
190
|
/**
|
|
@@ -2,50 +2,49 @@ import { Provider } from "./provider.mjs";
|
|
|
2
2
|
import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/provider/reddit.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Configuration options for Reddit OAuth 2.0 provider.
|
|
8
7
|
* Extends the base OAuth 2.0 configuration with Reddit-specific documentation.
|
|
9
8
|
*/
|
|
10
9
|
interface RedditConfig extends Oauth2WrappedConfig {
|
|
11
10
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
* Reddit app client ID.
|
|
12
|
+
* Get this from your Reddit application preferences at https://www.reddit.com/prefs/apps
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* {
|
|
17
|
+
* clientID: "abcdef123456"
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
22
21
|
readonly clientID: string;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
* Reddit app client secret.
|
|
24
|
+
* Keep this secure and never expose it to client-side code.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* {
|
|
29
|
+
* clientSecret: process.env.REDDIT_CLIENT_SECRET
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
34
33
|
readonly clientSecret: string;
|
|
35
34
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
* Reddit OAuth scopes to request access for.
|
|
36
|
+
* Determines what data and actions your app can access.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* {
|
|
41
|
+
* scopes: [
|
|
42
|
+
* "identity", // Access user identity
|
|
43
|
+
* "read" // Read private data
|
|
44
|
+
* ]
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
49
48
|
readonly scopes: string[];
|
|
50
49
|
}
|
|
51
50
|
/**
|
|
@@ -2,51 +2,50 @@ import { Provider } from "./provider.mjs";
|
|
|
2
2
|
import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/provider/slack.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Configuration options for Slack OAuth 2.0 provider.
|
|
8
7
|
* Extends the base OAuth 2.0 configuration with Slack-specific documentation.
|
|
9
8
|
*/
|
|
10
9
|
interface SlackConfig extends Oauth2WrappedConfig {
|
|
11
10
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
* Slack app client ID.
|
|
12
|
+
* Get this from your Slack App settings at https://api.slack.com/apps
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* {
|
|
17
|
+
* clientID: "123456789.1234567890"
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
22
21
|
readonly clientID: string;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
* Slack app client secret.
|
|
24
|
+
* Keep this secure and never expose it to client-side code.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* {
|
|
29
|
+
* clientSecret: process.env.SLACK_CLIENT_SECRET
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
34
33
|
readonly clientSecret: string;
|
|
35
34
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
* Slack OAuth scopes to request access for.
|
|
36
|
+
* Determines what data and actions your app can access.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* {
|
|
41
|
+
* scopes: [
|
|
42
|
+
* "users:read", // Access to user profiles
|
|
43
|
+
* "users:read.email", // Access user emails
|
|
44
|
+
* "team:read" // Access team information
|
|
45
|
+
* ]
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
50
49
|
readonly scopes: string[];
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
@@ -2,51 +2,50 @@ import { Provider } from "./provider.mjs";
|
|
|
2
2
|
import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/provider/spotify.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Configuration options for Spotify OAuth 2.0 provider.
|
|
8
7
|
* Extends the base OAuth 2.0 configuration with Spotify-specific documentation.
|
|
9
8
|
*/
|
|
10
9
|
interface SpotifyConfig extends Oauth2WrappedConfig {
|
|
11
10
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
* Spotify app client ID.
|
|
12
|
+
* Get this from your Spotify App at https://developer.spotify.com/dashboard
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* {
|
|
17
|
+
* clientID: "abcdef123456"
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
22
21
|
readonly clientID: string;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
* Spotify app client secret.
|
|
24
|
+
* Keep this secure and never expose it to client-side code.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* {
|
|
29
|
+
* clientSecret: process.env.SPOTIFY_CLIENT_SECRET
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
34
33
|
readonly clientSecret: string;
|
|
35
34
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
* Spotify OAuth scopes to request access for.
|
|
36
|
+
* Determines what data and actions your app can access.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* {
|
|
41
|
+
* scopes: [
|
|
42
|
+
* "user-read-private", // Access private user data
|
|
43
|
+
* "user-read-email", // Access user email
|
|
44
|
+
* "user-top-read" // Read top artists and tracks
|
|
45
|
+
* ]
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
50
49
|
readonly scopes: string[];
|
|
51
50
|
}
|
|
52
51
|
/**
|
package/dist/provider/totp.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Provider } from "./provider.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/provider/totp.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* TOTP data model stored in the database.
|
|
7
6
|
* Contains the user's TOTP configuration and backup codes.
|
|
@@ -24,69 +23,69 @@ interface TOTPModel {
|
|
|
24
23
|
*/
|
|
25
24
|
interface TOTPProviderConfig {
|
|
26
25
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
* The human-readable name of the issuer (your application).
|
|
27
|
+
* This appears in authenticator apps next to the TOTP entry.
|
|
28
|
+
*/
|
|
30
29
|
issuer: string;
|
|
31
30
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
* Custom authorize handler that generates the UI for TOTP login.
|
|
32
|
+
* Called when user wants to login with TOTP (main page).
|
|
33
|
+
*
|
|
34
|
+
* @param req - The HTTP request object
|
|
35
|
+
* @param error - Optional error message to display
|
|
36
|
+
*/
|
|
38
37
|
authorize: (req: Request, error?: string) => Promise<Response>;
|
|
39
38
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
* Custom register handler that generates the UI for TOTP setup.
|
|
40
|
+
* Called when user is setting up TOTP for the first time.
|
|
41
|
+
*
|
|
42
|
+
* @param req - The HTTP request object
|
|
43
|
+
* @param qrCodeUrl - The otpauth:// URL for QR code generation
|
|
44
|
+
* @param secret - The raw secret (for manual entry)
|
|
45
|
+
* @param backupCodes - Array of backup/recovery codes
|
|
46
|
+
* @param error - Optional error message to display
|
|
47
|
+
*/
|
|
49
48
|
register: (req: Request, qrCodeUrl: string, secret: string, backupCodes: string[], error?: string, email?: string) => Promise<Response>;
|
|
50
49
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
* Custom recovery handler that generates the UI for backup code entry.
|
|
51
|
+
* Called when user wants to use a recovery code instead of TOTP.
|
|
52
|
+
*
|
|
53
|
+
* @param req - The HTTP request object
|
|
54
|
+
* @param error - Optional error message to display
|
|
55
|
+
*/
|
|
57
56
|
recovery: (req: Request, error?: string) => Promise<Response>;
|
|
58
57
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
* Optional TOTP algorithm. Defaults to SHA1 for maximum compatibility.
|
|
59
|
+
* Most authenticator apps support SHA1, fewer support SHA256/SHA512.
|
|
60
|
+
*/
|
|
62
61
|
algorithm?: "SHA1" | "SHA256" | "SHA512";
|
|
63
62
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
* Optional number of digits in TOTP codes. Defaults to 6.
|
|
64
|
+
* Some apps support 8 digits for increased security.
|
|
65
|
+
*/
|
|
67
66
|
digits?: 6 | 8;
|
|
68
67
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
* Optional validity period for TOTP codes in seconds. Defaults to 30.
|
|
69
|
+
* Standard is 30 seconds, some high-security apps use 60.
|
|
70
|
+
*/
|
|
72
71
|
period?: number;
|
|
73
72
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
* Optional time window tolerance for clock drift. Defaults to 1.
|
|
74
|
+
* Allows tokens from previous/next time window to be valid.
|
|
75
|
+
*/
|
|
77
76
|
window?: number;
|
|
78
77
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
* Optional number of backup codes to generate. Defaults to 10.
|
|
79
|
+
*/
|
|
81
80
|
backupCodesCount?: number;
|
|
82
81
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
* Optional function to check if a user is allowed to set up TOTP.
|
|
83
|
+
*/
|
|
85
84
|
userCanSetupTOTP?: (userId: string, req: Request) => Promise<boolean>;
|
|
86
85
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
* Optional custom label generator for TOTP entries.
|
|
87
|
+
* Defaults to using the userId as the label.
|
|
88
|
+
*/
|
|
90
89
|
generateLabel?: (userId: string) => Promise<string>;
|
|
91
90
|
}
|
|
92
91
|
/**
|