# azuread/microsoft-authentication-library-for-java architecture

> Architecture diagram of the GitHub repository azuread/microsoft-authentication-library-for-java, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azuread/microsoft-authentication-library-for-java
- Repository: https://github.com/azuread/microsoft-authentication-library-for-java

## Overview

##### Main Components

a) Core Authentication Components:
- Authentication Flows Module
- Interactive Flow
- Client Credentials Flow
- Device Code Flow
- On-Behalf-Of Flow
- Username/Password Flow
- Integrated Windows Authentication

b) Token Management:
- Token Cache System
- Token Request/Response Handlers
- Token Validation Components

c) Client Applications:
- Public Client Applications
- Confidential Client Applications
- Managed Identity Applications

d) Authority/Identity Providers:
- AAD Authority
- B2C Authority
- ADFS Authority
- CIAM Authority

##### Integration Points

a) External Services:
- Microsoft Identity Platform
- Azure AD
- Azure AD B2C
- Microsoft Graph API

b) Cache Extensions:
- Persistence Layer
- Cross-Process Cache Locking
- Platform-specific Storage (Windows, Linux, macOS)

##### Architectural Patterns to Highlight

a) Builder Pattern:
- Client application builders
- Authentication parameters builders

b) Factory Pattern:
- Client credential factories
- Authority factories

**┌─────────────────────────────────────────────────────────┐**
- Client Applications                     │
- ┬───────────────────┬────────────────────┤
- Public Client │ Confidential      │ Managed Identity   │
- Application   │ Client Application│ Application        │
- ┬───────┴────────┬──────────┴────────┬──────────┘

**┌───────▼────────────────▼────────────────────▼──────────┐**
- Authentication Flows Layer                 │
- ┬────────────────┬──────────────────┬────────────┘

**┌───────▼────────┐ ┌────▼─────────┐ ┌──────▼───────────┐**
- Token Manager  │ │ Cache Manager │ │ Authority Manager│
- ┬────────┘ └──────────────┘ └──────────────────┘

**┌───────▼────────────────────────────────────────────────┐**
- External Identity Services                │
- ┘

##### Important Details
- Token lifecycle paths
- Cache interaction patterns
- Security boundary demarcations
- Error handling paths

##### Implementation Notes
- Use standardized UML notation where applicable
- Version information (current: 1.18.0)
- Java 8+ compatibility

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef client fill:#a8d1ff,stroke:#000
    classDef auth fill:#ffb366,stroke:#000
    classDef token fill:#90EE90,stroke:#000
    classDef external fill:#d194ff,stroke:#000
    classDef cache fill:#ffff99,stroke:#000
    classDef broker fill:#ff9999,stroke:#000

    %% Client Applications Layer
    subgraph ClientApps
        PublicClient["Public Client Application"]
        ConfClient["Confidential Client Application"]
        ManagedClient["Managed Identity Application"]
    end

    %% Authentication Flows Layer
    subgraph AuthFlows
        Interactive["Interactive Flow"]
        DeviceCode["Device Code Flow"]
        UserPass["Username/Password Flow"]
        OBO["On-Behalf-Of Flow"]
    end

    %% Token Management Layer
    subgraph TokenMgmt
        TokenCache["Token Cache"]
        TokenRequest["Token Request Executor"]
        TokenValidation["Token Validation"]
    end

    %% Authority Layer
    subgraph Authorities
        AAD["AAD Authority"]
        B2C["B2C Authority"]
        ADFS["ADFS Authority"]
        CIAM["CIAM Authority"]
    end

    %% Cache Storage Layer
    subgraph CacheStorage
        PersistenceLayer["Cache Persistence"]
        Linux["Linux Storage"]
        Mac["Mac Storage"]
    end

    %% External Services
    subgraph ExternalServices
        MicrosoftIdentity["Microsoft Identity Platform"]
        AzureAD["Azure AD"]
        GraphAPI["Microsoft Graph API"]
    end

    %% Broker Integration
    BrokerComponent["Broker Component"]

    %% Relationships
    ClientApps --> AuthFlows
    AuthFlows --> TokenMgmt
    TokenMgmt --> Authorities
    Authorities --> ExternalServices
    TokenCache --> CacheStorage
    BrokerComponent --> AuthFlows
    
    %% Click events
    click PublicClient "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/PublicClientApplication.java"
    click ConfClient "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ConfidentialClientApplication.java"
    click ManagedClient "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityApplication.java"
    click Interactive "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/InteractiveRequest.java"
    click DeviceCode "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DeviceCodeFlowRequest.java"
    click UserPass "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/UserNamePasswordRequest.java"
    click OBO "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/OnBehalfOfRequest.java"
    click TokenCache "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenCache.java"
    click TokenRequest "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java"
    click AAD "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AADAuthority.java"
    click B2C "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/B2CAuthority.java"
    click ADFS "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ADFSAuthority.java"
    click CIAM "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CIAMAuthority.java"
    click Linux "https://github.com/AzureAD/microsoft-authentication-library-for-java/tree/dev/msal4j-persistence-extension/src/main/java/com/microsoft/aad/msal4jextensions/persistence/linux/"
    click Mac "https://github.com/AzureAD/microsoft-authentication-library-for-java/tree/dev/msal4j-persistence-extension/src/main/java/com/microsoft/aad/msal4jextensions/persistence/mac/"
    click BrokerComponent "https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-brokers/src/main/java/com/microsoft/aad/msal4jbrokers/Broker.java"
    click PersistenceLayer "https://github.com/AzureAD/microsoft-authentication-library-for-java/tree/dev/msal4j-persistence-extension/src/main/java/com/microsoft/aad/msal4jextensions/"

    %% Styling
    class PublicClient,ConfClient,ManagedClient client
    class Interactive,DeviceCode,UserPass,OBO auth
    class TokenCache,TokenRequest,TokenValidation token
    class AAD,B2C,ADFS,CIAM external
    class PersistenceLayer,Linux,Mac cache
    class BrokerComponent broker
```
