Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ionic 7 Microsoft SSO Integration

Complete implementation of Microsoft Azure Entra ID Single Sign-On (SSO) for Ionic 7 hybrid mobile applications.

🎯 Features

  • βœ… 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

πŸ“‹ Prerequisites

  • 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

πŸš€ Quick Start

1. Clone and Install

git clone https://github.com/adil-Pathan/ionic-microsoft-sso.git
cd ionic-microsoft-sso
npm install

2. Configure Azure Entra ID

See IMPLEMENTATION_GUIDE.md for detailed Azure setup.

3. Update Configuration

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'
};

4. Setup Backend API

See BACKEND_API.md for Node.js/Express implementation.

5. Platform-Specific Setup

6. Build and Run

# 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 ios

πŸ“ Project Structure

src/
β”œβ”€β”€ 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

πŸ” Key Components

AuthService

Handles all authentication logic:

login(): void
logout(): Observable<void>
refreshToken(): Observable<AuthToken>
isAuthenticated(): Observable<boolean>
getAccessToken(): string | null
getUserProfile(): UserProfile | null

AuthInterceptor

Automatically attaches access token to all HTTP requests and handles token refresh on 401 errors.

AuthGuard

Protects routes requiring authentication. Redirects to login if not authenticated.

πŸ”‘ Environment Variables

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

πŸ“± Supported Platforms

  • βœ… Android 7+
  • βœ… iOS 14+
  • βœ… Web (development only)

πŸ”„ Authentication Flow

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

πŸ›‘οΈ Security Features

  • 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

πŸ“š API Endpoints

Backend should implement:

  • POST /api/auth/token - Exchange auth code for token
  • POST /api/auth/refresh - Refresh access token
  • GET /api/user/profile - Get user profile

See BACKEND_API.md for implementation details.

πŸ› Troubleshooting

See TROUBLESHOOTING.md for common issues and solutions.

Common issues:

  • Redirect URI mismatch
  • Token expiration
  • CORS errors
  • Deep linking issues
  • localStorage availability

πŸ“– Documentation

🀝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/your-feature
  3. Commit changes: git commit -m 'Add your feature'
  4. Push to branch: git push origin feature/your-feature
  5. Submit pull request

πŸ“„ License

MIT License - feel free to use this in your projects

πŸ’‘ Tips

  1. Always test on physical devices, not just emulators
  2. Keep tokens secure - never log them to console in production
  3. Implement proper error handling and user feedback
  4. Use HTTPS for all API communication
  5. Regularly update dependencies
  6. Test the logout flow thoroughly

πŸ”— Resources

πŸ“ž Support

For issues and questions:

  1. Check Troubleshooting Guide
  2. Review Azure Activity Logs
  3. Check browser console for errors
  4. Open an issue on GitHub

Version: 1.0.0
Last Updated: 2026-05-08
Maintainer: adil-Pathan

About

Microsoft Azure Entra ID SSO integration for Ionic 7 hybrid mobile app

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages