How azuread/microsoft-authentication-library-common-for-android works
Purpose and module topology
This is the internal shared authentication foundation for ADAL and MSAL Android, not a standalone app or public API. It is a Gradle multi-module repository rooted at settings.gradle; primary Android/runtime implementation is common, while common4j holds platform-neutral Java/Kotlin primitives. Supporting test/lab clients are separate modules.
Primary entry surfaces
Consumers enter through controller/command abstractions and Android authorization/broker components rather than an executable main:
• Command orchestration: common4j/src/main/com/microsoft/identity/common/java/controllers/CommandDispatcher.java, common4j/src/main/com/microsoft/identity/common/java/commands/TokenCommand.java.
• Android routing: common/src/main/java/com/microsoft/identity/common/internal/controllers/LocalMSALController.java, common/src/main/java/com/microsoft/identity/common/internal/controllers/BrokerMsalController.java.
• Android UI/activity boundary: common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivity.java.
OAuth/OIDC provider pipeline
Provider-neutral OAuth2 request, response, PKCE, token-cache, and discovery types live in common4j; Microsoft-specific AAD, Microsoft STS, B2C, and ADFS strategies specialize them. The usual flow is command parameters → controller/strategy → authorization or token HTTP exchange → parsed token result/cache.
• common4j/src/main/com/microsoft/identity/common/java/providers/oauth2/OAuth2Strategy.java
• common4j/src/main/com/microsoft/identity/common/java/providers/microsoft/azureactivedirectory/AzureActiveDirectoryOAuth2Strategy.java
• common4j/src/main/com/microsoft/identity/common/java/providers/microsoft/microsoftsts/MicrosoftStsOAuth2Strategy.java
Android interactive authorization
Android-specific code selects browser/custom-tab/WebView flows, launches activities/fragments, validates redirects, and handles web challenges including PKeyAuth, certificate authentication, passkeys/FIDO, and browser switching. This is the boundary between protocol logic and Android UI/intent lifecycle.
• common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AndroidAuthorizationStrategy.java
• common/src/main/java/com/microsoft/identity/common/internal/ui/browser/BrowserAuthorizationStrategy.java
• common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/ChallengeFactory.java
Broker and device-registration boundary
Broker operation adapts SDK requests/results and dispatches cross-process calls through Android AccountManager, bound services, and content providers, with validation and fallback strategies. AIDL declares service contracts. Device registration is a related IPC/protocol subsystem.
• common/src/main/java/com/microsoft/identity/common/internal/broker/BrokerRequest.java
• common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/IpcStrategyWithBackup.kt
• common/src/main/aidl/com/microsoft/identity/client/IMicrosoftAuthService.aidl
• common/src/main/java/com/microsoft/identity/deviceregistration/AndroidDeviceRegistrationClientController.java
Credentials, cache, and cryptographic storage
Account/credential DTOs and OAuth token caches are cross-platform; Android supplies SharedPreferences and Android Keystore-backed protection. Device proof-of-possession keys, JWT/JWE signing/encryption, and cache migration protect or evolve persisted authentication state.
• common4j/src/main/com/microsoft/identity/common/java/cache/MsalOAuth2TokenCache.java
• common/src/main/java/com/microsoft/identity/common/crypto/AndroidAuthSdkStorageEncryptionManager.java
• common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidDevicePopManager.java
Native authentication and observability
Native-auth models commands for sign-in, sign-up, MFA, JIT, and password reset as stateful API exchanges, alongside conventional browser-based OAuth. Logging, telemetry events, and OpenTelemetry abstractions span commands, broker calls, UI, cache, and HTTP.
• common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt
• common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthOAuth2Strategy.kt
• common4j/src/main/com/microsoft/identity/common/java/telemetry/Telemetry.java
• common4j/src/main/com/microsoft/identity/common/java/opentelemetry/OpenTelemetryHolder.java
Runtime and external dependencies
The production target is Android, implemented in Java and Kotlin with Android manifests/resources and Android IPC/Keystore/AccountManager/WebView APIs. Network traffic uses URL-connection HTTP abstractions; external identity services include Azure Active Directory/Microsoft STS, Azure AD B2C/CIAM, ADFS, and optionally Google federated sign-in. Lab and Key Vault generated API clients support integration infrastructure rather than core runtime behavior: LabApiUtilities/src/main/com/microsoft/identity/labapi/utilities/client/LabClient.java, keyvault/src/main/java/com/microsoft/identity/internal/test/keyvault/api/CertificatesApi.java.
Main entry points: OAuth2Strategy.java OAuth2 strategy · TokenCommand.java Token command · LocalMSALController.java Local MSAL controller · AndroidAuthorizationStrategy.java Android authorization strategy
Components 24
common4j protocol core
Platform-neutral command, OAuth, cache, native-auth, and telemetry primitives.
- Command dispatcher
common4j/src/main/com/microsoft/identity/common/java/controllers/CommandDispatcher.java - Token command
common4j/src/main/com/microsoft/identity/common/java/commands/TokenCommand.java - OAuth2 strategy · Provider-neutral authorization, token, PKCE, discovery, and cache flow.
common4j/src/main/com/microsoft/identity/common/java/providers/oauth2/OAuth2Strategy.java - AAD strategy
common4j/src/main/com/microsoft/identity/common/java/providers/microsoft/azureactivedirectory/AzureActiveDirectoryOAuth2Strategy.java - Microsoft STS strategy
common4j/src/main/com/microsoft/identity/common/java/providers/microsoft/microsoftsts/MicrosoftStsOAuth2Strategy.java - MSAL token cache · Cross-platform account and credential persistence.
common4j/src/main/com/microsoft/identity/common/java/cache/MsalOAuth2TokenCache.java - Native auth strategy
common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthOAuth2Strategy.kt - Telemetry
common4j/src/main/com/microsoft/identity/common/java/telemetry/Telemetry.java - OpenTelemetry holder
common4j/src/main/com/microsoft/identity/common/java/opentelemetry/OpenTelemetryHolder.java
common Android runtime
Android authorization, broker IPC, device, and secure-storage integration.
- Native auth controller · Runs stateful sign-in, sign-up, MFA, JIT, and reset exchanges.
common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt - Local MSAL controller · Routes requests through local Android authorization and token flows.
common/src/main/java/com/microsoft/identity/common/internal/controllers/LocalMSALController.java - Broker MSAL controller · Routes requests to the broker with fallback behavior.
common/src/main/java/com/microsoft/identity/common/internal/controllers/BrokerMsalController.java - Authorization activity · Android UI and intent lifecycle boundary.
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivity.java - Android authorization strategy
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AndroidAuthorizationStrategy.java - Browser authorization · Selects browser, custom-tab, or WebView authorization flow.
common/src/main/java/com/microsoft/identity/common/internal/ui/browser/BrowserAuthorizationStrategy.java - Web challenge factory · Builds PKeyAuth, certificate, passkey/FIDO, and browser-switch handlers.
common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/ChallengeFactory.java - Broker request · Adapts SDK requests and results for broker operations.
common/src/main/java/com/microsoft/identity/common/internal/broker/BrokerRequest.java - Broker IPC strategy · Dispatches broker calls with a backup strategy.
common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/IpcStrategyWithBackup.kt - Auth service AIDL
common/src/main/aidl/com/microsoft/identity/client/IMicrosoftAuthService.aidl - Device registration
common/src/main/java/com/microsoft/identity/deviceregistration/AndroidDeviceRegistrationClientController.java - Android secure storage · Protects persisted authentication state with Android Keystore-backed encryption.
common/src/main/java/com/microsoft/identity/common/crypto/AndroidAuthSdkStorageEncryptionManager.java - Device PoP manager · Manages device-bound proof-of-possession keys.
common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidDevicePopManager.java
Identity and platform services
- Identity providers · Azure AD, Microsoft STS, B2C/CIAM, ADFS, and optional Google federation.
- Android platform APIs · AccountManager, bound services, content providers, WebView, intents, and Keystore.
Connections 25
- Command dispatcher → Token command: dispatches
- Token command → Local MSAL controller: routes locally
- Token command → Broker MSAL controller: routes via broker
- Local MSAL controller → OAuth2 strategy: executes protocol flow
- OAuth2 strategy → AAD strategy: specialized by
- OAuth2 strategy → Microsoft STS strategy: specialized by
- OAuth2 strategy → MSAL token cache: reads and writes
- AAD strategy → Identity providers: HTTP authorization/token exchange
- Microsoft STS strategy → Identity providers: HTTP authorization/token exchange
- Local MSAL controller → Android authorization strategy: starts interactive flow
- Android authorization strategy → Authorization activity: launches
- Android authorization strategy → Browser authorization: uses
- Browser authorization → Web challenge factory: handles web challenges
- Authorization activity → Android platform APIs: uses UI and intent APIs
- Broker MSAL controller → Broker request: adapts request
- Broker request → Broker IPC strategy: dispatches through
- Broker IPC strategy → Auth service AIDL: binds service contract
- Broker IPC strategy → Android platform APIs: uses IPC APIs
- Device registration → Android platform APIs: uses device IPC
- MSAL token cache → Android secure storage: protected by
- Device PoP manager → Android secure storage: stores keys in
- Native auth controller → Native auth strategy: executes exchanges
- Native auth strategy → Identity providers: calls native-auth endpoints
- Command dispatcher → Telemetry: emits events
- Telemetry → OpenTelemetry holder: bridges tracing