@@ -35,6 +35,15 @@ const TEST_M2M_TOKENS: Record<string, string[]> = {
3535 'm2m-token-groups' : [ Scope . AllGroups ] ,
3636} ;
3737
38+ const SCOPE_SYNONYMS : Record < string , string [ ] > = {
39+ 'read:group' : [ Scope . ReadGroups ] ,
40+ [ Scope . ReadGroups ] : [ 'read:group' ] ,
41+ 'write:group' : [ Scope . WriteGroups ] ,
42+ [ Scope . WriteGroups ] : [ 'write:group' ] ,
43+ 'all:group' : [ Scope . AllGroups ] ,
44+ [ Scope . AllGroups ] : [ 'all:group' ] ,
45+ } ;
46+
3847@Injectable ( )
3948export class JwtService implements OnModuleInit {
4049 private jwksClientInstance : jwksClient . JwksClient ;
@@ -177,16 +186,30 @@ export class JwtService implements OnModuleInit {
177186 */
178187 private expandScopes ( scopes : string [ ] ) : string [ ] {
179188 const expandedScopes = new Set < string > ( ) ;
189+ const queue = [ ...scopes ] ;
180190
181- // Add all original scopes
182- scopes . forEach ( ( scope ) => expandedScopes . add ( scope ) ) ;
183-
184- // Expand all "all:*" scopes
185- scopes . forEach ( ( scope ) => {
186- if ( ALL_SCOPE_MAPPINGS [ scope ] ) {
187- ALL_SCOPE_MAPPINGS [ scope ] . forEach ( ( s ) => expandedScopes . add ( s ) ) ;
191+ while ( queue . length > 0 ) {
192+ const scope = queue . shift ( ) ;
193+ if ( ! scope || expandedScopes . has ( scope ) ) {
194+ continue ;
188195 }
189- } ) ;
196+
197+ expandedScopes . add ( scope ) ;
198+
199+ const synonyms = SCOPE_SYNONYMS [ scope ] ?? [ ] ;
200+ synonyms . forEach ( ( alias ) => {
201+ if ( ! expandedScopes . has ( alias ) ) {
202+ queue . push ( alias ) ;
203+ }
204+ } ) ;
205+
206+ const mappedScopes = ALL_SCOPE_MAPPINGS [ scope ] ?? [ ] ;
207+ mappedScopes . forEach ( ( alias ) => {
208+ if ( ! expandedScopes . has ( alias ) ) {
209+ queue . push ( alias ) ;
210+ }
211+ } ) ;
212+ }
190213
191214 return Array . from ( expandedScopes ) ;
192215 }
0 commit comments