Complete implementation of Microsoft Azure Entra ID Single Sign-On (SSO) for Ionic 7 hybrid mobile applications.
- β Microsoft/Azure Entra ID authentication
- β Hybrid mobile app support (Android & iOS)
- β Secure token management
- β Automatic token refresh
- β HTTP interceptor for token attachment
- β Auth guard for protected routes
- β User profile retrieval from Microsoft Graph
- β Deep linking support
- Node.js 16+ and npm
- Ionic 7 CLI
- Angular 16+
- iOS development tools (for iOS builds)
- Android SDK (for Android builds)
- Azure Entra ID tenant access
git clone https://github.com/adil-Pathan/ionic-microsoft-sso.git
cd ionic-microsoft-sso
npm installSee IMPLEMENTATION_GUIDE.md for detailed Azure setup.
Edit src/environments/environment.ts:
export const environment = {
production: false,
clientId: 'YOUR_CLIENT_ID',
tenantId: 'YOUR_TENANT_ID',
redirectUri: 'msauth://YOUR_APP_PACKAGE_NAME/YOUR_SIGNATURE_HASH',
authority: 'https://login.microsoftonline.com/YOUR_TENANT_ID',
msGraph: 'https://graph.microsoft.com/v1.0'
};See BACKEND_API.md for Node.js/Express implementation.
- Android: See ANDROID_SETUP.md
- iOS: See iOS_SETUP.md
# Web development
ionic serve
# Android
ionic build
npx cap sync android
npx cap open android
# iOS
ionic build
npx cap sync ios
npx cap open iossrc/
βββ app/
β βββ services/
β β βββ auth.service.ts # Main authentication service
β βββ interceptors/
β β βββ auth.interceptor.ts # HTTP token interceptor
β βββ guards/
β β βββ auth.guard.ts # Route protection guard
β βββ pages/
β β βββ login/
β β β βββ login.page.ts
β β β βββ login.page.html
β β β βββ login.page.scss
β β βββ home/
β β βββ home.page.ts
β β βββ home.page.html
β βββ app-routing.module.ts
β βββ app.module.ts
βββ environments/
β βββ environment.ts # Configuration
β βββ environment.prod.ts
docs/
βββ IMPLEMENTATION_GUIDE.md # Complete setup guide
βββ ANDROID_SETUP.md # Android configuration
βββ iOS_SETUP.md # iOS configuration
βββ BACKEND_API.md # Backend implementation
βββ TROUBLESHOOTING.md # Common issues
Handles all authentication logic:
login(): void
logout(): Observable<void>
refreshToken(): Observable<AuthToken>
isAuthenticated(): Observable<boolean>
getAccessToken(): string | null
getUserProfile(): UserProfile | nullAutomatically attaches access token to all HTTP requests and handles token refresh on 401 errors.
Protects routes requiring authentication. Redirects to login if not authenticated.
Create .env in backend:
AZURE_CLIENT_ID=your_client_id
AZURE_CLIENT_SECRET=your_client_secret
AZURE_TENANT_ID=your_tenant_id
AZURE_AUTHORITY=https://login.microsoftonline.com/your_tenant_id- β Android 7+
- β iOS 14+
- β Web (development only)
1. User clicks "Sign in with Microsoft"
2. App opens Microsoft login in browser
3. User enters credentials
4. Microsoft redirects to app with auth code
5. App exchanges code for access token (via backend)
6. App fetches user profile from Microsoft Graph
7. User is authenticated and logged in
- Secure token storage with encryption
- Automatic token refresh before expiration
- Backend token validation
- CORS protection
- Secure HTTP-only cookies (for web)
- Logout clears all sensitive data
Backend should implement:
POST /api/auth/token- Exchange auth code for tokenPOST /api/auth/refresh- Refresh access tokenGET /api/user/profile- Get user profile
See BACKEND_API.md for implementation details.
See TROUBLESHOOTING.md for common issues and solutions.
Common issues:
- Redirect URI mismatch
- Token expiration
- CORS errors
- Deep linking issues
- localStorage availability
- Fork the repository
- Create feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -m 'Add your feature' - Push to branch:
git push origin feature/your-feature - Submit pull request
MIT License - feel free to use this in your projects
- Always test on physical devices, not just emulators
- Keep tokens secure - never log them to console in production
- Implement proper error handling and user feedback
- Use HTTPS for all API communication
- Regularly update dependencies
- Test the logout flow thoroughly
- Azure Entra ID Documentation
- Ionic Documentation
- Angular Documentation
- Microsoft Graph API
- OAuth 2.0 Specification
For issues and questions:
- Check Troubleshooting Guide
- Review Azure Activity Logs
- Check browser console for errors
- Open an issue on GitHub
Version: 1.0.0
Last Updated: 2026-05-08
Maintainer: adil-Pathan