Automatic synchronization of organizational hierarchy (manager-subordinate relationships) from Microsoft Entra ID to GLPI.
- ✅ OAuth 2.0 Single Sign-On - Login to GLPI using Microsoft Entra ID credentials
- ✅ Automatic SSO Redirect (v1.4.0+) - Configurable auto-redirect to Microsoft login (never/cookie/always modes)
- ✅ Automatic User Provisioning - Create GLPI users from Entra ID (sync + SSO)
- ✅ Manager-Subordinate Sync - Automatically set
users_id_supervisorfrom Entra ID manager - ✅ Advanced Filtering - Filter users by account status, user type, employee type, job title, department, company
- ✅ Account Status Sync - Synchronize
accountEnabledfrom Entra ID to GLPIis_activefield - ✅ Deleted User Handling - Configurable actions (keep active/deactivate/delete) for users removed from Entra ID
- ✅ Scheduled Synchronization - Cron task runs every 30 minutes (configurable)
- ✅ Manual Override Support - Prevent auto-sync for manually set supervisors
- ✅ Detailed Logging - Track all sync operations and failures
- ✅ Connection Testing - Test Microsoft Graph API credentials before saving
- ✅ CSRF Protection - Secure OAuth state validation with session-based CSRF tokens
- ✅ Emergency Admin Access - Bypass SSO redirect with
?no_sso=1parameter
- GLPI >= 11.0
- PHP >= 8.2
- PHP curl extension
- Microsoft Entra ID tenant with admin access
cd /var/www/html/glpi/plugins
git clone https://github.com/lukaskraic/glpi-entra-hierarchy.git glpientrahierarchy
# ⚠️ Important: Specify target folder name 'glpientrahierarchy' (no hyphens)
# OR manually download and extract to plugins/glpientrahierarchy/chown -R www-data:www-data /var/www/html/glpi/plugins/glpientrahierarchy
chmod -R 755 /var/www/html/glpi/plugins/glpientrahierarchy- Login to GLPI as administrator
- Go to Setup → Plugins
- Find Entra Hierarchy Sync in the list
- Click Install
- Click Enable
- Go to Azure Portal
- Navigate to Microsoft Entra ID → App registrations
- Click New registration
- Enter application name:
GLPI Hierarchy Sync - Select Accounts in this organizational directory only
- Click Register
- Copy Application (client) ID
- Copy Directory (tenant) ID
- Go to Certificates & secrets
- Click New client secret
- Add description:
GLPI Sync Secret - Select expiration (recommended: 24 months)
- Click Add
- Copy the secret value immediately (you won't see it again!)
- Go to API permissions
- Click Add a permission
- Select Microsoft Graph
- Select Application permissions
- Add the following permissions:
User.Read.All- Read all users' full profilesDirectory.Read.All- Read directory data
- Click Add permissions
- Click Add a permission again
- Select Microsoft Graph
- Select Delegated permissions
- Add the following permissions:
openid- Sign users inprofile- View users' basic profileemail- View users' email addressUser.Read- Sign in and read user profile
- Click Add permissions
- Click Grant admin consent for [Your Organization]
- Confirm by clicking Yes
- Go to Authentication
- Click Add a platform → Web
- Add Redirect URI:
https://your-glpi-domain.com/plugins/glpientrahierarchy/front/oauth_callback.php- Replace
your-glpi-domain.comwith your actual GLPI URL - Use
http://localhostfor development/testing
- Replace
- Enable ID tokens under Implicit grant and hybrid flows
- Click Configure
- Click Save
- Go to Setup → Plugins → Entra Hierarchy Sync → Configuration
- Enter the credentials from Azure:
- Client ID - From app registration
- Client Secret - The secret value you copied
- Tenant ID - From app registration
- Click Test connection to verify credentials
-
Enable OAuth SSO:
- Check Enable OAuth 2.0 SSO
- Enter Redirect URI:
https://your-glpi-domain.com/plugins/glpientrahierarchy/front/oauth_callback.php- Must match the Redirect URI configured in Entra ID App Registration
- Click Test OAuth Configuration to verify SSO setup
- Important: Ensure the Redirect URI in Entra ID matches exactly (including protocol and path)
-
Configure Auto-Redirect to Microsoft SSO (v1.4.0+):
- Select auto-redirect mode from dropdown:
- Never - Show GLPI login form (default, users manually click Microsoft button)
- If previously used - Auto-redirect users who previously used Microsoft login (cookie-based)
- Always - Force all users to Microsoft SSO, bypass GLPI login form entirely
- Emergency access: Use
?no_sso=1parameter to bypass auto-redirect- Example:
https://your-glpi-domain.com/index.php?no_sso=1 - Allows admin access even when "Always" mode is enabled
- Example:
- Select auto-redirect mode from dropdown:
-
SSO User Matching:
- Users are matched by:
- Existing Entra ID mapping (
glpi_plugin_entrahierarchy_usermaps) - GLPI username matching Entra ID UPN
- GLPI username matching Entra ID email
- Existing Entra ID mapping (
- New users are automatically created on first SSO login (if sync is enabled)
- User profile is updated from Entra ID on each login
- Users are matched by:
- Enable automatic synchronization
- Set synchronization interval (default: 1800 seconds = 30 minutes)
- Configure user filters (optional):
- Sync only active users - Skip users with
accountEnabled = false - Require account enabled - Only sync users with enabled accounts
- User type filter - Filter by Member, Guest, etc.
- Employee types - Comma-separated list (e.g., "Employee,Contractor")
- Require job title - Only sync users with a job title
- Department filter - Only sync specific department
- Company name filter - Only sync specific company
- Sync only active users - Skip users with
- Configure deleted user handling:
- Keep active - Do nothing when user is deleted from Entra ID (default)
- Deactivate - Set
is_active = 0in GLPI - Delete - Remove user from GLPI
⚠️ Note: Only affects users synced from Entra ID (with mapping). Local GLPI users are never affected.
- Click Save configuration
- Navigate to your GLPI login page
- Click "Sign in with Microsoft" button (below standard login form)
- Redirected to Microsoft Entra ID authentication
- Enter Microsoft credentials (if not already signed in)
- Grant consent (first time only)
- Automatically logged into GLPI
- CSRF Protection: OAuth state parameter validated against session token
- Secure Token Handling: Access tokens never exposed to browser
- Session Integration: Standard GLPI session management
- Auto User Creation: New users created on first SSO login (if sync enabled)
- Profile Updates: User profile synchronized from Entra ID on each login
The plugin supports two complementary workflows:
-
Scheduled Sync (Background):
- Runs via cron every 30 minutes (configurable)
- Creates/updates all users in bulk
- Sets manager-subordinate relationships
- Handles deleted users
-
SSO Login (On-Demand):
- User logs in via Microsoft button
- User profile created/updated from Entra ID
- Session established immediately
- No need to wait for scheduled sync
- Fetch Users - Retrieves all users from Entra ID via Microsoft Graph API
- Apply Filters - Filters users based on configuration (account status, user type, department, etc.)
- Find or Create - Matches Entra ID users to GLPI users (by UPN or email)
- Create Missing Users - Creates new GLPI users for unmapped Entra ID users
- Sync Account Status - Synchronizes
accountEnabledfrom Entra ID to GLPIis_activefield - Sync Managers - For each user, fetches their manager from Entra ID
- Update Supervisors - Sets
users_id_supervisorin GLPI to match Entra ID hierarchy - Handle Deleted Users - Processes users deleted from Entra ID (based on configuration)
- Log Results - Records sync statistics including filtered, created, updated, deactivated, deleted counts
The plugin matches Entra ID users to GLPI users using:
- Existing mapping in
glpi_plugin_entrahierarchy_usermapstable - GLPI username matching Entra ID
userPrincipalName - GLPI username matching Entra ID
mail
If you manually set a user's supervisor in GLPI and want to prevent auto-sync from changing it:
UPDATE glpi_plugin_entrahierarchy_usermaps
SET manual_supervisor = 1
WHERE users_id = [USER_ID];The plugin detects users that have been deleted or removed from Entra ID by comparing the last_sync timestamp:
- During Sync - Each successfully synced user's
last_synctimestamp is updated - After Sync - Users with
last_syncolder than current sync start time are considered deleted from Entra ID - Action Applied - Based on configuration, these users are either:
- Left active (default)
- Deactivated (
is_active = 0) - Deleted from GLPI
Safety: Only users with Entra ID mapping are affected. Local GLPI users without mapping are never touched.
- Go to Setup → Automatic actions
- Find SyncEntraHierarchy task
- Click Execute
docker exec -u www-data glpi-app php /var/www/html/glpi/front/cron.php --force 'GlpiPlugin\EntraHierarchy\EntraSync-SyncEntraHierarchy'View synchronization history:
SELECT * FROM glpi_plugin_entrahierarchy_synclogs
ORDER BY date DESC LIMIT 10;View Entra ID to GLPI user mappings:
SELECT
u.name as glpi_username,
m.entra_upn,
m.entra_email,
m.last_sync,
m.manual_supervisor
FROM glpi_plugin_entrahierarchy_usermaps m
JOIN glpi_users u ON m.users_id = u.id
ORDER BY m.last_sync DESC;SELECT * FROM glpi_crontasks
WHERE itemtype = 'GlpiPlugin\\EntraHierarchy\\EntraSync';Error: "Invalid OAuth state" or "CSRF token mismatch"
Solutions:
- Clear browser cookies and try again
- Check PHP session is working:
session_start()in PHP - Verify
session.save_pathis writable inphp.ini - Check GLPI logs:
/var/www/html/glpi/files/_log/php-errors.log
Error: "Invalid Redirect URI" from Microsoft
Solutions:
- Verify Redirect URI in plugin config matches Entra ID App Registration
- Check for trailing slashes (should not have one)
- Ensure protocol matches (http vs https)
- Example:
https://glpi.example.com/plugins/glpientrahierarchy/front/oauth_callback.php
Error: "User not found" after successful Microsoft login
Solutions:
- Enable automatic user creation in plugin configuration
- Check user filters aren't too restrictive
- Verify user exists in Entra ID with proper attributes (email, UPN)
- Check sync logs:
SELECT * FROM glpi_plugin_entrahierarchy_synclogs
Issue: Can't access GLPI after enabling "Always" mode
Solution: Use emergency access URL: https://your-glpi-domain.com/index.php?no_sso=1
Issue: Auto-redirect not working
Solutions:
- Check JavaScript is enabled in browser
- Clear browser cache and cookies
- Verify
oauth_auto_redirectconfiguration in database - Open browser console (F12) and check for debug messages
Issue: Auto-redirect happens but shouldn't
Solutions:
- Check auto-redirect mode in plugin configuration
- Delete
glpi_entra_sso_preferredcookie from browser - Verify no browser cache is being used (hard refresh: Ctrl+Shift+R)
Error: "Connection failed. Please check your credentials."
Solutions:
- Verify Client ID, Client Secret, and Tenant ID are correct
- Check that API permissions were granted admin consent
- Ensure client secret has not expired
- Check GLPI server can reach
https://login.microsoftonline.comandhttps://graph.microsoft.com
Check:
- Is sync enabled in configuration?
- Check cron task status:
Setup → Automatic actions - View sync logs:
SELECT * FROM glpi_plugin_entrahierarchy_synclogs - Check PHP error log:
/var/www/html/glpi/files/_log/php-errors.log
Possible causes:
- Manager user doesn't exist in GLPI yet (will be created on next sync)
- Manager user not properly mapped (check
glpi_plugin_entrahierarchy_usermaps) - Manual supervisor override is enabled
Check mapping:
SELECT u.name, m.entra_upn, m.manual_supervisor
FROM glpi_users u
JOIN glpi_plugin_entrahierarchy_usermaps m ON u.id = m.users_id
WHERE u.id = [USER_ID];Configuration settings table:
client_id,client_secret,tenant_id- Azure app credentialssync_enabled,sync_interval- Synchronization settingssync_filter_*- User filtering options (7 filters)deleted_users_action- Action for deleted Entra users (keep_active/deactivate/delete)oauth_enabled- Enable/disable OAuth 2.0 SSO (v1.3.0+)oauth_redirect_uri- OAuth callback URL for SSO (v1.3.0+)oauth_auto_redirect- Auto-redirect mode: never/cookie/always (v1.4.0+)
Maps GLPI users to Entra ID users:
users_id- GLPI user IDentra_id- Entra ID user object IDentra_upn,entra_email- User identifiersentra_display_name,entra_job_title,entra_department,entra_company_name- User detailsentra_office_location,entra_mobile_phone,entra_business_phones- Contact infoentra_employee_id,entra_employee_type- Employment detailsentra_user_type- Member/Guest typeentra_account_enabled- Account status from Entra IDmanual_supervisor- Flag to prevent supervisor auto-synclast_sync- Timestamp of last synchronization (used for deleted user detection)
Logs all synchronization operations:
status,message- Sync resultusers_synced,users_created,users_updated,users_failed- Sync statisticsusers_deactivated,users_deleted- Deleted user handling statisticsduration- Sync execution time
Microsoft Graph API has rate limits:
- 10,000 requests per 10 minutes per application
For large organizations (1000+ users), the plugin handles pagination automatically.
- ✅ Client secret stored in database (consider encrypting at rest)
- ✅ API permissions follow least privilege principle
- ✅ Uses OAuth 2.0 Client Credentials flow
- ✅ No user passwords stored or transmitted
- Go to Setup → Plugins
- Click Uninstall on Entra Hierarchy Sync
- Confirm deletion
Note: This will remove:
- All plugin database tables
- User mappings (GLPI users remain intact)
- Sync logs
- Cron task registration
- GitHub Issues: https://github.com/yourorg/glpientrahierarchy/issues
- GLPI Forum: https://forum.glpi-project.org
GPLv2+
Entra Hierarchy Development Team
1.4.2 - Critical Bug Fix: OAuth Columns Missing in Fresh Installation
- v1.4.2 (2025-11-13) - Critical bug fix: Added missing OAuth columns in fresh installation schema
- v1.4.0 (2025-01-21) - Automatic SSO redirect, cookie-based preference, emergency admin access
- v1.3.0 (2025-01-20) - OAuth 2.0 SSO, CSRF protection, automatic user provisioning on login
- v1.1.0 (2024-10-17) - Advanced filtering and deleted user handling
- v1.0.0 (2024-10-16) - Initial release with hierarchy synchronization