You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Description": "Admins can read any user's todo list"
39
-
},
40
-
{
41
-
"AllowedMemberTypes": [
42
-
"User"
43
-
],
44
-
"Name": "TaskUser",
45
-
"Description": "Users can read and modify their todo lists"
46
-
}
47
-
],
48
-
"ManualSteps": [
49
-
{
50
-
"Comment": "To receive the 'roles' claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this SPA app. The guide, https://aka.ms/userassignmentrequired provides step by step instructions."
51
-
},
52
-
{
53
-
"Comment": "Or you can run the .\\CreateUsersAndAssignRoles.ps1 command to automatically create a number of users, and assign these users to the app roles of this app."
"Description": "Admins can read any user's todo list"
52
+
},
53
+
{
54
+
"AllowedMemberTypes": [
55
+
"User"
56
+
],
57
+
"Name": "TaskUser",
58
+
"Description": "Users can read and modify their todo lists"
59
+
}
60
+
],
61
+
"OptionalClaims": {
62
+
"IdTokenClaims": [
63
+
"acct"
64
+
]
65
+
},
66
+
"ManualSteps": [
67
+
{
68
+
"Comment": "To receive the 'roles' claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this SPA app. The guide, https://aka.ms/userassignmentrequired provides step by step instructions."
69
+
},
70
+
{
71
+
"Comment": "Or you can run the .\\CreateUsersAndAssignRoles.ps1 command to automatically create a number of users, and assign these users to the app roles of this app."
Copy file name to clipboardExpand all lines: 5-AccessControl/1-call-api-roles/README.md
+45-19Lines changed: 45 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,6 @@ In the sample, a **dashboard** component allows signed-in users to see the tasks
38
38
39
39
> :information_source: See the community call: [Implement authorization in your applications with the Microsoft identity platform](https://www.youtube.com/watch?v=LRoc-na27l0)
40
40
41
-
42
41
> :information_source: See the community call: [Deep dive on using MSAL.js to integrate Angular single-page applications with Azure Active Directory](https://www.youtube.com/watch?v=EJey9KP1dZA)
43
42
44
43
## Scenario
@@ -213,6 +212,15 @@ To add users to this app role, follow the guidelines here: [Assign users and gro
213
212
214
213
For more information, see: [How to: Add app roles in your application and receive them in the token](https://docs.microsoft.com/azure/active-directory/develop/howto-add-app-roles-in-azure-ad-apps)
215
214
215
+
##### (Optional) Configure Optional Claims
216
+
217
+
1. Still on the same app registration, select the **Token configuration** blade to the left.
218
+
1. Select **Add optional claim**:
219
+
1. Select **optional claim type**, then choose **Access**.
220
+
1. Select the optional claim **acct**.
221
+
> Provides user's account status in tenant. If the user is a member of the tenant, the value is 0. If they're a guest, the value is 1.
222
+
1. Select **Add** to save your changes.
223
+
216
224
##### Configure the client app (msal-angular-app) to use your app registration
217
225
218
226
Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.
@@ -288,41 +296,61 @@ To provide feedback on or suggest features for Azure Active Directory, visit [Us
288
296
289
297
### Angular RoleGuard and protected routes for role-based access control
290
298
291
-
The client application Angular SPA has a **RoleGuard** (`role.guard.ts`) component that checks whether a user has the right privileges to access a protected route. It does this by checking `roles` claim the ID token of the signed-in user:
299
+
The client application Angular SPA has a [role.guard.ts](./SPA/src/app/role.guard.ts) component that checks whether a user has the right privileges to access a protected route. It does this by checking `roles` claim the ID token of the signed-in user:
window.alert('You do not have access as the expected role is not found. Please ensure that your account is assigned to an app role and then sign-out and sign-in again.');
309
-
returnfalse;
310
337
}
311
338
312
-
returntrue;
313
-
}
339
+
returnof(hasRequiredRole);
340
+
})
341
+
);
342
+
}
314
343
}
315
344
```
316
345
317
-
We then enable **RoleGuard** in `app-routing.module.ts` as follows:
346
+
We then enable **RoleGuard** in [app-routing.module.ts](./SPA/src/app/app-routing.module.ts) as follows:
318
347
319
348
```typescript
320
349
const routes:Routes= [
321
350
{
322
351
path: 'todo-edit/:id',
323
352
component: TodoEditComponent,
324
353
canActivate: [
325
-
MsalGuard,
326
354
RoleGuard
327
355
],
328
356
data: {
@@ -333,7 +361,6 @@ const routes: Routes = [
333
361
path: 'todo-view',
334
362
component: TodoViewComponent,
335
363
canActivate: [
336
-
MsalGuard,
337
364
RoleGuard
338
365
],
339
366
data: {
@@ -344,7 +371,6 @@ const routes: Routes = [
344
371
path: 'dashboard',
345
372
component: DashboardComponent,
346
373
canActivate: [
347
-
MsalGuard,
348
374
RoleGuard,
349
375
],
350
376
data: {
@@ -401,7 +427,7 @@ Finally, in `TodoListController.cs`, we decorate our routes with the appropriate
0 commit comments