@drawbridge/drawbridge-utils 0.0.82 → 0.0.83

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.
@@ -361,6 +361,19 @@ var createOAuthModel = ({ controller }) => ({
361
361
  const granted = intersect(scope, token.scope ?? []);
362
362
  return granted.length > 0;
363
363
  },
364
+ // Scope enforcement at AUTHORIZE time. Without this, @node-oauth's
365
+ // AuthorizeHandler grants whatever scope the request asks for — the client
366
+ // registry's scopes list was only advisory (reachable from any logged-in
367
+ // browser via the dashboard's authorize BFF). Every requested scope must be
368
+ // registered on the client; an empty request falls back to the client's
369
+ // full registered grant. Returning false → invalid_scope.
370
+ validateScope: (user, client, scope) => {
371
+ const requested = Array.isArray(scope) ? scope : scope ? String(scope).split(/\s+/).filter(Boolean) : [];
372
+ const allowed = (client == null ? void 0 : client.scopes) ?? [];
373
+ if (!requested.length) return allowed;
374
+ const invalid = requested.filter((entry) => !allowed.includes(entry));
375
+ return invalid.length ? false : requested;
376
+ },
364
377
  // client_credentials grant: treat the client as the resource owner.
365
378
  getUserFromClient: (client) => ({ id: client.id, type: "client" })
366
379
  });
@@ -304,6 +304,28 @@ const createOAuthModel = ({ controller }) => ({
304
304
 
305
305
  },
306
306
 
307
+ // Scope enforcement at AUTHORIZE time. Without this, @node-oauth's
308
+ // AuthorizeHandler grants whatever scope the request asks for — the client
309
+ // registry's scopes list was only advisory (reachable from any logged-in
310
+ // browser via the dashboard's authorize BFF). Every requested scope must be
311
+ // registered on the client; an empty request falls back to the client's
312
+ // full registered grant. Returning false → invalid_scope.
313
+ validateScope : ( user, client, scope ) => {
314
+
315
+ const requested = Array.isArray( scope )
316
+ ? scope
317
+ : ( scope ? String( scope ).split( /\s+/ ).filter( Boolean ) : [] );
318
+
319
+ const allowed = client?.scopes ?? [];
320
+
321
+ if( ! requested.length ) return allowed;
322
+
323
+ const invalid = requested.filter( ( entry ) => ! allowed.includes( entry ) );
324
+
325
+ return invalid.length ? false : requested;
326
+
327
+ },
328
+
307
329
  // client_credentials grant: treat the client as the resource owner.
308
330
  getUserFromClient : ( client ) => ({ id : client.id, type : 'client' })
309
331
 
@@ -304,6 +304,28 @@ const createOAuthModel = ({ controller }) => ({
304
304
 
305
305
  },
306
306
 
307
+ // Scope enforcement at AUTHORIZE time. Without this, @node-oauth's
308
+ // AuthorizeHandler grants whatever scope the request asks for — the client
309
+ // registry's scopes list was only advisory (reachable from any logged-in
310
+ // browser via the dashboard's authorize BFF). Every requested scope must be
311
+ // registered on the client; an empty request falls back to the client's
312
+ // full registered grant. Returning false → invalid_scope.
313
+ validateScope : ( user, client, scope ) => {
314
+
315
+ const requested = Array.isArray( scope )
316
+ ? scope
317
+ : ( scope ? String( scope ).split( /\s+/ ).filter( Boolean ) : [] );
318
+
319
+ const allowed = client?.scopes ?? [];
320
+
321
+ if( ! requested.length ) return allowed;
322
+
323
+ const invalid = requested.filter( ( entry ) => ! allowed.includes( entry ) );
324
+
325
+ return invalid.length ? false : requested;
326
+
327
+ },
328
+
307
329
  // client_credentials grant: treat the client as the resource owner.
308
330
  getUserFromClient : ( client ) => ({ id : client.id, type : 'client' })
309
331
 
@@ -326,6 +326,19 @@ var createOAuthModel = ({ controller }) => ({
326
326
  const granted = intersect(scope, token.scope ?? []);
327
327
  return granted.length > 0;
328
328
  },
329
+ // Scope enforcement at AUTHORIZE time. Without this, @node-oauth's
330
+ // AuthorizeHandler grants whatever scope the request asks for — the client
331
+ // registry's scopes list was only advisory (reachable from any logged-in
332
+ // browser via the dashboard's authorize BFF). Every requested scope must be
333
+ // registered on the client; an empty request falls back to the client's
334
+ // full registered grant. Returning false → invalid_scope.
335
+ validateScope: (user, client, scope) => {
336
+ const requested = Array.isArray(scope) ? scope : scope ? String(scope).split(/\s+/).filter(Boolean) : [];
337
+ const allowed = (client == null ? void 0 : client.scopes) ?? [];
338
+ if (!requested.length) return allowed;
339
+ const invalid = requested.filter((entry) => !allowed.includes(entry));
340
+ return invalid.length ? false : requested;
341
+ },
329
342
  // client_credentials grant: treat the client as the resource owner.
330
343
  getUserFromClient: (client) => ({ id: client.id, type: "client" })
331
344
  });
package/package.json CHANGED
@@ -164,5 +164,5 @@
164
164
  "test": "node --test test/"
165
165
  },
166
166
  "types": "dist/index.d.ts",
167
- "version": "0.0.82"
167
+ "version": "0.0.83"
168
168
  }