@better-auth/oauth-provider 1.5.0-beta.1 → 1.5.0-beta.2
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-resource.d.mts +1 -1
- package/dist/client-resource.mjs +1 -1
- package/dist/client.d.mts +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -154
- package/dist/{oauth-kjs13QN6.d.mts → oauth-BrFoF22H.d.mts} +1 -1
- package/dist/{oauth-Cex7QJsW.d.mts → oauth-C1OnEiU-.d.mts} +2 -2
- package/package.json +5 -5
package/dist/client-resource.mjs
CHANGED
|
@@ -20,7 +20,7 @@ const oauthProviderResourceClient = (auth) => {
|
|
|
20
20
|
const issuer = opts?.verifyOptions?.issuer ?? jwtPluginOptions?.jwt?.issuer ?? authServerBaseUrl;
|
|
21
21
|
if (!audience) throw Error("please define opts.verifyOptions.audience");
|
|
22
22
|
if (!issuer) throw Error("please define opts.verifyOptions.issuer");
|
|
23
|
-
const jwksUrl = opts?.jwksUrl ?? jwtPluginOptions?.jwks?.remoteUrl ?? (authServerBaseUrl ? `${authServerBaseUrl + (authServerBasePath ?? "")}/jwks` : void 0);
|
|
23
|
+
const jwksUrl = opts?.jwksUrl ?? jwtPluginOptions?.jwks?.remoteUrl ?? (authServerBaseUrl ? `${authServerBaseUrl + (authServerBasePath ?? "")}${jwtPluginOptions?.jwks?.jwksPath ?? "/jwks"}` : void 0);
|
|
24
24
|
const introspectUrl = opts?.remoteVerify?.introspectUrl ?? (authServerBaseUrl ? `${authServerBaseUrl}${authServerBasePath ?? ""}/oauth2/introspect` : void 0);
|
|
25
25
|
try {
|
|
26
26
|
if (!token?.length) throw new APIError("UNAUTHORIZED", { message: "missing authorization header" });
|
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./oauth-
|
|
2
|
-
import { t as oauthProvider } from "./oauth-
|
|
1
|
+
import "./oauth-BrFoF22H.mjs";
|
|
2
|
+
import { t as oauthProvider } from "./oauth-C1OnEiU-.mjs";
|
|
3
3
|
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
4
4
|
|
|
5
5
|
//#region src/client.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ as Awaitable, a as ResourceServerMetadata, c as OAuthConsent, d as OAuthRefreshToken, f as Prompt, g as VerificationValue, h as StoreTokenType, i as OIDCMetadata, l as OAuthOpaqueAccessToken, m as Scope, n as GrantType, o as AuthorizePrompt, p as SchemaClient, r as OAuthClient, s as OAuthAuthorizationQuery, t as AuthServerMetadata, u as OAuthOptions } from "./oauth-
|
|
2
|
-
import { t as oauthProvider } from "./oauth-
|
|
1
|
+
import { _ as Awaitable, a as ResourceServerMetadata, c as OAuthConsent, d as OAuthRefreshToken, f as Prompt, g as VerificationValue, h as StoreTokenType, i as OIDCMetadata, l as OAuthOpaqueAccessToken, m as Scope, n as GrantType, o as AuthorizePrompt, p as SchemaClient, r as OAuthClient, s as OAuthAuthorizationQuery, t as AuthServerMetadata, u as OAuthOptions } from "./oauth-BrFoF22H.mjs";
|
|
2
|
+
import { t as oauthProvider } from "./oauth-C1OnEiU-.mjs";
|
|
3
3
|
import { verifyAccessToken } from "better-auth/oauth2";
|
|
4
|
-
import { JWSAlgorithms, JwtOptions } from "better-auth/plugins
|
|
4
|
+
import { JWSAlgorithms, JwtOptions } from "better-auth/plugins";
|
|
5
5
|
import { JWTPayload } from "jose";
|
|
6
6
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
7
7
|
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { a as getJwtPlugin, c as parsePrompt, d as validateClientCredentials, i
|
|
|
2
2
|
import { generateCodeChallenge, getJwks, verifyJwsAccessToken } from "better-auth/oauth2";
|
|
3
3
|
import { APIError } from "better-call";
|
|
4
4
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
5
|
-
import { createHash } from "@better-auth/utils/hash";
|
|
6
5
|
import { constantTimeEqual, generateRandomString, makeSignature } from "better-auth/crypto";
|
|
7
6
|
import { defineRequestState } from "@better-auth/core/context";
|
|
8
7
|
import { logger } from "@better-auth/core/env";
|
|
@@ -10,11 +9,8 @@ import { APIError as APIError$1, createAuthEndpoint, createAuthMiddleware, getOA
|
|
|
10
9
|
import { parseSetCookieHeader } from "better-auth/cookies";
|
|
11
10
|
import { mergeSchema } from "better-auth/db";
|
|
12
11
|
import * as z from "zod";
|
|
13
|
-
import { signJWT, toExpJWT } from "better-auth/plugins
|
|
12
|
+
import { signJWT, toExpJWT } from "better-auth/plugins";
|
|
14
13
|
import { SignJWT, compactVerify, createLocalJWKSet, decodeJwt } from "jose";
|
|
15
|
-
import "@better-auth/utils";
|
|
16
|
-
import "@better-auth/utils/hex";
|
|
17
|
-
import { createRandomStringGenerator } from "@better-auth/utils/random";
|
|
18
14
|
|
|
19
15
|
//#region src/metadata.ts
|
|
20
16
|
function authServerMetadata(ctx, opts, overrides) {
|
|
@@ -24,7 +20,7 @@ function authServerMetadata(ctx, opts, overrides) {
|
|
|
24
20
|
issuer: opts?.jwt?.issuer ?? baseURL,
|
|
25
21
|
authorization_endpoint: `${baseURL}/oauth2/authorize`,
|
|
26
22
|
token_endpoint: `${baseURL}/oauth2/token`,
|
|
27
|
-
jwks_uri: overrides?.jwt_disabled ? void 0 : opts?.jwks?.remoteUrl ?? `${baseURL}/jwks`,
|
|
23
|
+
jwks_uri: overrides?.jwt_disabled ? void 0 : opts?.jwks?.remoteUrl ?? `${baseURL}${opts?.jwks?.jwksPath ?? "/jwks"}`,
|
|
28
24
|
registration_endpoint: `${baseURL}/oauth2/register`,
|
|
29
25
|
introspection_endpoint: `${baseURL}/oauth2/introspect`,
|
|
30
26
|
revocation_endpoint: `${baseURL}/oauth2/revoke`,
|
|
@@ -1223,7 +1219,7 @@ async function rpInitiatedLogoutEndpoint(ctx, opts) {
|
|
|
1223
1219
|
const { id_token_hint, client_id, post_logout_redirect_uri, state } = ctx.query;
|
|
1224
1220
|
const baseURL = ctx.context.baseURL;
|
|
1225
1221
|
const jwtPluginOptions = (opts.disableJwtPlugin ? void 0 : getJwtPlugin(ctx.context))?.options;
|
|
1226
|
-
const jwksUrl = jwtPluginOptions?.jwks?.remoteUrl ?? `${baseURL}/jwks`;
|
|
1222
|
+
const jwksUrl = jwtPluginOptions?.jwks?.remoteUrl ?? `${baseURL}${jwtPluginOptions?.jwks?.jwksPath ?? "/jwks"}`;
|
|
1227
1223
|
let clientId = client_id;
|
|
1228
1224
|
if (!clientId) {
|
|
1229
1225
|
let decoded;
|
|
@@ -1323,152 +1319,6 @@ async function rpInitiatedLogoutEndpoint(ctx, opts) {
|
|
|
1323
1319
|
}
|
|
1324
1320
|
}
|
|
1325
1321
|
|
|
1326
|
-
//#endregion
|
|
1327
|
-
//#region ../better-auth/src/crypto/jwt.ts
|
|
1328
|
-
const info = new Uint8Array([
|
|
1329
|
-
66,
|
|
1330
|
-
101,
|
|
1331
|
-
116,
|
|
1332
|
-
116,
|
|
1333
|
-
101,
|
|
1334
|
-
114,
|
|
1335
|
-
65,
|
|
1336
|
-
117,
|
|
1337
|
-
116,
|
|
1338
|
-
104,
|
|
1339
|
-
46,
|
|
1340
|
-
106,
|
|
1341
|
-
115,
|
|
1342
|
-
32,
|
|
1343
|
-
71,
|
|
1344
|
-
101,
|
|
1345
|
-
110,
|
|
1346
|
-
101,
|
|
1347
|
-
114,
|
|
1348
|
-
97,
|
|
1349
|
-
116,
|
|
1350
|
-
101,
|
|
1351
|
-
100,
|
|
1352
|
-
32,
|
|
1353
|
-
69,
|
|
1354
|
-
110,
|
|
1355
|
-
99,
|
|
1356
|
-
114,
|
|
1357
|
-
121,
|
|
1358
|
-
112,
|
|
1359
|
-
116,
|
|
1360
|
-
105,
|
|
1361
|
-
111,
|
|
1362
|
-
110,
|
|
1363
|
-
32,
|
|
1364
|
-
75,
|
|
1365
|
-
101,
|
|
1366
|
-
121
|
|
1367
|
-
]);
|
|
1368
|
-
|
|
1369
|
-
//#endregion
|
|
1370
|
-
//#region ../better-auth/src/crypto/random.ts
|
|
1371
|
-
const generateRandomString$1 = createRandomStringGenerator("a-z", "0-9", "A-Z", "-_");
|
|
1372
|
-
|
|
1373
|
-
//#endregion
|
|
1374
|
-
//#region ../better-auth/src/utils/time.ts
|
|
1375
|
-
const SEC = 1e3;
|
|
1376
|
-
const MIN = SEC * 60;
|
|
1377
|
-
const HOUR = MIN * 60;
|
|
1378
|
-
const DAY = HOUR * 24;
|
|
1379
|
-
const WEEK = DAY * 7;
|
|
1380
|
-
const MONTH = DAY * 30;
|
|
1381
|
-
const YEAR = DAY * 365.25;
|
|
1382
|
-
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1383
|
-
function parse(value) {
|
|
1384
|
-
const match = REGEX.exec(value);
|
|
1385
|
-
if (!match || match[4] && match[1]) throw new TypeError(`Invalid time string format: "${value}". Use formats like "7d", "30m", "1 hour", etc.`);
|
|
1386
|
-
const n = parseFloat(match[2]);
|
|
1387
|
-
const unit = match[3].toLowerCase();
|
|
1388
|
-
let result;
|
|
1389
|
-
switch (unit) {
|
|
1390
|
-
case "years":
|
|
1391
|
-
case "year":
|
|
1392
|
-
case "yrs":
|
|
1393
|
-
case "yr":
|
|
1394
|
-
case "y":
|
|
1395
|
-
result = n * YEAR;
|
|
1396
|
-
break;
|
|
1397
|
-
case "months":
|
|
1398
|
-
case "month":
|
|
1399
|
-
case "mo":
|
|
1400
|
-
result = n * MONTH;
|
|
1401
|
-
break;
|
|
1402
|
-
case "weeks":
|
|
1403
|
-
case "week":
|
|
1404
|
-
case "w":
|
|
1405
|
-
result = n * WEEK;
|
|
1406
|
-
break;
|
|
1407
|
-
case "days":
|
|
1408
|
-
case "day":
|
|
1409
|
-
case "d":
|
|
1410
|
-
result = n * DAY;
|
|
1411
|
-
break;
|
|
1412
|
-
case "hours":
|
|
1413
|
-
case "hour":
|
|
1414
|
-
case "hrs":
|
|
1415
|
-
case "hr":
|
|
1416
|
-
case "h":
|
|
1417
|
-
result = n * HOUR;
|
|
1418
|
-
break;
|
|
1419
|
-
case "minutes":
|
|
1420
|
-
case "minute":
|
|
1421
|
-
case "mins":
|
|
1422
|
-
case "min":
|
|
1423
|
-
case "m":
|
|
1424
|
-
result = n * MIN;
|
|
1425
|
-
break;
|
|
1426
|
-
case "seconds":
|
|
1427
|
-
case "second":
|
|
1428
|
-
case "secs":
|
|
1429
|
-
case "sec":
|
|
1430
|
-
case "s":
|
|
1431
|
-
result = n * SEC;
|
|
1432
|
-
break;
|
|
1433
|
-
default: throw new TypeError(`Unknown time unit: "${unit}"`);
|
|
1434
|
-
}
|
|
1435
|
-
if (match[1] === "-" || match[4] === "ago") return -result;
|
|
1436
|
-
return result;
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* Parse a time string and return the value in seconds.
|
|
1440
|
-
*
|
|
1441
|
-
* @param value - A time string like "7d", "30m", "1 hour", "2 hours ago"
|
|
1442
|
-
* @returns The parsed value in seconds (rounded)
|
|
1443
|
-
* @throws TypeError if the string format is invalid
|
|
1444
|
-
*
|
|
1445
|
-
* @example
|
|
1446
|
-
* sec("1d") // 86400
|
|
1447
|
-
* sec("2 hours") // 7200
|
|
1448
|
-
* sec("-30s") // -30
|
|
1449
|
-
* sec("2 hours ago") // -7200
|
|
1450
|
-
*/
|
|
1451
|
-
function sec(value) {
|
|
1452
|
-
return Math.round(parse(value) / 1e3);
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
//#endregion
|
|
1456
|
-
//#region ../better-auth/src/plugins/jwt/utils.ts
|
|
1457
|
-
/**
|
|
1458
|
-
* Converts an expirationTime to ISO seconds expiration time (the format of JWT exp)
|
|
1459
|
-
*
|
|
1460
|
-
* See https://github.com/panva/jose/blob/main/src/lib/jwt_claims_set.ts#L245
|
|
1461
|
-
*
|
|
1462
|
-
* @param expirationTime - see options.jwt.expirationTime
|
|
1463
|
-
* @param iat - the iat time to consolidate on
|
|
1464
|
-
* @returns
|
|
1465
|
-
*/
|
|
1466
|
-
function toExpJWT$1(expirationTime, iat) {
|
|
1467
|
-
if (typeof expirationTime === "number") return expirationTime;
|
|
1468
|
-
else if (expirationTime instanceof Date) return Math.floor(expirationTime.getTime() / 1e3);
|
|
1469
|
-
else return iat + sec(expirationTime);
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
1322
|
//#endregion
|
|
1473
1323
|
//#region src/register.ts
|
|
1474
1324
|
async function registerEndpoint(ctx, opts) {
|
|
@@ -1540,7 +1390,7 @@ async function createOAuthClientEndpoint(ctx, opts, settings) {
|
|
|
1540
1390
|
disabled: void 0,
|
|
1541
1391
|
jwks: void 0,
|
|
1542
1392
|
jwks_uri: void 0,
|
|
1543
|
-
client_secret_expires_at: storedClientSecret ? settings.isRegister && opts?.clientRegistrationClientSecretExpiration ? toExpJWT
|
|
1393
|
+
client_secret_expires_at: storedClientSecret ? settings.isRegister && opts?.clientRegistrationClientSecretExpiration ? toExpJWT(opts.clientRegistrationClientSecretExpiration, iat) : 0 : void 0,
|
|
1544
1394
|
client_id: clientId,
|
|
1545
1395
|
client_secret: storedClientSecret,
|
|
1546
1396
|
client_id_issued_at: iat,
|
|
@@ -3010,6 +2860,7 @@ const oauthProvider = (options) => {
|
|
|
3010
2860
|
id: "oauthProvider",
|
|
3011
2861
|
options: opts,
|
|
3012
2862
|
init: (ctx) => {
|
|
2863
|
+
if (ctx.options.session && !ctx.options.session.storeSessionInDatabase) throw new BetterAuthError("OAuth Provider requires `session.storeSessionInDatabase: true` when using secondaryStorage");
|
|
3013
2864
|
if (!opts.disableJwtPlugin) {
|
|
3014
2865
|
const issuer = getJwtPlugin(ctx).options?.jwt?.issuer ?? ctx.baseURL;
|
|
3015
2866
|
const issuerPath = new URL(issuer).pathname;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JWSAlgorithms } from "better-auth/plugins
|
|
1
|
+
import { JWSAlgorithms } from "better-auth/plugins";
|
|
2
2
|
import { JWTPayload } from "jose";
|
|
3
3
|
import { InferOptionSchema, Session, User } from "better-auth/types";
|
|
4
4
|
import { LiteralString } from "@better-auth/core";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as OAuthConsent, i as OIDCMetadata, m as Scope, r as OAuthClient, t as AuthServerMetadata, u as OAuthOptions } from "./oauth-
|
|
1
|
+
import { c as OAuthConsent, i as OIDCMetadata, m as Scope, r as OAuthClient, t as AuthServerMetadata, u as OAuthOptions } from "./oauth-BrFoF22H.mjs";
|
|
2
2
|
import * as better_call0 from "better-call";
|
|
3
3
|
import "@better-auth/core/context";
|
|
4
4
|
import * as z from "zod";
|
|
5
|
+
import * as better_auth_plugins0 from "better-auth/plugins";
|
|
5
6
|
import * as jose0 from "jose";
|
|
6
7
|
import * as better_auth0 from "better-auth";
|
|
7
|
-
import * as better_auth_plugins0 from "better-auth/plugins";
|
|
8
8
|
|
|
9
9
|
//#region src/oauth.d.ts
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/oauth-provider",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "An oauth provider plugin for Better Auth",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@modelcontextprotocol/sdk": "^1.24.2",
|
|
43
43
|
"listhen": "^1.9.0",
|
|
44
44
|
"tsdown": "^0.17.2",
|
|
45
|
-
"@better-auth/core": "1.5.0-beta.
|
|
46
|
-
"better-auth": "1.5.0-beta.
|
|
45
|
+
"@better-auth/core": "1.5.0-beta.2",
|
|
46
|
+
"better-auth": "1.5.0-beta.2"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"jose": "^6.1.0",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"@better-auth/utils": "0.3.0",
|
|
54
54
|
"@better-fetch/fetch": "1.1.21",
|
|
55
55
|
"better-call": "1.1.7",
|
|
56
|
-
"@better-auth/core": "1.5.0-beta.
|
|
57
|
-
"better-auth": "1.5.0-beta.
|
|
56
|
+
"@better-auth/core": "1.5.0-beta.2",
|
|
57
|
+
"better-auth": "1.5.0-beta.2"
|
|
58
58
|
},
|
|
59
59
|
"files": [
|
|
60
60
|
"dist"
|