Skip to content

Commit d7f9b5a

Browse files
committed
review changes
1 parent 3695ae9 commit d7f9b5a

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

5-AccessControl/1-call-api-roles/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ To provide feedback on or suggest features for Azure Active Directory, visit [Us
295295

296296
### Angular RoleGuard and protected routes for role-based access control
297297

298-
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:
298+
The client application Angular SPA has a [role.guard.ts](./SPA/src/app/role.guard.ts) component that checks whether a user belongs to the required role(s) to access a protected route (see also: [base.guard.ts](./SPA/src/app/base.guard.ts)). It does this by checking `roles` claim the ID token of the signed-in user:
299299

300300
```typescript
301301
@Injectable()
@@ -390,9 +390,9 @@ const routes: Routes = [
390390

391391
However, it is important to be aware of that no content on a browser application is **truly** secure. That is, our **RoleGuard** component is primarily responsible for rendering the correct pages and other UI elements for a user in a particular role; in the example above, we allow only users in the `TaskAdmin` role to see the `Dashboard` component. In order to **truly** protect data and expose certain REST operations to a selected set of users, we enable **RBAC** on the back-end/web API as well in this sample. This is shown next.
392392

393-
### Policy based Authorization for .NET Core web API
393+
### Policy based authorization for .NET Core web API
394394

395-
As mentioned before, in order to **truly** implement **RBAC** and secure data, this sample allows only authorized calls to our web API. We do this by defining access policies and decorating our HTTP methods with them. To do so, we first add `roles` claim as a validation parameter in `Startup.cs`, and then we create authorization policies that depends on this claim:
395+
As mentioned before, in order to **truly** implement **RBAC** and secure data, this sample allows only authorized calls to our web API. We do this by defining access policies and decorating our HTTP methods with them. To do so, we first add `roles` claim as a validation parameter in [Startup.cs](./API/TodoListAPI/Startup.cs), and then we create authorization policies that depends on this claim:
396396

397397
```csharp
398398
// See https://docs.microsoft.com/aspnet/core/security/authorization/roles for more info.
@@ -411,7 +411,7 @@ As mentioned before, in order to **truly** implement **RBAC** and secure data, t
411411
});
412412
```
413413

414-
We defined these roles in `appsettings.json` as follows:
414+
We defined these roles in [appsettings.json](./API/TodoListAPI/appsettings.json) as follows:
415415

416416
```json
417417
"Roles": {
@@ -420,7 +420,7 @@ We defined these roles in `appsettings.json` as follows:
420420
}
421421
```
422422

423-
Finally, in `TodoListController.cs`, we decorate our routes with the appropriate policy:
423+
Finally, in [TodoListController.cs](./API/TodoListAPI/Controllers/TodoListController.cs), we decorate our routes with the appropriate policy:
424424

425425
```csharp
426426
// GET: api/todolist/getAll

5-AccessControl/1-call-api-roles/SPA/src/app/app.component.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ a.title {
77
}
88

99
footer {
10-
position: absolute;
10+
position: fixed;
11+
left: 0;
1112
bottom: 0;
1213
width: 100%;
14+
color: white;
15+
text-align: center;
1316
}
1417

1518
.footer-text {

5-AccessControl/1-call-api-roles/SPA/src/app/base.guard.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import { Observable, of } from "rxjs";
1212
import { MsalBroadcastService, MsalGuardConfiguration, MSAL_GUARD_CONFIG, MsalService } from "@azure/msal-angular";
1313
import { InteractionType, BrowserConfigurationAuthError, BrowserUtils, UrlString, PopupRequest, RedirectRequest, AuthenticationResult } from "@azure/msal-browser";
1414

15+
/**
16+
* Guard for protecting routes that require authentication. You can extend it to create custom route guards.
17+
* This class is based on MsalGuard from msal-angular. For more information, visit:
18+
* https://azuread.github.io/microsoft-authentication-library-for-js/ref/classes/_azure_msal_angular.msalguard.html)
19+
*/
1520
@Injectable()
1621
export class BaseGuard implements CanActivate, CanActivateChild, CanLoad {
1722
private loginFailedRoute?: UrlTree;

5-AccessControl/1-call-api-roles/SPA/src/app/dashboard/dashboard.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<mat-card class="card-section" *ngFor="let tb of table" class='card-section'>
2-
<mat-card-title>{{tb.owner}}</mat-card-title>
2+
<mat-card-title>Owner: {{tb.owner}}</mat-card-title>
33
<ol>
44
<li *ngFor="let task of tb.tasks">{{task.description}}</li>
55
</ol>

5-AccessControl/1-call-api-roles/SPA/src/app/home/home.component.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#table-container {
2-
height: 500px;
32
overflow: auto;
43
}
54

0 commit comments

Comments
 (0)