# snok/django-auth-adfs architecture

> Architecture diagram of the GitHub repository snok/django-auth-adfs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/snok/django-auth-adfs
- Repository: https://github.com/snok/django-auth-adfs

## Overview

django-auth-adfs is a Django authentication integration for on-premises ADFS and Azure AD. In the browser flow, a user starts login, is redirected to the identity provider, and returns to a callback that authenticates the authorization code, provisions or updates the Django user, and establishes a session. It also supports middleware-enforced login and DRF bearer-token authentication; backend token validation can retrieve group membership through Microsoft Graph. The graph reflects the sampled calls and README-described routes; other configuration and integration details were not inspected.

Main entry points: [`django_auth_adfs/backend.py`](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/backend.py) (Auth backends), [`django_auth_adfs/views.py`](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/views.py) (OAuth views), [`django_auth_adfs/config.py`](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/config.py) (Provider config), [`django_auth_adfs/rest_framework.py`](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/rest_framework.py) (DRF bearer auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_oauth["Browser OAuth"]
  node_routes["OAuth routes<br/>[urls.py]"]
  node_views["OAuth views<br/>[views.py]"]
end

subgraph group_auth["Authentication"]
  node_backend["Auth backends<br/>[backend.py]"]
  node_userstore[("Django users / groups")]
  node_signals["Post-auth signal<br/>[signals.py]"]
  node_exceptions["MFA exception<br/>[exceptions.py]"]
  node_middleware["Login middleware<br/>[middleware.py]"]
end

subgraph group_config["Provider Configuration"]
  node_providerconfig["Provider config<br/>[config.py]"]
  node_openid{{"OIDC metadata"}}
end

subgraph group_integrations["API Integrations"]
  node_drfauth["DRF bearer auth<br/>[rest_framework.py]"]
  node_drfroutes["DRF login routes<br/>[drf_urls.py]"]
  node_graph{{"Microsoft Graph"}}
end

node_user(("Browser user"))
node_adfs{{"ADFS / Azure AD"}}

node_user -->|"opens login"| node_routes
node_routes -->|"routes requests"| node_views
node_views -->|"builds redirects"| node_providerconfig
node_views -->|"authenticates code"| node_backend
node_views -->|"redirects callback"| node_user
node_providerconfig -->|"loads metadata"| node_openid
node_providerconfig -->|"builds provider URLs"| node_adfs
node_views -->|"redirects for login"| node_adfs
node_backend -->|"exchanges code"| node_adfs
node_backend -->|"uses provider settings"| node_providerconfig
node_backend -->|"creates and updates"| node_userstore
node_backend -->|"sends signal"| node_signals
node_backend -->|"raises MFA error"| node_exceptions
node_backend -->|"queries memberships"| node_graph
node_middleware -->|"handles MFA error"| node_exceptions
node_user -->|"sends bearer token"| node_drfauth
node_drfauth -->|"authenticates token"| node_backend
node_drfauth -->|"handles MFA error"| node_exceptions
node_drfroutes -->|"routes login"| node_views

click node_routes "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/urls.py"
click node_views "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/views.py"
click node_backend "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/backend.py"
click node_signals "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/signals.py"
click node_exceptions "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/exceptions.py"
click node_middleware "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/middleware.py"
click node_providerconfig "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/config.py"
click node_drfauth "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/rest_framework.py"
click node_drfroutes "https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/drf_urls.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_routes,node_views,node_user toneBlue
class node_backend,node_userstore,node_signals,node_exceptions,node_middleware toneAmber
class node_providerconfig,node_openid toneMint
class node_drfauth,node_drfroutes,node_graph toneRose
class node_adfs toneIndigo
```

## Components

### Browser OAuth

- [OAuth routes](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/urls.py): `django_auth_adfs/urls.py`
- [OAuth views](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/views.py): `django_auth_adfs/views.py`

### Authentication

- [Auth backends](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/backend.py): `django_auth_adfs/backend.py`
- **Django users / groups**
- [Post-auth signal](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/signals.py): `django_auth_adfs/signals.py`
- [MFA exception](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/exceptions.py): `django_auth_adfs/exceptions.py`
- [Login middleware](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/middleware.py): `django_auth_adfs/middleware.py`

### Provider Configuration

- [Provider config](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/config.py): `django_auth_adfs/config.py`
- **OIDC metadata**

### API Integrations

- [DRF bearer auth](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/rest_framework.py): `django_auth_adfs/rest_framework.py`
- [DRF login routes](https://github.com/snok/django-auth-adfs/blob/main/django_auth_adfs/drf_urls.py): `django_auth_adfs/drf_urls.py`
- **Microsoft Graph**

### Other components

- **Browser user**
- **ADFS / Azure AD**

## Connections

- Browser user → OAuth routes: opens login (evidence: `README.rst`)
- OAuth routes → OAuth views: routes requests (evidence: `django_auth_adfs/urls.py`)
- OAuth views → Provider config: builds redirects (evidence: `django_auth_adfs/views.py`)
- OAuth views → Auth backends: authenticates code (evidence: `django_auth_adfs/views.py`)
- OAuth views → Browser user: redirects callback (evidence: `django_auth_adfs/views.py`)
- Provider config → OIDC metadata: loads metadata (evidence: `django_auth_adfs/config.py`)
- Provider config → ADFS / Azure AD: builds provider URLs (evidence: `django_auth_adfs/config.py`)
- OAuth views → ADFS / Azure AD: redirects for login (evidence: `django_auth_adfs/views.py`)
- Auth backends → ADFS / Azure AD: exchanges code (evidence: `django_auth_adfs/backend.py`)
- Auth backends → Provider config: uses provider settings (evidence: `django_auth_adfs/backend.py`)
- Auth backends → Django users / groups: creates and updates (evidence: `django_auth_adfs/backend.py`)
- Auth backends → Post-auth signal: sends signal (evidence: `django_auth_adfs/backend.py`)
- Auth backends → MFA exception: raises MFA error (evidence: `django_auth_adfs/backend.py`)
- Auth backends → Microsoft Graph: queries memberships (evidence: `django_auth_adfs/backend.py`)
- Login middleware → MFA exception: handles MFA error (evidence: `django_auth_adfs/middleware.py`)
- Browser user → DRF bearer auth: sends bearer token (evidence: `README.rst`)
- DRF bearer auth → Auth backends: authenticates token (evidence: `django_auth_adfs/rest_framework.py`)
- DRF bearer auth → MFA exception: handles MFA error (evidence: `django_auth_adfs/rest_framework.py`)
- DRF login routes → OAuth views: routes login (evidence: `django_auth_adfs/drf_urls.py`)
