This repository contains a sample Angular (v20) SPA integrated with an ASP.NET Web API (v8), secured using Microsoft Entra External ID. The project demonstrates authentication and API access configuration using MSAL and JwtBearer authentication.
⚠️ Note: This project is intended only for demonstration and development purposes. It is not suitable for production environments.
Before you start, make sure you have the following:
- VS Code IDE (or another code editor)
- Node.js & npm installed for Angular
- .NET SDK installed for ASP.NET Web API
- An Azure Free Tier Account
- An Entra ID (Azure AD) external tenant with two app registrations configured:
- SPA Angular UI
- ASP.NET Web API
- Angular CLI installed globally:
npm install -g @angular/cli
- Git installed for cloning the repository
git clone https://github.com/dwalterskoetter/sample-entra-angular-aspnet.gitcd API/MyApi
dotnet restorecd ../../UI/angular-ui
npm installAdd your Entra ID / Azure AD information:
"AzureAd": {
"Instance": "https://YOUR_TENANT_DOMAIN.ciamlogin.com",
"TenantId": "YOUR_TENANT_ID",
"ClientId": "YOUR_CLIENT_ID",
"Domain": "YOUR_TENANT_DOMAIN.onmicrosoft.com"
}Add your MSAL configuration:
const msalConfig = {
auth: {
clientId: "YOUR_CLIENT_ID",
authority: "https://YOUR_TENANT_DOMAIN.ciamlogin.com/",
redirectUri: "http://localhost:4200",
postLogoutRedirectUri: "http://localhost:4200",
},
cache: {
cacheLocation: BrowserCacheLocation.LocalStorage,
},
};
export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
return {
interactionType: InteractionType.Redirect,
protectedResourceMap: new Map<string, Array<string> | null>([
["http://localhost:5074/*", ["api://YOUR_CLIENT_ID/access_as_user"]],
]),
};
}cd API/MyApi
dotnet runcd ../../UI/angular-ui
ng serve- Open your browser and navigate to http://localhost:4200
- You should be able to authenticate via Entra ID and call the API securely.
- Ensure your API and UI app registrations are correctly configured in your Entra ID tenant.
- For production deployment, update CORS policies and redirect URIs accordingly.
This project is released under the MIT License.