@@ -19,6 +19,9 @@ export class RolesGuard implements CanActivate {
1919 context . getClass ( ) ,
2020 ] ) ;
2121 if ( ! required || required . length === 0 ) return true ;
22+ const normalizedRequiredRoles = required . map ( ( role ) =>
23+ role . trim ( ) . toLowerCase ( ) ,
24+ ) ;
2225
2326 const req = context . switchToHttp ( ) . getRequest ( ) ;
2427 const user = req . authUser ;
@@ -31,24 +34,33 @@ export class RolesGuard implements CanActivate {
3134 . split ( "," )
3235 . map ( ( r : string ) => r . trim ( ) )
3336 . filter ( Boolean ) ;
37+ const normalizedRoles = roles . map ( ( role ) => role . toLowerCase ( ) ) ;
3438
35- const ok = roles . some ( ( r : string ) => required . includes ( r ) ) ;
39+ const ok = normalizedRoles . some ( ( role : string ) =>
40+ normalizedRequiredRoles . includes ( role ) ,
41+ ) ;
3642 if ( ok ) return true ;
3743
3844 const fallbackScopes = this . reflector . getAllAndOverride < string [ ] > (
3945 SCOPES_KEY ,
40- [ context . getHandler ( ) , context . getClass ( ) ]
46+ [ context . getHandler ( ) , context . getClass ( ) ] ,
4147 ) ;
4248
4349 if ( fallbackScopes && fallbackScopes . length > 0 ) {
50+ const normalizedFallbackScopes = fallbackScopes . map ( ( scope ) =>
51+ scope . trim ( ) . toLowerCase ( ) ,
52+ ) ;
4453 const scopes : string [ ] = Array . isArray ( user . scopes )
4554 ? user . scopes
4655 : ( user . scope || "" )
4756 . split ( " " )
4857 . map ( ( s : string ) => s . trim ( ) )
4958 . filter ( Boolean ) ;
59+ const normalizedScopes = scopes . map ( ( scope ) => scope . toLowerCase ( ) ) ;
5060
51- const scopeOk = fallbackScopes . some ( ( s ) => scopes . includes ( s ) ) ;
61+ const scopeOk = normalizedScopes . some ( ( scope ) =>
62+ normalizedFallbackScopes . includes ( scope ) ,
63+ ) ;
5264 if ( scopeOk ) return true ;
5365 }
5466
0 commit comments