# aspnet/security architecture

> Architecture diagram of the GitHub repository aspnet/security, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aspnet/security
- Repository: https://github.com/aspnet/security

## Overview

##### Main Components

a. Core Authentication Framework
- "Microsoft.AspNetCore.Authentication" at the center
- AuthenticationMiddleware as the entry point
- Core interfaces (IAuthenticationService, IAuthorizationService)

b. Authentication Handlers (arrange in a circular pattern around the core)
- Cookie Authentication
- JWT Bearer
- OAuth 2.0
- OpenID Connect
- Social Authentication Providers (Facebook, Google, Twitter, Microsoft)
- WS-Federation

c. Authorization Framework
- Authorization Policy System
- Authorization Handlers
- Policy Evaluation Pipeline

##### Relationships and Data Flow

- Request flow through the middleware pipeline
- Authentication handler selection and execution
- Token/ticket processing and validation
- Integration with external identity providers
- Policy evaluation flow

##### Detailed Component Breakdown

Authentication Core:
**┌─ Authentication Middleware ─┐**
- Handler Selection       │
- Authentication Manager  │
- Results Pipeline       │
- ┘

Authentication Handlers:
**┌─ Handler Base Classes ───┐**
- AuthenticationHandler │
- RemoteAuthHandler    │
- SignInHandler       │
- ┘

Authorization System:
**┌─ Authorization Service ──┐**
- Policy Evaluation    │
- Requirements        │
- Handlers           │
- ┘

##### Integration Points

Connections with:
- ASP.NET Core Middleware Pipeline
- External Identity Providers
- Token Validation Services
- Data Protection System

##### Key Processes to Highlight

- Authentication Challenge Process
- Token Validation Flow
- Authorization Policy Evaluation
- Social Authentication Flow

##### Additional Elements

Include:
- Configuration Options
- Event Systems
- Security Token Handlers
- Cookie Management
- Data Protection Integration

##### Notes Section

Annotations for:
- Security considerations
- Configuration requirements
- Common integration patterns
- Best practices

Remember to include version compatibility notes and any breaking changes between major versions, as this is a critical security component.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Authentication Framework"]
        AM["Authentication Middleware"]
        AH["Authentication Handler Base"]
        AS["Authentication Service"]
        AuS["Authorization Service"]
    end

    subgraph Handlers["Authentication Handlers"]
        direction TB
        Cookie["Cookie Authentication"]
        JWT["JWT Bearer"]
        OAuth["OAuth 2.0"]
        OIDC["OpenID Connect"]
        WS["WS-Federation"]
        
        subgraph Social["Social Authentication"]
            direction TB
            FB["Facebook"]
            GO["Google"]
            TW["Twitter"]
            MS["Microsoft Account"]
        end
    end

    subgraph Authorization["Authorization Framework"]
        direction TB
        AP["Authorization Policy"]
        PE["Policy Evaluator"]
        AuM["Authorization Middleware"]
    end

    subgraph Additional["Additional Components"]
        direction TB
        CP["Cookie Policy"]
        OI["OWIN Security Interop"]
    end

    %% Core relationships
    AM --> AH
    AH --> AS
    AS --> AuS

    %% Handler relationships
    AH --> Cookie
    AH --> JWT
    AH --> OAuth
    AH --> OIDC
    AH --> WS
    AH --> Social
    OAuth --> Social
    Social --> FB
    Social --> GO
    Social --> TW
    Social --> MS

    %% Authorization relationships
    AuS --> AP
    AP --> PE
    PE --> AuM

    %% Additional relationships
    Cookie --> CP
    AM --> OI

    %% Click events
    click AM "https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication/AuthenticationMiddleware.cs"
    click AH "https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs"
    click AS "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication/"
    click Cookie "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.Cookies/"
    click JWT "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.JwtBearer/"
    click OAuth "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.OAuth/"
    click OIDC "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/"
    click WS "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.WsFederation/"
    click FB "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.Facebook/"
    click GO "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.Google/"
    click TW "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.Twitter/"
    click MS "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/"
    click AP "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.Authorization.Policy/"
    click AuM "https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authorization.Policy/AuthorizationMiddleware.cs"
    click PE "https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authorization.Policy/PolicyEvaluator.cs"
    click CP "https://github.com/aspnet/Security/tree/master/src/Microsoft.AspNetCore.CookiePolicy/"
    click OI "https://github.com/aspnet/Security/tree/master/src/Microsoft.Owin.Security.Interop/"

    %% Styling
    classDef core fill:#2374ab
    classDef handlers fill:#2a9d8f
    classDef auth fill:#e9c46a
    classDef additional fill:#f4a261
    classDef social fill:#64b5f6

    class AM,AH,AS,AuS core
    class Cookie,JWT,OAuth,OIDC,WS handlers
    class FB,GO,TW,MS social
    class AP,PE,AuM auth
    class CP,OI additional
```
