This folder contains a sample project demonstrating Microsoft Identity CIAM (Customer Identity and Access Management) integration using Angular with native authentication and a CORS proxy.
This sample app leverages the @azure/msal-browser/custom-auth SDK to implement secure, standards-based native authentication flows with Microsoft Identity CIAM. All authentication logic is handled on the client side, and API calls are securely proxied to the backend using a CORS proxy.
- New users can register using either:
- Email + password
- Email + OTP (passwordless registration)
- During registration, users provide required attributes such as first name, last name, job title, city, country, email, and password (if applicable).
- The sign-up flow may include email verification or additional steps as required by the backend.
- After successful registration, the app automatically continues to sign in the user.
- During the automatic sign-in after registration, users can add authentication methods (email or SMS) if no strong auth method is registered.
- Handles validation and error feedback for user input.
- Supports both password-based and passwordless authentication.
- Users sign in with their email as the username.
- Password-based: Enter email and password to authenticate.
- Passwordless: Enter email to receive a one-time passcode (OTP) for authentication.
- Multi-Factor Authentication (MFA): If MFA is required, users select a verification method and complete a second factor challenge.
- Just-In-Time (JIT) Authentication Method Registration: If no authentication method is registered, users can add one during sign-in.
- Handles authentication errors and displays appropriate messages.
- Users can initiate a self-serve password reset if they forget their password.
- The password reset flow uses email OTP for authentication and verification.
- Guides users through requesting a reset code, verifying their identity, and setting a new password.
- After successful password reset, the app automatically continues to sign in the user.
- During the automatic sign-in after password reset, users can add authentication methods if no strong auth method is registered.
- Also, during the automatic sign-in after password reset, users may be requried to complete additional verification if MFA is enabled.
- Handles errors such as invalid or expired reset codes.
- Node.js 16.x or later
- npm 7.x or later
- Clone the repository:
git clone https://github.com/Azure-Samples/ms-identity-ciam-native-javascript-samples
cd typescript/native-auth/angular-sample- Install dependencies:
npm install- Open
src/app/config/auth-config.tsand replace the following with the values obtained from the Microsoft Entra admin center:Enter_the_Application_Id_Here→ Application (client) IDEnter_the_Tenant_Subdomain_Here→ Tenant Subdomain
- Save the file.
The Native Auth APIs currently don't support Cross-Origin Resource Sharing CORS so a proxy server must be setup between the web app and the APIs.
- The included CORS proxy server (Node.js, listens on port 3001) forwards requests to the Tenant URL endpoints.
- Configure
proxy.config.jsin the project root:tenantSubdomain: Your tenant subdomain (e.g.,contosoforcontoso.onmicrosoft.com)tenantId: Your Tenant IdlocalApiPath: The endpoint called from localhost (recommended/api)port: Port for the CORS proxy (recommended3001)
- Start the CORS proxy:
npm run cors- In a new terminal, start the Angular development server:
npm run startThe app will be available at http://localhost:4200.
angular-sample/
├── cors.js # Local CORS proxy server for CORS workaround
├── package.json # Project dependencies and scripts
├── proxy.config.js # Proxy configuration for backend API
├── angular.json # Angular CLI configuration
├── tsconfig.json # TypeScript configuration
├── src/
│ ├── main.ts # Entry point for the Angular app
│ ├── styles.scss # Global styles for the app
│ └── app/
│ ├── app.component.ts # Root Angular component (logic)
│ ├── app.component.html # Root Angular component (template)
│ ├── app.component.scss # Root Angular component (styles)
│ ├── app.module.ts # Main Angular module definition
│ ├── config/
│ │ └── auth-config.ts # MSAL/CIAM authentication configuration
│ ├── services/
│ │ └── auth.service.ts # Authentication service (handles MSAL logic)
│ └── components/
│ ├── shared/ # Shared reusable components
│ │ ├── auth-method-selection-form/ # JIT auth method registration
│ │ ├── auth-method-challenge-form/ # JIT challenge verification
│ │ ├── mfa-auth-method-selection-form/ # MFA method selection
│ │ ├── mfa-challenge-form/ # MFA challenge verification
│ │ ├── code-form/ # Reusable OTP code input
│ │ └── password-form/ # Reusable password input
│ ├── navbar/
│ │ ├── navbar.component.ts # Navbar component logic
│ │ ├── navbar.component.html # Navbar component template
│ │ └── navbar.component.scss # Navbar component styles
│ ├── sign-in/
│ │ ├── sign-in.component.ts # Sign-in page with MFA and JIT support
│ │ ├── sign-in.component.html # Sign-in page template
│ │ └── sign-in.component.scss # Sign-in page styles
│ ├── sign-up/
│ │ ├── sign-up.component.ts # Sign-up page with MFA and JIT support
│ │ ├── sign-up.component.html # Sign-up page template
│ │ └── sign-up.component.scss # Sign-up page styles
│ ├── reset-password/
│ │ ├── reset-password.component.ts # Reset password page with JIT support
│ │ ├── reset-password.component.html # Reset password page template
│ │ └── reset-password.component.scss # Reset password page styles
│ ├── welcome.component.ts # Welcome/landing page logic
│ ├── welcome.component.html # Welcome/landing page template
│ └── welcome.component.scss # Welcome/landing page styles
└── ...other config and support files
- All authentication flows and UI are implemented in the
src/app/components/directory. - Shared components for JIT and MFA are consolidated in
src/app/components/shared/to promote code reuse. - Shared UI and logic are in
src/app/components/andsrc/app/services/. - The CORS proxy and configuration files are at the project root.
src/app/components/welcome.component.ts- Main landing pagesrc/app/components/navbar/navbar.component.ts- Top navigation bar- Authentication components:
src/app/components/sign-in/sign-in.component.ts- Sign-in page with MFA and JIT supportsrc/app/components/sign-up/sign-up.component.ts- Sign-up page with MFA and JIT supportsrc/app/components/reset-password/reset-password.component.ts- Password reset page with JIT support
- Shared components:
src/app/components/shared/- Reusable form components for JIT and MFA flows
- Ensure the CORS proxy is running if your frontend needs to communicate with a backend API that does not allow cross-origin requests.
- Update
proxy.config.jsas needed for your environment. - See the project
README.mdfor more specific details.
See the contributing guide to learn about our development process.
This project is licensed under the MIT License - see the LICENSE file for details.