This repository is a Schematic implementation that serves as a starting point for an authorized angular application using MSAL.js v5 to authenticate to an Azure resource. This will get you quickly started on creating a cloud ready Angular application.
- Angular 18 or newer (MSAL v5 drops support for Angular 17 and below)
- No Server-Side Rendering or Static Site Generation (for now)
- An Azure AD application registration (see below)
-
Run the schematic in your Angular project (View the package here):
ng add azure-msal-auth-schematic
-
The CLI will prompt you for:
clientId: Your Azure AD Application (client) IDtenantId: Your Azure AD Directory (tenant) IDapiUrl: The URL of your protected APIapiScope: The API scope to request
-
The schematic will:
- Add MSAL v5 dependencies to your
package.json - Overwrite
src/app/app.config.tsto register MSAL providers - Generate:
src/app/services/authentication.service.tssrc/app/environments/environment.ts(pre-populated with your values)src/app/environments/environment.prod.tssrc/app/app.config.authentication.tssrc/app/app.routes.ts,src/app/app.ts,src/app/app.htmlsrc/app/sample/sample.ts— an example guarded componentsrc/app/login-failed/login-failed.ts— a component shown on auth failure
- Add MSAL v5 dependencies to your
-
If you skipped the prompts, update
environment.tswith your Azure AD values:clientId: Your Azure AD Application (client) IDtenantId: Your Azure AD Directory (tenant) ID (in theauthorityURL)
- Go to the Azure Portal
- Register a new application in Azure Active Directory
- Add a redirect URI (e.g.,
http://localhost:4200/) - Copy the Application (client) ID and Directory (tenant) ID
- Update your
environment.tsaccordingly
- Ensure your project uses Angular 18+ (MSAL v5 requires Angular 18 or newer)
- If you see errors about missing modules in the schematic workspace, they are expected and will not appear in your generated Angular project
The schematic scaffolds a secure Angular app with MSAL.js v5, ready for Azure AD authentication and API calls.