@better-auth/oauth-provider 1.6.4 → 1.6.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.
@@ -1,5 +1,5 @@
1
1
  import { a as getJwtPlugin, o as getOAuthProviderPlugin, y as handleMcpErrors } from "./utils-B9Pj9EPf.mjs";
2
- import { t as PACKAGE_VERSION } from "./version-Cvnm3JjE.mjs";
2
+ import { t as PACKAGE_VERSION } from "./version-CYsV29Ge.mjs";
3
3
  import { verifyAccessToken } from "better-auth/oauth2";
4
4
  import { APIError } from "better-call";
5
5
  import { logger } from "@better-auth/core/env";
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-Cvnm3JjE.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-CYsV29Ge.mjs";
2
2
  import { safeJSONParse } from "@better-auth/core/utils/json";
3
3
  //#region src/client.ts
4
4
  function parseSignedQuery(search) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _ as validateClientCredentials, a as getJwtPlugin, b as mcpHandler, c as isPKCERequired, d as parsePrompt, f as resolveSessionAuthTime, g as storeToken, h as storeClientSecret, i as getClient, l as normalizeTimestampValue, m as searchParamsToQuery, n as decryptStoredClientSecret, p as resolveSubjectIdentifier, r as deleteFromPrompt, s as getStoredToken, t as basicToClientCredentials, u as parseClientMetadata, v as verifyOAuthQueryParams } from "./utils-B9Pj9EPf.mjs";
2
- import { t as PACKAGE_VERSION } from "./version-Cvnm3JjE.mjs";
2
+ import { t as PACKAGE_VERSION } from "./version-CYsV29Ge.mjs";
3
3
  import { APIError, createAuthEndpoint, createAuthMiddleware, getOAuthState, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
4
4
  import { generateCodeChallenge, getJwks, verifyJwsAccessToken } from "better-auth/oauth2";
5
5
  import { APIError as APIError$1 } from "better-call";
@@ -1404,14 +1404,8 @@ function schemaToOAuth(input) {
1404
1404
  //#region src/oauthClient/endpoints.ts
1405
1405
  async function getClientEndpoint(ctx, opts) {
1406
1406
  const session = await getSessionFromCtx(ctx);
1407
+ await assertClientPrivileges(ctx, session, opts, "read");
1407
1408
  if (!session) throw new APIError("UNAUTHORIZED");
1408
- if (!ctx.headers) throw new APIError("BAD_REQUEST");
1409
- if (opts.clientPrivileges && !await opts.clientPrivileges({
1410
- headers: ctx.headers,
1411
- action: "read",
1412
- session: session.session,
1413
- user: session.user
1414
- })) throw new APIError("UNAUTHORIZED");
1415
1409
  const client = await getClient(ctx, opts, ctx.query.client_id);
1416
1410
  if (!client) throw new APIError("NOT_FOUND", {
1417
1411
  error_description: "client not found",
@@ -1452,14 +1446,8 @@ async function getClientPublicEndpoint(ctx, opts, clientId) {
1452
1446
  }
1453
1447
  async function getClientsEndpoint(ctx, opts) {
1454
1448
  const session = await getSessionFromCtx(ctx);
1449
+ await assertClientPrivileges(ctx, session, opts, "list");
1455
1450
  if (!session) throw new APIError("UNAUTHORIZED");
1456
- if (!ctx.headers) throw new APIError("BAD_REQUEST");
1457
- if (opts.clientPrivileges && !await opts.clientPrivileges({
1458
- headers: ctx.headers,
1459
- action: "list",
1460
- session: session.session,
1461
- user: session.user
1462
- })) throw new APIError("UNAUTHORIZED");
1463
1451
  const referenceId = await opts.clientReference?.(session);
1464
1452
  if (referenceId) return await ctx.context.adapter.findMany({
1465
1453
  model: "oauthClient",
@@ -1493,14 +1481,8 @@ async function getClientsEndpoint(ctx, opts) {
1493
1481
  }
1494
1482
  async function deleteClientEndpoint(ctx, opts) {
1495
1483
  const session = await getSessionFromCtx(ctx);
1484
+ await assertClientPrivileges(ctx, session, opts, "delete");
1496
1485
  if (!session) throw new APIError("UNAUTHORIZED");
1497
- if (!ctx.headers) throw new APIError("BAD_REQUEST");
1498
- if (opts.clientPrivileges && !await opts.clientPrivileges({
1499
- headers: ctx.headers,
1500
- action: "delete",
1501
- session: session.session,
1502
- user: session.user
1503
- })) throw new APIError("UNAUTHORIZED");
1504
1486
  const clientId = ctx.body.client_id;
1505
1487
  if (opts.cachedTrustedClients?.has(clientId)) throw new APIError("INTERNAL_SERVER_ERROR", {
1506
1488
  error_description: "trusted clients must be updated manually",
@@ -1526,14 +1508,8 @@ async function deleteClientEndpoint(ctx, opts) {
1526
1508
  }
1527
1509
  async function updateClientEndpoint(ctx, opts) {
1528
1510
  const session = await getSessionFromCtx(ctx);
1511
+ await assertClientPrivileges(ctx, session, opts, "update");
1529
1512
  if (!session) throw new APIError("UNAUTHORIZED");
1530
- if (!ctx.headers) throw new APIError("BAD_REQUEST");
1531
- if (opts.clientPrivileges && !await opts.clientPrivileges({
1532
- headers: ctx.headers,
1533
- action: "update",
1534
- session: session.session,
1535
- user: session.user
1536
- })) throw new APIError("UNAUTHORIZED");
1537
1513
  const clientId = ctx.body.client_id;
1538
1514
  if (opts.cachedTrustedClients?.has(clientId)) throw new APIError("INTERNAL_SERVER_ERROR", {
1539
1515
  error_description: "trusted clients must be updated manually",
@@ -1580,14 +1556,8 @@ async function updateClientEndpoint(ctx, opts) {
1580
1556
  }
1581
1557
  async function rotateClientSecretEndpoint(ctx, opts) {
1582
1558
  const session = await getSessionFromCtx(ctx);
1559
+ await assertClientPrivileges(ctx, session, opts, "rotate");
1583
1560
  if (!session) throw new APIError("UNAUTHORIZED");
1584
- if (!ctx.headers) throw new APIError("BAD_REQUEST");
1585
- if (opts.clientPrivileges && !await opts.clientPrivileges({
1586
- headers: ctx.headers,
1587
- action: "rotate",
1588
- session: session.session,
1589
- user: session.user
1590
- })) throw new APIError("UNAUTHORIZED");
1591
1561
  const clientId = ctx.body.client_id;
1592
1562
  if (opts.cachedTrustedClients?.has(clientId)) throw new APIError("INTERNAL_SERVER_ERROR", {
1593
1563
  error_description: "trusted clients must be updated manually",
@@ -1629,6 +1599,16 @@ async function rotateClientSecretEndpoint(ctx, opts) {
1629
1599
  clientSecret: (opts.prefix?.clientSecret ?? "") + clientSecret
1630
1600
  });
1631
1601
  }
1602
+ async function assertClientPrivileges(ctx, session, opts, action) {
1603
+ if (!session) throw new APIError("UNAUTHORIZED");
1604
+ if (!ctx.headers) throw new APIError("BAD_REQUEST");
1605
+ if (opts.clientPrivileges && !await opts.clientPrivileges({
1606
+ headers: ctx.headers,
1607
+ action,
1608
+ session: session.session,
1609
+ user: session.user
1610
+ })) throw new APIError("UNAUTHORIZED");
1611
+ }
1632
1612
  //#endregion
1633
1613
  //#region src/oauthClient/index.ts
1634
1614
  const adminCreateOAuthClient = (opts) => createAuthEndpoint("/admin/oauth2/create-client", {
@@ -1811,6 +1791,7 @@ const adminCreateOAuthClient = (opts) => createAuthEndpoint("/admin/oauth2/creat
1811
1791
  }
1812
1792
  }
1813
1793
  }, async (ctx) => {
1794
+ await assertClientPrivileges(ctx, await getSessionFromCtx(ctx), opts, "create");
1814
1795
  return createOAuthClientEndpoint(ctx, opts, { isRegister: false });
1815
1796
  });
1816
1797
  const createOAuthClient = (opts) => createAuthEndpoint("/oauth2/create-client", {
@@ -1980,6 +1961,7 @@ const createOAuthClient = (opts) => createAuthEndpoint("/oauth2/create-client",
1980
1961
  } }
1981
1962
  } }
1982
1963
  }, async (ctx) => {
1964
+ await assertClientPrivileges(ctx, await getSessionFromCtx(ctx), opts, "create");
1983
1965
  return createOAuthClientEndpoint(ctx, opts, { isRegister: false });
1984
1966
  });
1985
1967
  const getOAuthClient = (opts) => createAuthEndpoint("/oauth2/get-client", {
@@ -1,5 +1,5 @@
1
1
  //#endregion
2
2
  //#region src/version.ts
3
- const PACKAGE_VERSION = "1.6.4";
3
+ const PACKAGE_VERSION = "1.6.5";
4
4
  //#endregion
5
5
  export { PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/oauth-provider",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "An oauth provider plugin for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -64,15 +64,15 @@
64
64
  "@modelcontextprotocol/sdk": "^1.27.1",
65
65
  "listhen": "^1.9.0",
66
66
  "tsdown": "0.21.1",
67
- "@better-auth/core": "1.6.4",
68
- "better-auth": "1.6.4"
67
+ "@better-auth/core": "1.6.5",
68
+ "better-auth": "1.6.5"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@better-auth/utils": "0.4.0",
72
72
  "@better-fetch/fetch": "1.1.21",
73
73
  "better-call": "1.3.5",
74
- "@better-auth/core": "^1.6.4",
75
- "better-auth": "^1.6.4"
74
+ "@better-auth/core": "^1.6.5",
75
+ "better-auth": "^1.6.5"
76
76
  },
77
77
  "scripts": {
78
78
  "build": "tsdown",