@better-auth/oauth-provider 1.7.0-beta.3 → 1.7.0-beta.5
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/{client-assertion-BYtMWGCE.mjs → client-assertion-DmT1B6_6.mjs} +42 -51
- package/dist/client-resource.d.mts +27 -6
- package/dist/client-resource.mjs +2 -2
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -1
- package/dist/index.d.mts +9 -6
- package/dist/index.mjs +893 -388
- package/dist/{oauth-Ds-ejTJY.d.mts → oauth-BXrYl5x6.d.mts} +129 -7
- package/dist/{oauth-BxP4Iupj.d.mts → oauth-DU6NeviY.d.mts} +171 -52
- package/dist/{utils-_Jr_enAe.mjs → utils-D2dLqo7f.mjs} +86 -17
- package/dist/{version-CG1YnCiF.mjs → version-B1ZiRmxj.mjs} +1 -1
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrivateKeyJwtSigningAlgorithm } from "@better-auth/core/oauth2";
|
|
2
2
|
import { JWSAlgorithms } from "better-auth/plugins";
|
|
3
3
|
import { JWTPayload } from "jose";
|
|
4
4
|
import { InferOptionSchema, Session, User } from "better-auth/types";
|
|
@@ -100,6 +100,14 @@ declare const schema: {
|
|
|
100
100
|
type: "string[]";
|
|
101
101
|
required: false;
|
|
102
102
|
};
|
|
103
|
+
backchannelLogoutUri: {
|
|
104
|
+
type: "string";
|
|
105
|
+
required: false;
|
|
106
|
+
};
|
|
107
|
+
backchannelLogoutSessionRequired: {
|
|
108
|
+
type: "boolean";
|
|
109
|
+
required: false;
|
|
110
|
+
};
|
|
103
111
|
tokenEndpointAuthMethod: {
|
|
104
112
|
type: "string";
|
|
105
113
|
required: false;
|
|
@@ -152,6 +160,7 @@ declare const schema: {
|
|
|
152
160
|
token: {
|
|
153
161
|
type: "string";
|
|
154
162
|
required: true;
|
|
163
|
+
unique: true;
|
|
155
164
|
};
|
|
156
165
|
clientId: {
|
|
157
166
|
type: "string";
|
|
@@ -185,6 +194,10 @@ declare const schema: {
|
|
|
185
194
|
type: "string";
|
|
186
195
|
required: false;
|
|
187
196
|
};
|
|
197
|
+
resources: {
|
|
198
|
+
type: "string[]";
|
|
199
|
+
required: false;
|
|
200
|
+
};
|
|
188
201
|
expiresAt: {
|
|
189
202
|
type: "date";
|
|
190
203
|
};
|
|
@@ -256,6 +269,10 @@ declare const schema: {
|
|
|
256
269
|
type: "string";
|
|
257
270
|
required: false;
|
|
258
271
|
};
|
|
272
|
+
resources: {
|
|
273
|
+
type: "string[]";
|
|
274
|
+
required: false;
|
|
275
|
+
};
|
|
259
276
|
refreshId: {
|
|
260
277
|
type: "string";
|
|
261
278
|
required: false;
|
|
@@ -271,6 +288,10 @@ declare const schema: {
|
|
|
271
288
|
createdAt: {
|
|
272
289
|
type: "date";
|
|
273
290
|
};
|
|
291
|
+
revoked: {
|
|
292
|
+
type: "date";
|
|
293
|
+
required: false;
|
|
294
|
+
};
|
|
274
295
|
scopes: {
|
|
275
296
|
type: "string[]";
|
|
276
297
|
required: true;
|
|
@@ -302,6 +323,10 @@ declare const schema: {
|
|
|
302
323
|
type: "string";
|
|
303
324
|
required: false;
|
|
304
325
|
};
|
|
326
|
+
resources: {
|
|
327
|
+
type: "string[]";
|
|
328
|
+
required: false;
|
|
329
|
+
};
|
|
305
330
|
scopes: {
|
|
306
331
|
type: "string[]";
|
|
307
332
|
required: true;
|
|
@@ -314,6 +339,27 @@ declare const schema: {
|
|
|
314
339
|
};
|
|
315
340
|
};
|
|
316
341
|
};
|
|
342
|
+
/**
|
|
343
|
+
* Single-use record for `private_key_jwt` client assertion `jti` values. The
|
|
344
|
+
* row id is a digest of the per-client assertion identifier, so a replayed or
|
|
345
|
+
* concurrent assertion collides on the primary key and the insert fails
|
|
346
|
+
* atomically on every adapter (SQL primary key, MongoDB `_id`), including
|
|
347
|
+
* across multiple server processes.
|
|
348
|
+
*
|
|
349
|
+
* A row keeps blocking its id until deleted; `expiresAt` marks when removal
|
|
350
|
+
* is safe, since the assertion it guards has expired and is rejected earlier.
|
|
351
|
+
* TODO: no scheduled job prunes expired rows yet; like the verification
|
|
352
|
+
* table, they accumulate until a deployment-level sweep removes them.
|
|
353
|
+
*/
|
|
354
|
+
oauthClientAssertion: {
|
|
355
|
+
modelName: string;
|
|
356
|
+
fields: {
|
|
357
|
+
expiresAt: {
|
|
358
|
+
type: "date";
|
|
359
|
+
required: true;
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
};
|
|
317
363
|
};
|
|
318
364
|
//#endregion
|
|
319
365
|
//#region src/types/helpers.d.ts
|
|
@@ -832,8 +878,8 @@ interface OAuthOptions<Scopes extends readonly Scope[] = InternallySupportedScop
|
|
|
832
878
|
customAccessTokenClaims?: (info: {
|
|
833
879
|
/** The user object if token is associated to a user. Null if user doesn't exist. Undefined if user not applicable. */user?: (User & Record<string, unknown>) | null; /** reference of the consent/authorization */
|
|
834
880
|
referenceId?: string; /** Scopes granted for this token */
|
|
835
|
-
scopes: Scopes; /** The
|
|
836
|
-
|
|
881
|
+
scopes: Scopes; /** The resources requested. */
|
|
882
|
+
resources?: string[]; /** oAuthClient metadata */
|
|
837
883
|
metadata?: Record<string, any>;
|
|
838
884
|
}) => Awaitable<Record<string, any>>;
|
|
839
885
|
/**
|
|
@@ -1191,6 +1237,10 @@ interface OAuthAuthorizationQuery {
|
|
|
1191
1237
|
* with the Claim Value being the nonce value sent in the Authentication Request.
|
|
1192
1238
|
*/
|
|
1193
1239
|
nonce?: string;
|
|
1240
|
+
/**
|
|
1241
|
+
* Resource parameter as specified by [RFC 8707](https://www.rfc-editor.org/rfc/rfc8707.html)
|
|
1242
|
+
*/
|
|
1243
|
+
resource?: string | string[];
|
|
1194
1244
|
}
|
|
1195
1245
|
/**
|
|
1196
1246
|
* Stored within the verification.value field
|
|
@@ -1204,6 +1254,7 @@ interface VerificationValue {
|
|
|
1204
1254
|
query: OAuthAuthorizationQuery;
|
|
1205
1255
|
sessionId: string;
|
|
1206
1256
|
userId: string;
|
|
1257
|
+
resource?: string[];
|
|
1207
1258
|
referenceId?: string;
|
|
1208
1259
|
authTime?: number;
|
|
1209
1260
|
}
|
|
@@ -1272,6 +1323,22 @@ interface SchemaClient<Scopes extends readonly Scope[] = InternallySupportedScop
|
|
|
1272
1323
|
* For example, `https://example.com/logout/callback`
|
|
1273
1324
|
*/
|
|
1274
1325
|
postLogoutRedirectUris?: string[];
|
|
1326
|
+
/**
|
|
1327
|
+
* RP URL that will receive a signed Logout Token when the end-user's OP
|
|
1328
|
+
* session ends. Registering it is the per-client opt-in for back-channel
|
|
1329
|
+
* logout. Must be absolute, without a fragment, and HTTPS for confidential
|
|
1330
|
+
* clients.
|
|
1331
|
+
*
|
|
1332
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#RPMetadata
|
|
1333
|
+
*/
|
|
1334
|
+
backchannelLogoutUri?: string;
|
|
1335
|
+
/**
|
|
1336
|
+
* When true, the RP requires the `sid` claim in every Logout Token.
|
|
1337
|
+
* User-scoped (sid-less) logouts are not dispatched to such a client.
|
|
1338
|
+
*
|
|
1339
|
+
* @default false
|
|
1340
|
+
*/
|
|
1341
|
+
backchannelLogoutSessionRequired?: boolean;
|
|
1275
1342
|
tokenEndpointAuthMethod?: "none" | "client_secret_basic" | "client_secret_post" | "private_key_jwt";
|
|
1276
1343
|
grantTypes?: GrantType[];
|
|
1277
1344
|
responseTypes?: "code"[];
|
|
@@ -1363,12 +1430,22 @@ interface OAuthOpaqueAccessToken<Scopes extends readonly Scope[] = InternallySup
|
|
|
1363
1430
|
expiresAt: Date;
|
|
1364
1431
|
/** The creation date of the access token. */
|
|
1365
1432
|
createdAt: Date;
|
|
1433
|
+
/**
|
|
1434
|
+
* When the access token was revoked. Set by session-end dispatch, the
|
|
1435
|
+
* revoke endpoint, and back-channel logout. Introspection and protected
|
|
1436
|
+
* endpoints MUST treat a revoked token as inactive.
|
|
1437
|
+
*/
|
|
1438
|
+
revoked?: Date | null;
|
|
1366
1439
|
/**
|
|
1367
1440
|
* Scope granted for the access token.
|
|
1368
1441
|
*
|
|
1369
1442
|
* Shall match the refreshId.scopes if refreshId is provided.
|
|
1370
1443
|
*/
|
|
1371
1444
|
scopes: Scopes;
|
|
1445
|
+
/**
|
|
1446
|
+
* Resources allowed for this access token.
|
|
1447
|
+
*/
|
|
1448
|
+
resources?: string[];
|
|
1372
1449
|
}
|
|
1373
1450
|
/**
|
|
1374
1451
|
* Refresh Token Database Schema
|
|
@@ -1396,6 +1473,10 @@ interface OAuthRefreshToken<Scopes extends readonly Scope[] = InternallySupporte
|
|
|
1396
1473
|
* Considered Immutable once granted.
|
|
1397
1474
|
*/
|
|
1398
1475
|
scopes: Scopes;
|
|
1476
|
+
/**
|
|
1477
|
+
* Resources allowed for this refresh token
|
|
1478
|
+
*/
|
|
1479
|
+
resources?: string[];
|
|
1399
1480
|
}
|
|
1400
1481
|
/**
|
|
1401
1482
|
* Consent Database Schema
|
|
@@ -1404,6 +1485,7 @@ type OAuthConsent<Scopes extends readonly Scope[] = InternallySupportedScopes[]>
|
|
|
1404
1485
|
id: string;
|
|
1405
1486
|
clientId: string;
|
|
1406
1487
|
userId: string;
|
|
1488
|
+
resources?: string[];
|
|
1407
1489
|
referenceId?: string;
|
|
1408
1490
|
scopes: Scopes;
|
|
1409
1491
|
createdAt: Date;
|
|
@@ -1457,9 +1539,11 @@ interface AuthServerMetadata {
|
|
|
1457
1539
|
/**
|
|
1458
1540
|
* The URL of the dynamic client registration endpoint.
|
|
1459
1541
|
*
|
|
1542
|
+
* This field is only present when `allowDynamicClientRegistration` is enabled.
|
|
1543
|
+
*
|
|
1460
1544
|
* @default `/oauth2/register`
|
|
1461
1545
|
*/
|
|
1462
|
-
registration_endpoint
|
|
1546
|
+
registration_endpoint?: string;
|
|
1463
1547
|
/**
|
|
1464
1548
|
* Supported scopes.
|
|
1465
1549
|
*/
|
|
@@ -1492,7 +1576,7 @@ interface AuthServerMetadata {
|
|
|
1492
1576
|
* token endpoint for the "private_key_jwt" and "client_secret_jwt"
|
|
1493
1577
|
* authentication methods (see field token_endpoint_auth_methods_supported).
|
|
1494
1578
|
*/
|
|
1495
|
-
token_endpoint_auth_signing_alg_values_supported?:
|
|
1579
|
+
token_endpoint_auth_signing_alg_values_supported?: PrivateKeyJwtSigningAlgorithm[];
|
|
1496
1580
|
/**
|
|
1497
1581
|
* URL of a page containing human-readable information
|
|
1498
1582
|
* that developers might want or need to know when using the
|
|
@@ -1538,7 +1622,7 @@ interface AuthServerMetadata {
|
|
|
1538
1622
|
* token endpoint for the "private_key_jwt" and "client_secret_jwt"
|
|
1539
1623
|
* authentication methods (see field revocation_endpoint_auth_methods_supported).
|
|
1540
1624
|
*/
|
|
1541
|
-
revocation_endpoint_auth_signing_alg_values_supported?:
|
|
1625
|
+
revocation_endpoint_auth_signing_alg_values_supported?: PrivateKeyJwtSigningAlgorithm[];
|
|
1542
1626
|
/**
|
|
1543
1627
|
* URL of the authorization server's OAuth 2.0
|
|
1544
1628
|
* introspection endpoint [RFC7662](https://datatracker.ietf.org/doc/html/rfc7662)
|
|
@@ -1559,7 +1643,7 @@ interface AuthServerMetadata {
|
|
|
1559
1643
|
* the "private_key_jwt" and "client_secret_jwt" authentication methods
|
|
1560
1644
|
* (see field introspection_endpoint_auth_methods_supported).
|
|
1561
1645
|
*/
|
|
1562
|
-
introspection_endpoint_auth_signing_alg_values_supported?:
|
|
1646
|
+
introspection_endpoint_auth_signing_alg_values_supported?: PrivateKeyJwtSigningAlgorithm[];
|
|
1563
1647
|
/**
|
|
1564
1648
|
* Supported code challenge methods.
|
|
1565
1649
|
*
|
|
@@ -1585,6 +1669,28 @@ interface AuthServerMetadata {
|
|
|
1585
1669
|
* it on its own.
|
|
1586
1670
|
*/
|
|
1587
1671
|
client_id_metadata_document_supported?: boolean;
|
|
1672
|
+
/**
|
|
1673
|
+
* Boolean value specifying whether the OP supports back-channel logout,
|
|
1674
|
+
* with true indicating support.
|
|
1675
|
+
*
|
|
1676
|
+
* Registered in the "OAuth Authorization Server Metadata" IANA registry
|
|
1677
|
+
* under OpenID Connect Back-Channel Logout 1.0, so this may appear at both
|
|
1678
|
+
* `.well-known/oauth-authorization-server` and `.well-known/openid-configuration`.
|
|
1679
|
+
*
|
|
1680
|
+
* @default false
|
|
1681
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#OPMetadata
|
|
1682
|
+
*/
|
|
1683
|
+
backchannel_logout_supported?: boolean;
|
|
1684
|
+
/**
|
|
1685
|
+
* Boolean value specifying whether the OP can pass a `sid` (session ID)
|
|
1686
|
+
* Claim in the Logout Token to identify the RP session with the OP.
|
|
1687
|
+
*
|
|
1688
|
+
* When true, the OP also includes `sid` in ID Tokens it issues.
|
|
1689
|
+
*
|
|
1690
|
+
* @default false
|
|
1691
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#OPMetadata
|
|
1692
|
+
*/
|
|
1693
|
+
backchannel_logout_session_supported?: boolean;
|
|
1588
1694
|
}
|
|
1589
1695
|
/**
|
|
1590
1696
|
* Metadata returned by the openid-configuration endpoint:
|
|
@@ -1687,6 +1793,22 @@ interface OAuthClient {
|
|
|
1687
1793
|
software_statement?: string;
|
|
1688
1794
|
redirect_uris: string[];
|
|
1689
1795
|
post_logout_redirect_uris?: string[];
|
|
1796
|
+
/**
|
|
1797
|
+
* RP URL that the OP POSTs a signed Logout Token to when a session at the OP
|
|
1798
|
+
* ends. The RP uses the token to terminate its own session state for that
|
|
1799
|
+
* user (including any access tokens it has bound to the session).
|
|
1800
|
+
*
|
|
1801
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#RPMetadata
|
|
1802
|
+
*/
|
|
1803
|
+
backchannel_logout_uri?: string;
|
|
1804
|
+
/**
|
|
1805
|
+
* When true, the RP requires the `sid` Claim in every Logout Token it
|
|
1806
|
+
* receives; the OP will not dispatch user-scoped (sid-less) logouts to it.
|
|
1807
|
+
*
|
|
1808
|
+
* @default false
|
|
1809
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#RPMetadata
|
|
1810
|
+
*/
|
|
1811
|
+
backchannel_logout_session_required?: boolean;
|
|
1690
1812
|
token_endpoint_auth_method?: "none" | "client_secret_basic" | "client_secret_post" | "private_key_jwt";
|
|
1691
1813
|
grant_types?: GrantType[];
|
|
1692
1814
|
response_types?: "code"[];
|