Overview

Universal Windows Platform application developed for Microsoft DX (Developer Experience) Readiness initiative. Demonstrates Microsoft Graph API integration by crawling Office 365 organizational directory, retrieving user profiles and photos, and displaying them in an adaptive UWP interface.

Served as reference implementation for enterprise developers learning Microsoft Graph API.

Architecture

Authentication Layer

  • Azure Active Directory authentication via ADAL (Active Directory Authentication Library)
  • OAuth 2.0 authorization code flow
  • Token caching with automatic refresh
  • Multi-tenant support (configurable tenant ID)

Microsoft Graph Integration

  • GraphServiceClient for API calls
  • User directory queries: GET /users
  • Individual user retrieval: GET /users/{id}
  • Profile photo download: GET /users/{id}/photo/$value
  • Batch operations for efficient data retrieval

UWP Application Structure

  • MainPage: User list view with authentication flow
  • UserDisplayPage: Master-detail split view for user profiles
  • UserOperations: Business logic for Graph API calls
  • NavigationHelper: Page navigation and state management
  • ObservableDictionary: Data binding for XAML views

Adaptive UI

  • Responsive layout for desktop/tablet/phone
  • Window size change detection
  • Dynamic single-pane/dual-pane switching
  • Progress indicators for async operations

Technical Implementation

ADAL Authentication Flow: Used AcquireTokenAsync() with force prompt for initial signin. Token stored in ADAL token cache with automatic refresh handling. Implemented error handling for expired tokens, revoked permissions, and network failures.

Graph API Calls: Used HttpClient with bearer token authentication. Example GET /users query returns IUserCollectionPage with pagination support. Implemented continuation token handling for large directories (10,000+ users).

Profile Photo Handling: GET /users/{id}/photo/$value returns raw image stream. Converted to BitmapImage for XAML Image control display. Implemented fallback to default avatar when photo unavailable (HTTP 404 response).

Async/Await Pattern: All Graph API calls use async/await to prevent UI blocking. Progress indicators (ProgressBar/ProgressRing) shown during operations. Implemented cancellation tokens for long-running operations.

Error Handling: Wrapped Graph calls in try/catch for ServiceException. Handled common errors: 401 Unauthorized (token expired), 403 Forbidden (insufficient permissions), 429 Too Many Requests (throttling). Implemented exponential backoff for retry logic.

Technical Challenges

API Permissions: Microsoft Graph requires specific permission scopes. User.ReadBasic.All sufficient for name and photo, but User.Read.All required for full profile data (manager, department, office location). Admin consent needed for tenant-wide read permissions.

Photo Retrieval Performance: Downloading 100+ user photos sequentially caused UI lag. Implemented concurrent async downloads with SemaphoreSlim to limit parallelism (max 10 concurrent). Cached photos in local storage to avoid repeated downloads.

Token Expiration: ADAL tokens expire after 1 hour. Initial implementation required re-authentication. Fixed by using AcquireTokenSilentAsync() which automatically refreshes using cached refresh token. Only prompts user if refresh token expired (90 days).

Pagination Handling: Large organizations have 10,000+ users. Graph API returns 100 users per page with @odata.nextLink for continuation. Implemented “Load More” button instead of auto-loading all users to prevent memory issues.

Results

Successfully demonstrated Microsoft Graph API capabilities for enterprise directory access. Application retrieves and displays user profiles with sub-second response time for typical organizations (< 1000 users). Served as reference code for Microsoft partner training sessions.

Used in DX Readiness workshops to teach developers about Azure AD authentication, Microsoft Graph API patterns, and UWP development best practices.

Tech Stack

  • Platform: Universal Windows Platform (UWP), Windows 10
  • Language: C#, XAML
  • APIs: Microsoft Graph API v1.0, Azure Active Directory Authentication Library (ADAL)
  • Framework: .NET Framework 4.6, Windows 10 SDK (10240+)
  • NuGet Packages: Microsoft.Graph, Microsoft.IdentityModel.Clients.ActiveDirectory

Source Code

Code will be available on GitHub at: https://github.com/tanchunsiong/o365-photo-crawler

Project Created: 2015-2016


Connect: