Skip to content

Commit 7ee6df3

Browse files
committed
feat: add readScope helper for extracting scopes from requests
1 parent cfc0b62 commit 7ee6df3

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ declare namespace OAuth2Server {
233233
* Additional supported grant types.
234234
*/
235235
extendedGrantTypes?: Record<string, typeof AbstractGrantType>;
236+
237+
/**
238+
* Helper function to extract scope string from the request.
239+
*/
240+
readScope?: (request: Request) => string[] | null;
236241
}
237242

238243
interface AssertionCredential {

lib/grant-types/abstract-grant-type.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AbstractGrantType {
2525
this.model = options.model;
2626
this.refreshTokenLifetime = options.refreshTokenLifetime;
2727
this.alwaysIssueNewRefreshToken = options.alwaysIssueNewRefreshToken;
28+
this.readScope = options.readScope ?? ((request) => parseScope(request.body.scope));
2829
}
2930

3031
/**
@@ -73,7 +74,7 @@ class AbstractGrantType {
7374
* Get scope from the request body.
7475
*/
7576
getScope (request) {
76-
return parseScope(request.body.scope);
77+
return this.readScope(request);
7778
}
7879

7980
/**

lib/handlers/token-handler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class TokenHandler {
6161
this.allowExtendedTokenAttributes = options.allowExtendedTokenAttributes;
6262
this.requireClientAuthentication = options.requireClientAuthentication || {};
6363
this.alwaysIssueNewRefreshToken = options.alwaysIssueNewRefreshToken !== false;
64+
this.readScope = options.readScope;
6465
}
6566

6667
/**
@@ -247,7 +248,8 @@ class TokenHandler {
247248
accessTokenLifetime: accessTokenLifetime,
248249
model: this.model,
249250
refreshTokenLifetime: refreshTokenLifetime,
250-
alwaysIssueNewRefreshToken: this.alwaysIssueNewRefreshToken
251+
alwaysIssueNewRefreshToken: this.alwaysIssueNewRefreshToken,
252+
readScope: this.readScope,
251253
};
252254

253255
return new Type(options).handle(request, client);

0 commit comments

Comments
 (0)