Skip to content

Commit

Permalink
Merge pull request #6610 from MicrosoftDocs/main
Browse files Browse the repository at this point in the history
Merge main to live, 4 AM
  • Loading branch information
v-ccolin authored Jan 20, 2025
2 parents b701ef1 + ebda831 commit 543fbfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Call an API from an Angular single-page app in a Microsoft Entra te
author: henrymbuguakiarie
manager: mwongerapk
ms.author: henrymbugua
ms.date: 11/11/2024
ms.date: 01/20/2025
ms.reviewer: ejahjaloo
ms.service: identity-platform

Expand All @@ -30,23 +30,6 @@ In this tutorial:

To configure your Angular application to interact with the Microsoft Graph API, complete the following steps:

1. Open the `src/app/app.module.ts` file and add the following code snippet:

```typescript
// MSAL Interceptor is required to request access tokens in order to access the protected resource (Graph)
export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
const protectedResourceMap = new Map<string, Array<string>>();
protectedResourceMap.set('https://graph.microsoft.com/v1.0/me', ['user.read']);

return {
interactionType: InteractionType.Redirect,
protectedResourceMap
};
}
```

The `MSALInterceptorConfigFactory` function configures the MSAL Interceptor to request access tokens for protected resources. It creates a `protectedResourceMap`, linking the Microsoft Graph API endpoint `https://graph.microsoft.com/v1.0/me` with the `user.read` permission. The function then returns an `MsalInterceptorConfiguration` that specifies `Redirect` for `interactionType` and includes the `protectedResourceMap`, allowing the interceptor to add access tokens to API requests automatically.

1. Open the `src/app/profile/profile.component.ts` file and replace the contents with the following code snippet:

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Prepare an Angular Single-page Application in a Microsoft Entra ten
author: henrymbuguakiarie
manager: mwongerapk
ms.author: henrymbugua
ms.date: 11/11/2024
ms.date: 01/20/2025
ms.reviewer: ejahjaloo
ms.service: identity-platform

Expand Down Expand Up @@ -163,6 +163,17 @@ We'll use the values recorded during the app registration to configure the appli
}
});
}

// MSAL Interceptor is required to request access tokens in order to access the protected resource (Graph)
export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
const protectedResourceMap = new Map<string, Array<string>>();
protectedResourceMap.set('https://graph.microsoft.com/v1.0/me', ['user.read']);

return {
interactionType: InteractionType.Redirect,
protectedResourceMap
};
}

// MSAL Guard is required to protect routes and require authentication before accessing protected routes
export function MSALGuardConfigFactory(): MsalGuardConfiguration {
Expand Down

0 comments on commit 543fbfc

Please sign in to comment.