# microsoft/moodle-auth_oidc architecture

> Architecture diagram of the GitHub repository microsoft/moodle-auth_oidc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/moodle-auth_oidc
- Repository: https://github.com/microsoft/moodle-auth_oidc

## Overview

This Moodle authentication plugin provides configurable OpenID Connect single sign-on. Users enter through Moodle’s login integration or the plugin landing page, are redirected to an identity provider, and return through the authorization-code flow for token validation and Moodle account matching or creation. Separate settings and account-management surfaces configure providers and handle linking or disconnection; privacy, events, and scheduled cleanup support the lifecycle. The workflow edges reflect excerpts and README documentation; unsampled subsystem connections are omitted where their callers are not shown.

Main entry points: [`settings.php`](https://github.com/microsoft/moodle-auth_oidc/blob/master/settings.php) (Provider settings), [`classes/loginflow/authcode.php`](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/loginflow/authcode.php) (Authorization code flow), [`classes/oidcclient.php`](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/oidcclient.php) (OIDC client), [`auth.php`](https://github.com/microsoft/moodle-auth_oidc/blob/master/auth.php) (Auth entry points)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_admin["Configuration"]
  node_settings["Provider settings<br/>[settings.php]"]
  node_application["Application form<br/>[application.php]"]
  node_endpoint["Endpoint validation"]
  node_loginsetting["Login flow setting"]
  node_redirectsetting["Redirect URI setting"]
  node_iconsetting["Provider icon setting"]
end

subgraph group_auth["Authentication"]
  node_entry["Auth entry points<br/>[auth.php]"]
  node_landing["OIDC landing<br/>[index.php]"]
  node_flow["Authorization code flow<br/>[authcode.php]"]
  node_baseflow["Login flow base<br/>[base.php]"]
  node_oidcclient["OIDC client<br/>[oidcclient.php]"]
  node_http["HTTP client<br/>[httpclient.php]"]
  node_jwt["JWT handling<br/>[jwt.php]"]
end

subgraph group_accounts["Account lifecycle"]
  node_accountforms["Account management forms<br/>[disconnect.php]"]
  node_bindingtool["Claim binding tool"]
  node_management["Application management"]
end

subgraph group_ops["Lifecycle support"]
  node_privacy["Privacy provider<br/>[provider.php]"]
  node_events["Authentication events<br/>[user_created.php]"]
  node_observers["Event observers<br/>[observers.php]"]
  node_cleanup["Scheduled cleanup"]
  node_sidcleanup["Session cleanup"]
  node_tokens[("OIDC token records")]
end

node_user(("Moodle user"))
node_idp(("OIDC provider"))
node_adminuser(("Site administrator"))

node_user -->|"starts login"| node_entry
node_entry -.->|"selects flow"| node_baseflow
node_landing -->|"handles redirect"| node_flow
node_flow -->|"requests authorization"| node_oidcclient
node_oidcclient -.->|"authorization exchange"| node_idp
node_oidcclient -.->|"uses HTTP"| node_http
node_flow -.->|"validates tokens"| node_jwt
node_flow -->|"completes login"| node_user
node_flow -->|"fires events"| node_events
node_adminuser -->|"configures"| node_settings
node_settings -->|"registers setting"| node_endpoint
node_settings -->|"registers setting"| node_loginsetting
node_settings -->|"registers setting"| node_redirectsetting
node_settings -.->|"registers setting"| node_iconsetting
node_adminuser -.->|"edits provider"| node_application
node_user -.->|"manages connection"| node_accountforms
node_user -.->|"updates claim binding"| node_bindingtool
node_adminuser -.->|"manages application"| node_management
node_privacy -.->|"handles personal data"| node_tokens
node_observers -.->|"observes events"| node_events
node_cleanup -.->|"cleans records"| node_tokens
node_sidcleanup -.->|"cleans sessions"| node_tokens

click node_entry "https://github.com/microsoft/moodle-auth_oidc/blob/master/auth.php"
click node_landing "https://github.com/microsoft/moodle-auth_oidc/blob/master/index.php"
click node_flow "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/loginflow/authcode.php"
click node_baseflow "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/loginflow/base.php"
click node_oidcclient "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/oidcclient.php"
click node_http "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/httpclient.php"
click node_jwt "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/jwt.php"
click node_settings "https://github.com/microsoft/moodle-auth_oidc/blob/master/settings.php"
click node_application "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/form/application.php"
click node_endpoint "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_endpoint.php"
click node_loginsetting "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_loginflow.php"
click node_redirectsetting "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_redirecturi.php"
click node_iconsetting "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_iconselect.php"
click node_accountforms "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/form/disconnect.php"
click node_bindingtool "https://github.com/microsoft/moodle-auth_oidc/blob/master/change_binding_username_claim_tool.php"
click node_management "https://github.com/microsoft/moodle-auth_oidc/blob/master/manageapplication.php"
click node_privacy "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/privacy/provider.php"
click node_events "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/event/user_created.php"
click node_observers "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/observers.php"
click node_cleanup "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/task/cleanup_oidc_state_and_token.php"
click node_sidcleanup "https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/task/cleanup_oidc_sid.php"

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_settings,node_application,node_endpoint,node_loginsetting,node_redirectsetting,node_iconsetting,node_user toneBlue
class node_entry,node_landing,node_flow,node_baseflow,node_oidcclient,node_http,node_jwt toneAmber
class node_accountforms,node_bindingtool,node_management toneMint
class node_privacy,node_events,node_observers,node_cleanup,node_sidcleanup,node_tokens toneRose
class node_idp,node_adminuser toneIndigo
```

## Components

### Configuration

- [Provider settings](https://github.com/microsoft/moodle-auth_oidc/blob/master/settings.php): `settings.php`
- [Application form](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/form/application.php): `classes/form/application.php`
- [Endpoint validation](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_endpoint.php): `classes/adminsetting/auth_oidc_admin_setting_endpoint.php`
- [Login flow setting](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_loginflow.php): `classes/adminsetting/auth_oidc_admin_setting_loginflow.php`
- [Redirect URI setting](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_redirecturi.php): `classes/adminsetting/auth_oidc_admin_setting_redirecturi.php`
- [Provider icon setting](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/adminsetting/auth_oidc_admin_setting_iconselect.php): `classes/adminsetting/auth_oidc_admin_setting_iconselect.php`

### Authentication

- [Auth entry points](https://github.com/microsoft/moodle-auth_oidc/blob/master/auth.php): `auth.php`
- [OIDC landing](https://github.com/microsoft/moodle-auth_oidc/blob/master/index.php): `index.php`
- [Authorization code flow](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/loginflow/authcode.php): `classes/loginflow/authcode.php`
- [Login flow base](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/loginflow/base.php): `classes/loginflow/base.php`
- [OIDC client](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/oidcclient.php): `classes/oidcclient.php`
- [HTTP client](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/httpclient.php): `classes/httpclient.php`
- [JWT handling](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/jwt.php): `classes/jwt.php`

### Account lifecycle

- [Account management forms](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/form/disconnect.php): `classes/form/disconnect.php`
- [Claim binding tool](https://github.com/microsoft/moodle-auth_oidc/blob/master/change_binding_username_claim_tool.php): `change_binding_username_claim_tool.php`
- [Application management](https://github.com/microsoft/moodle-auth_oidc/blob/master/manageapplication.php): `manageapplication.php`

### Lifecycle support

- [Privacy provider](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/privacy/provider.php): `classes/privacy/provider.php`
- [Authentication events](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/event/user_created.php): `classes/event/user_created.php`
- [Event observers](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/observers.php): `classes/observers.php`
- [Scheduled cleanup](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/task/cleanup_oidc_state_and_token.php): `classes/task/cleanup_oidc_state_and_token.php`
- [Session cleanup](https://github.com/microsoft/moodle-auth_oidc/blob/master/classes/task/cleanup_oidc_sid.php): `classes/task/cleanup_oidc_sid.php`
- **OIDC token records**

### Other components

- **Moodle user**
- **OIDC provider**
- **Site administrator**

## Connections

- Moodle user → Auth entry points: starts login
- Auth entry points → Login flow base: selects flow
- OIDC landing → Authorization code flow: handles redirect (evidence: `index.php`)
- Authorization code flow → OIDC client: requests authorization (evidence: `classes/loginflow/authcode.php`)
- OIDC client → OIDC provider: authorization exchange
- OIDC client → HTTP client: uses HTTP
- Authorization code flow → JWT handling: validates tokens
- Authorization code flow → Moodle user: completes login (evidence: `classes/loginflow/authcode.php`)
- Authorization code flow → Authentication events: fires events (evidence: `classes/loginflow/authcode.php`)
- Site administrator → Provider settings: configures
- Provider settings → Endpoint validation: registers setting (evidence: `settings.php`)
- Provider settings → Login flow setting: registers setting (evidence: `settings.php`)
- Provider settings → Redirect URI setting: registers setting (evidence: `settings.php`)
- Provider settings → Provider icon setting: registers setting (evidence: `settings.php`)
- Site administrator → Application form: edits provider
- Moodle user → Account management forms: manages connection
- Moodle user → Claim binding tool: updates claim binding
- Site administrator → Application management: manages application
- Privacy provider → OIDC token records: handles personal data
- Event observers → Authentication events: observes events
- Scheduled cleanup → OIDC token records: cleans records
- Session cleanup → OIDC token records: cleans sessions
