@@ -15,6 +15,15 @@ import {
15
15
} from "../errors/index.js" ;
16
16
17
17
const CONFIG_SECRET_NAME = "infra-events-api-config" as const ;
18
+ const AzureRoleMapping : Record < RunEnvironment , Record < string , AppRoles [ ] > > = {
19
+ prod : {
20
+ "AutonomousWriters" : [ AppRoles . MANAGER ]
21
+ } ,
22
+ dev : {
23
+ "AutonomousWriters" : [ AppRoles . MANAGER ]
24
+ } ,
25
+ }
26
+
18
27
const GroupRoleMapping : Record < RunEnvironment , Record < string , AppRoles [ ] > > = {
19
28
prod : {
20
29
"48591dbc-cdcb-4544-9f63-e6b92b067e33" : [ AppRoles . MANAGER ] , // Infra Chairs
@@ -63,6 +72,7 @@ export type AadToken = {
63
72
unique_name : string ;
64
73
uti : string ;
65
74
ver : string ;
75
+ roles ?: string [ ] ;
66
76
} ;
67
77
const smClient = new SecretsManagerClient ( {
68
78
region : process . env . AWS_REGION || "us-east-1" ,
@@ -181,9 +191,22 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
181
191
}
182
192
}
183
193
} else {
184
- throw new UnauthenticatedError ( {
185
- message : "Could not find groups in token." ,
186
- } ) ;
194
+ if ( verifiedTokenData . roles ) {
195
+ for ( const group of verifiedTokenData . roles ) {
196
+ if ( ! AzureRoleMapping [ fastify . runEnvironment ] [ group ] ) {
197
+ continue ;
198
+ }
199
+ for ( const role of AzureRoleMapping [ fastify . runEnvironment ] [
200
+ group
201
+ ] ) {
202
+ userRoles . add ( role ) ;
203
+ }
204
+ }
205
+ } else {
206
+ throw new UnauthenticatedError ( {
207
+ message : "Could not find groups or roles in token." ,
208
+ } ) ;
209
+ }
187
210
}
188
211
if ( intersection ( userRoles , expectedRoles ) . size === 0 ) {
189
212
throw new UnauthorizedError ( {
0 commit comments