# juanifioren/django-oidc-provider architecture

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

- Interactive diagram: https://gitdiagram.com/juanifioren/django-oidc-provider
- Repository: https://github.com/juanifioren/django-oidc-provider

## Overview

##### Main Components

a. Core OIDC Provider Components:
- Authorization Endpoint
- Token Endpoint
- UserInfo Endpoint
- Session Management
- Introspection Endpoint
- Provider Configuration Endpoint

b. Supporting Systems:
- Database (for storing clients, tokens, and RSA keys)
- Template System (for UI components)
- Authentication System (Django's auth)

**┌─ Client Applications Layer ─────────────────────┐**
- (External OAuth2/OIDC Clients)                  │
- ┬───────────────────────────┘
- ↓
**┌─ API Endpoints Layer ──────────────────────────┐**
- ┌─────────┐ ┌──────┐ ┌────────┐ ┌──────────┐  │
- /authorize│ │/token│ │/userinfo│ │/.well-known│ │
- ┘ └──────┘ └────────┘ └──────────┘  │
- ┬───────────────────────────┘
- ↓
**┌─ Core Logic Layer ───────────────────────────────┐**
- ┌─────────────┐ ┌──────────┐ ┌───────────────┐  │
- Claims Handler│ │Token Gen.│ │Scope Validator│  │
- ┘ └──────────┘ └───────────────┘  │
- ┬───────────────────────────┘
- ↓
**┌─ Data Storage Layer ─────────────────────────────┐**
- ┌──────────┐ ┌─────────┐ ┌────────┐ ┌───────┐   │
- RSA Keys  │ │Clients  │ │Tokens  │ │Users  │   │
- ┘ └─────────┘ └────────┘ └───────┘   │
- ┘

##### Important Flows to Highlight

a. Authorization Flow:
- Client → /authorize → User Authentication → Consent → Authorization Code

b. Token Flow:
- Client → /token → Validation → Access Token + ID Token

##### Technical Details to Note

- Authentication flows
- Data access
- API calls
- Internal communication

##### Implementation-Specific Details

- The separation between lib/ and views
- The role of middleware
- Template customization options
- Available management commands

Remember to:
- Clear boundaries between components
- Version information
- Document extension points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications Layer"]
        ExtClients["External OAuth2/OIDC Clients"]
    end

    subgraph API["API Endpoints Layer"]
        Auth["/authorize"]:::endpoint
        Token["/token"]:::endpoint
        UserInfo["/userinfo"]:::endpoint
        WellKnown["/.well-known"]:::endpoint
        Introspect["/introspect"]:::endpoint
    end

    subgraph Core["Core Logic Layer"]
        Claims["Claims Handler"]:::core
        TokenGen["Token Generation"]:::core
        ScopeVal["Scope Validator"]:::core
        OAuth2Utils["OAuth2 Utilities"]:::core
        ErrorHandler["Error Handler"]:::core
        SessionMgmt["Session Management"]:::core
        URLRouter["URL Router"]:::core
        Middleware["Middleware"]:::core
        Signals["Signal Handlers"]:::core
    end

    subgraph Data["Data Storage Layer"]
        RSAKeys["RSA Keys"]:::storage
        Clients["Clients"]:::storage
        Tokens["Tokens"]:::storage
        Users["Users"]:::storage
        Settings["Core Settings"]:::storage
    end

    subgraph Support["Supporting Systems"]
        Templates["Template System"]:::support
        DjangoAuth["Django Authentication"]:::support
    end

    %% Connections
    ExtClients --> Auth
    ExtClients --> Token
    ExtClients --> UserInfo
    ExtClients --> WellKnown
    ExtClients --> Introspect

    Auth --> Claims
    Auth --> TokenGen
    Auth --> ScopeVal
    Auth --> OAuth2Utils
    Auth --> ErrorHandler
    Auth --> SessionMgmt

    Token --> TokenGen
    Token --> OAuth2Utils
    Token --> ErrorHandler

    UserInfo --> Claims
    UserInfo --> TokenGen
    UserInfo --> ErrorHandler

    TokenGen --> RSAKeys
    TokenGen --> Tokens

    URLRouter --> |Routes| API
    Middleware --> |Processes| API
    Signals --> |Monitors| Core

    Core --> Templates
    Core --> DjangoAuth
    Core --> Data

    %% Click Events
    click Auth "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/endpoints/authorize.py"
    click Token "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/endpoints/token.py"
    click Introspect "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/endpoints/introspection.py"
    click SessionMgmt "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/templates/oidc_provider/check_session_iframe.html"
    click Claims "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/claims.py"
    click TokenGen "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/utils/token.py"
    click Data "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/models.py"
    click Settings "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/settings.py"
    click Templates "https://github.com/juanifioren/django-oidc-provider/tree/master/oidc_provider/templates/oidc_provider/"
    click OAuth2Utils "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/utils/oauth2.py"
    click RSAKeys "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/management/commands/creatersakey.py"
    click ErrorHandler "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/lib/errors.py"
    click URLRouter "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/urls.py"
    click Middleware "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/middleware.py"
    click Signals "https://github.com/juanifioren/django-oidc-provider/blob/master/oidc_provider/signals.py"

    %% Styles
    classDef endpoint fill:#2374ab,color:white
    classDef core fill:#57a773,color:white
    classDef storage fill:#ffc857,color:black
    classDef support fill:#929292,color:white

    %% Legend
    subgraph Legend
        E["API Endpoint"]:::endpoint
        C["Core Component"]:::core
        S["Storage"]:::storage
        SP["Support System"]:::support
    end
```
