@draftlab/auth 0.15.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 +22 -23
- package/dist/core.mjs +3 -3
- 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/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/microsoft.d.mts +67 -68
- package/dist/provider/oauth2.d.mts +75 -76
- package/dist/provider/passkey.d.mts +20 -21
- package/dist/provider/password.d.mts +174 -202
- package/dist/provider/provider.d.mts +105 -107
- 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/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 +0 -1
- package/package.json +3 -3
package/dist/client.d.mts
CHANGED
|
@@ -3,7 +3,6 @@ import { SubjectSchema } from "./subject.mjs";
|
|
|
3
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
4
|
|
|
5
5
|
//#region src/client.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Result type for operations that can succeed or fail.
|
|
9
8
|
*
|
|
@@ -38,16 +37,16 @@ type FetchLike = (url: string, init?: RequestInit) => Promise<FetchResponse>;
|
|
|
38
37
|
*/
|
|
39
38
|
interface WellKnown {
|
|
40
39
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* URI to the JWKS endpoint for token verification.
|
|
41
|
+
*/
|
|
43
42
|
jwks_uri: string;
|
|
44
43
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
* URI to the token endpoint for authorization code exchange.
|
|
45
|
+
*/
|
|
47
46
|
token_endpoint: string;
|
|
48
47
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
* URI to the authorization endpoint for starting flows.
|
|
49
|
+
*/
|
|
51
50
|
authorization_endpoint: string;
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
@@ -55,16 +54,16 @@ interface WellKnown {
|
|
|
55
54
|
*/
|
|
56
55
|
interface Tokens {
|
|
57
56
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
* Access token for making authenticated API requests.
|
|
58
|
+
*/
|
|
60
59
|
access: string;
|
|
61
60
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
* Refresh token for obtaining new access tokens.
|
|
62
|
+
*/
|
|
64
63
|
refresh: string;
|
|
65
64
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
* Number of seconds until the access token expires.
|
|
66
|
+
*/
|
|
68
67
|
expiresIn: number;
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
@@ -72,12 +71,12 @@ interface Tokens {
|
|
|
72
71
|
*/
|
|
73
72
|
type Challenge = {
|
|
74
73
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
* State parameter for CSRF protection.
|
|
75
|
+
*/
|
|
77
76
|
state: string;
|
|
78
77
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
* PKCE code verifier for token exchange.
|
|
79
|
+
*/
|
|
81
80
|
verifier?: string;
|
|
82
81
|
};
|
|
83
82
|
/**
|
|
@@ -85,37 +84,37 @@ type Challenge = {
|
|
|
85
84
|
*/
|
|
86
85
|
interface ClientInput {
|
|
87
86
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
* Client ID that identifies your application.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* {
|
|
92
|
+
* clientID: "my-web-app"
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
97
96
|
clientID: string;
|
|
98
97
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
* Base URL of your Draft Auth server.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* {
|
|
103
|
+
* issuer: "https://auth.myserver.com"
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
108
107
|
issuer: string;
|
|
109
108
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
* Optionally, override the internally used fetch function.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* {
|
|
114
|
+
* fetch: customFetch
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
119
118
|
fetch?: FetchLike;
|
|
120
119
|
}
|
|
121
120
|
/**
|
|
@@ -123,32 +122,32 @@ interface ClientInput {
|
|
|
123
122
|
*/
|
|
124
123
|
interface AuthorizeOptions {
|
|
125
124
|
/**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
125
|
+
* Enable PKCE flow for enhanced security.
|
|
126
|
+
*
|
|
127
|
+
* Recommended for single-page applications and mobile apps.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* {
|
|
133
|
+
* pkce: true
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
138
137
|
pkce?: boolean;
|
|
139
138
|
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
139
|
+
* Specific authentication provider to use.
|
|
140
|
+
*
|
|
141
|
+
* If not specified, users see a provider selection screen
|
|
142
|
+
* or are redirected to the single configured provider.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* {
|
|
147
|
+
* provider: "google"
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
152
151
|
provider?: string;
|
|
153
152
|
}
|
|
154
153
|
/**
|
|
@@ -156,24 +155,24 @@ interface AuthorizeOptions {
|
|
|
156
155
|
*/
|
|
157
156
|
interface AuthorizeResult {
|
|
158
157
|
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
158
|
+
* Challenge data needed for PKCE flows.
|
|
159
|
+
*
|
|
160
|
+
* Store this securely and use when exchanging the code.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* sessionStorage.setItem("challenge", JSON.stringify(challenge))
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
168
167
|
challenge: Challenge;
|
|
169
168
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
* Authorization URL to redirect the user to.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* window.location.href = url
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
177
176
|
url: string;
|
|
178
177
|
}
|
|
179
178
|
/**
|
|
@@ -181,17 +180,17 @@ interface AuthorizeResult {
|
|
|
181
180
|
*/
|
|
182
181
|
interface RefreshOptions {
|
|
183
182
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
183
|
+
* Current access token to check before refreshing.
|
|
184
|
+
*
|
|
185
|
+
* Helps avoid unnecessary refresh requests.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* {
|
|
190
|
+
* access: currentAccessToken
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
195
194
|
access?: string;
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
@@ -199,34 +198,34 @@ interface RefreshOptions {
|
|
|
199
198
|
*/
|
|
200
199
|
interface VerifyOptions {
|
|
201
200
|
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
* Refresh token for automatic refresh if access token is expired.
|
|
202
|
+
*
|
|
203
|
+
* If passed in, this will automatically refresh the access token if it has expired.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* {
|
|
208
|
+
* refresh: refreshToken
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
213
212
|
refresh?: string;
|
|
214
213
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
* Expected issuer for validation.
|
|
215
|
+
* @internal
|
|
216
|
+
*/
|
|
218
217
|
issuer?: string;
|
|
219
218
|
/**
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
* Expected audience for validation.
|
|
220
|
+
* Defaults to clientID for security. Override only if you know what you're doing.
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
224
223
|
audience?: string;
|
|
225
224
|
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
* Custom fetch for HTTP requests.
|
|
226
|
+
*
|
|
227
|
+
* Optionally, override the internally used fetch function.
|
|
228
|
+
*/
|
|
230
229
|
fetch?: FetchLike;
|
|
231
230
|
}
|
|
232
231
|
/**
|
|
@@ -234,19 +233,26 @@ interface VerifyOptions {
|
|
|
234
233
|
*/
|
|
235
234
|
interface VerifyResult<T extends SubjectSchema> {
|
|
236
235
|
/**
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
* New tokens if access token was refreshed during verification.
|
|
237
|
+
*/
|
|
239
238
|
tokens?: Tokens;
|
|
240
239
|
/**
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
* Audience (client ID) the token was issued for.
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
244
243
|
aud: string;
|
|
245
244
|
/**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
* Unique subject identifier.
|
|
246
|
+
*
|
|
247
|
+
* This is a stable, consistent identifier derived from the subject type and properties.
|
|
248
|
+
* Format: `{type}:{hash}` (e.g., `user:30e16a2659c8bbb2`)
|
|
249
|
+
*/
|
|
250
|
+
sub: string;
|
|
251
|
+
/**
|
|
252
|
+
* Decoded subject information from the access token.
|
|
253
|
+
*
|
|
254
|
+
* Contains user data that was encoded when the token was issued.
|
|
255
|
+
*/
|
|
250
256
|
subject: { [K in keyof T]: {
|
|
251
257
|
type: K;
|
|
252
258
|
properties: StandardSchemaV1.InferOutput<T[K]>;
|
|
@@ -257,18 +263,18 @@ interface VerifyResult<T extends SubjectSchema> {
|
|
|
257
263
|
*/
|
|
258
264
|
interface RevokeOptions {
|
|
259
265
|
/**
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
266
|
+
* Optional hint about the token type.
|
|
267
|
+
* Can be "access_token" or "refresh_token".
|
|
268
|
+
*
|
|
269
|
+
* Helps the server optimize token lookup.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* {
|
|
274
|
+
* tokenTypeHint: "refresh_token"
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
272
278
|
tokenTypeHint?: "access_token" | "refresh_token";
|
|
273
279
|
}
|
|
274
280
|
/**
|
|
@@ -276,165 +282,165 @@ interface RevokeOptions {
|
|
|
276
282
|
*/
|
|
277
283
|
interface Client {
|
|
278
284
|
/**
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
285
|
+
* Start an OAuth authorization flow.
|
|
286
|
+
*
|
|
287
|
+
* @param redirectURI - Where users will be sent after authorization
|
|
288
|
+
* @param response - Response type ("code" or "token")
|
|
289
|
+
* @param opts - Additional authorization options
|
|
290
|
+
* @returns Authorization URL and challenge data
|
|
291
|
+
*
|
|
292
|
+
* @example Basic flow
|
|
293
|
+
* ```ts
|
|
294
|
+
* const result = await client.authorize(
|
|
295
|
+
* "https://myapp.com/callback",
|
|
296
|
+
* "code"
|
|
297
|
+
* )
|
|
298
|
+
* if (result.success) {
|
|
299
|
+
* window.location.href = result.data.url
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @example PKCE flow
|
|
304
|
+
* ```ts
|
|
305
|
+
* const result = await client.authorize(
|
|
306
|
+
* "https://spa.example.com/callback",
|
|
307
|
+
* "code",
|
|
308
|
+
* { pkce: true, scopes: ["read", "write"] }
|
|
309
|
+
* )
|
|
310
|
+
* if (result.success) {
|
|
311
|
+
* sessionStorage.setItem("challenge", JSON.stringify(result.data.challenge))
|
|
312
|
+
* window.location.href = result.data.url
|
|
313
|
+
* }
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
310
316
|
authorize(redirectURI: string, response: "code" | "token", opts?: AuthorizeOptions): Promise<Result<AuthorizeResult>>;
|
|
311
317
|
/**
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
318
|
+
* Exchange authorization code for tokens.
|
|
319
|
+
*
|
|
320
|
+
* @param code - Authorization code from the callback
|
|
321
|
+
* @param redirectURI - Same redirect URI used in authorization
|
|
322
|
+
* @param verifier - PKCE code verifier (required for PKCE flows)
|
|
323
|
+
* @returns Access tokens and metadata
|
|
324
|
+
*
|
|
325
|
+
* @example Basic exchange
|
|
326
|
+
* ```ts
|
|
327
|
+
* const urlParams = new URLSearchParams(window.location.search)
|
|
328
|
+
* const code = urlParams.get('code')
|
|
329
|
+
*
|
|
330
|
+
* if (code) {
|
|
331
|
+
* const result = await client.exchange(code, "https://myapp.com/callback")
|
|
332
|
+
* if (result.success) {
|
|
333
|
+
* const { access, refresh } = result.data
|
|
334
|
+
* // Store tokens securely
|
|
335
|
+
* }
|
|
336
|
+
* }
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @example PKCE exchange
|
|
340
|
+
* ```ts
|
|
341
|
+
* const challenge = JSON.parse(sessionStorage.getItem("challenge") || "{}")
|
|
342
|
+
* const code = new URLSearchParams(window.location.search).get('code')
|
|
343
|
+
*
|
|
344
|
+
* if (code && challenge.verifier) {
|
|
345
|
+
* const result = await client.exchange(
|
|
346
|
+
* code,
|
|
347
|
+
* "https://spa.example.com/callback",
|
|
348
|
+
* challenge.verifier
|
|
349
|
+
* )
|
|
350
|
+
* if (result.success) {
|
|
351
|
+
* sessionStorage.removeItem("challenge")
|
|
352
|
+
* // Handle tokens
|
|
353
|
+
* }
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
351
357
|
exchange(code: string, redirectURI: string, verifier?: string): Promise<Result<Tokens, InvalidAuthorizationCodeError>>;
|
|
352
358
|
/**
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
359
|
+
* Refresh an access token using a refresh token.
|
|
360
|
+
*
|
|
361
|
+
* @param refresh - Refresh token to use
|
|
362
|
+
* @param opts - Additional refresh options
|
|
363
|
+
* @returns New tokens if refresh was needed
|
|
364
|
+
*
|
|
365
|
+
* @example Basic refresh
|
|
366
|
+
* ```ts
|
|
367
|
+
* const result = await client.refresh(storedRefreshToken)
|
|
368
|
+
*
|
|
369
|
+
* if (result.success && result.data.tokens) {
|
|
370
|
+
* const { access, refresh: newRefresh } = result.data.tokens
|
|
371
|
+
* updateStoredTokens(access, newRefresh)
|
|
372
|
+
* } else if (result.success) {
|
|
373
|
+
* // Token still valid
|
|
374
|
+
* } else {
|
|
375
|
+
* redirectToLogin()
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
373
379
|
refresh(refresh: string, opts?: RefreshOptions): Promise<Result<{
|
|
374
380
|
tokens?: Tokens;
|
|
375
381
|
}, InvalidRefreshTokenError | InvalidAccessTokenError>>;
|
|
376
382
|
/**
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
383
|
+
* Verify and decode an access token.
|
|
384
|
+
*
|
|
385
|
+
* @param subjects - Subject schema used when creating the issuer
|
|
386
|
+
* @param token - Access token to verify
|
|
387
|
+
* @param options - Additional verification options
|
|
388
|
+
* @returns Decoded token data and user information
|
|
389
|
+
*
|
|
390
|
+
* @example Basic verification
|
|
391
|
+
* ```ts
|
|
392
|
+
* const result = await client.verify(subjects, accessToken)
|
|
393
|
+
*
|
|
394
|
+
* if (result.success) {
|
|
395
|
+
* const { subject, scopes } = result.data
|
|
396
|
+
* // Access user ID: subject.properties.userID
|
|
397
|
+
* // Access scopes: scopes?.join(', ')
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example With automatic refresh
|
|
402
|
+
* ```ts
|
|
403
|
+
* const result = await client.verify(subjects, accessToken, {
|
|
404
|
+
* refresh: refreshToken
|
|
405
|
+
* })
|
|
406
|
+
*
|
|
407
|
+
* if (result.success) {
|
|
408
|
+
* if (result.data.tokens) {
|
|
409
|
+
* // Tokens were refreshed
|
|
410
|
+
* updateStoredTokens(result.data.tokens.access, result.data.tokens.refresh)
|
|
411
|
+
* }
|
|
412
|
+
* // Use verified subject data
|
|
413
|
+
* const user = result.data.subject.properties
|
|
414
|
+
* }
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
411
417
|
verify<T extends SubjectSchema>(subjects: T, token: string, options?: VerifyOptions): Promise<Result<VerifyResult<T>, InvalidRefreshTokenError | InvalidAccessTokenError | InvalidSubjectError>>;
|
|
412
418
|
/**
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
419
|
+
* Revoke a token (access or refresh token).
|
|
420
|
+
*
|
|
421
|
+
* Once revoked, the token cannot be used to access resources or refresh.
|
|
422
|
+
* Useful for implementing logout functionality.
|
|
423
|
+
*
|
|
424
|
+
* @param token - The token to revoke
|
|
425
|
+
* @param opts - Additional revocation options
|
|
426
|
+
* @returns Empty result on success
|
|
427
|
+
*
|
|
428
|
+
* @example Logout with refresh token revocation
|
|
429
|
+
* ```ts
|
|
430
|
+
* const result = await client.revoke(refreshToken, {
|
|
431
|
+
* tokenTypeHint: "refresh_token"
|
|
432
|
+
* })
|
|
433
|
+
*
|
|
434
|
+
* if (result.success) {
|
|
435
|
+
* // Token revoked successfully, user is logged out
|
|
436
|
+
* clearStoredTokens()
|
|
437
|
+
* redirectToHome()
|
|
438
|
+
* } else {
|
|
439
|
+
* // Revocation failed, but still clear tokens on client
|
|
440
|
+
* clearStoredTokens()
|
|
441
|
+
* }
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
438
444
|
revoke(token: string, opts?: RevokeOptions): Promise<Result<void>>;
|
|
439
445
|
}
|
|
440
446
|
/**
|