# oidc-wp/openid-connect-generic architecture

> Architecture diagram of the GitHub repository oidc-wp/openid-connect-generic, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oidc-wp/openid-connect-generic
- Repository: https://github.com/oidc-wp/openid-connect-generic

## Overview

##### Project type and purpose
- This is a WordPress plugin (“OpenID Connect Generic Client”) that adds OAuth2/OpenID Connect SSO capabilities to a WordPress site.
- Its goal is to hook into WordPress’s login flow, direct users to an external OpenID Connect authorization server, handle the callback, fetch tokens and user claims, then map or create WordPress users accordingly.

##### File structure
- Top-level plugin entry point: openid-connect-generic.php
- includes/
- openid-connect-generic-client-wrapper.php – HTTP calls to token, userinfo endpoints
- openid-connect-generic-client.php – core client logic, authorization URL builder
- openid-connect-generic-login-form.php – adds “Login with OpenID Connect” button to WP login form
- openid-connect-generic-option-settings.php – reads/writes plugin configuration to WP options table
- openid-connect-generic-settings-page.php – admin UI under Settings > OpenID Connect Generic
- openid-connect-generic-option-logger.php – log storage and cleanup logic
- functions.php – helper functions and hook registrations
- css/styles-admin.css – styling for the settings page
- languages/ – .pot file for translations
- tests/ – phpunit and phpstan tests for each module
- tools/local-env & tools/apache – local Docker/VM dev environment configuration
- composer.json – autoloading and coding-standards tools
- Gruntfile.js – build tasks for linting, CSS preprocessing, etc.

##### Extract architecture details from README
- Uses Authorization Code Flow: user → Authorization Endpoint → callback to WP AJAX → Token Endpoint → UserInfo Endpoint
- Configurable Redirect URI via WP AJAX or clean URL
- Automatic user creation or mapping on successful authentication
- Filters/hooks allow deep customization (e.g., “remember me” filter, session expiration hooks)

a. Main components
- User’s Browser / UI
- WordPress Core
– login form and admin-ajax.php endpoint
– WP database (users, options)
- OpenID Connect Generic Plugin
– Presentation layer: login button injector, admin CSS, settings page
– Service layer: client wrapper for HTTP calls (authorization, token, userinfo)
– Persistence: WP options API for config, WP users table for mapping/creation, logger table or postmeta
- External OpenID Connect Provider
– Authorization Endpoint
– Token Endpoint
– UserInfo Endpoint
– (Optional) Revocation/Introspection Endpoints
b. Relationships & interactions
1. Browser → WordPress login page (requests)
2. Plugin injects “Login with OpenID Connect” – user clicks
3. Plugin constructs Authorization URL → redirect browser → External Provider
4. User authenticates at Provider → Provider redirects back to WP AJAX endpoint
5. Plugin’s client-wrapper exchanges authorization code for tokens at Token Endpoint
6. Plugin optionally calls UserInfo Endpoint to fetch claims
7. Plugin maps claims to existing WP user or creates new user in WP database
8. Plugin sets WP authentication cookies → redirects user to desired page
c. Architectural patterns & principles
- Layered design within the plugin (presentation, service, persistence)
- Dependency injection of HTTP client via the generic-client-wrapper
- Use of WordPress hooks/filters as extension points (e.g., filter for session expiration)
- Singleton pattern for main plugin instance for global access (<openid-connect-generic.php>)
- Separation of concerns: settings management, logging, authentication flow, UI injection
d. Key technologies & frameworks
- PHP 7.4+ and WordPress Plugin API (actions, filters, options API)
- OAuth2/OpenID Connect standards (Authorization Code Flow)
- Composer for autoloading, PHPUnit and PHPStan for testing, Grunt for build tasks
- Docker-based local development via tools/local-env (Apache + WP-CLI)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    subgraph "User"
        Browser["User's Browser / UI"]
    end

    %% WordPress Core
    subgraph "WordPress Core"
        direction TB
        LoginPage["WP Login Page"]:::wordpress
        AJAX["admin-ajax.php Endpoint"]:::wordpress
        DBUsers["WP Users Table"]:::wordpress
        DBOptions["WP Options Table"]:::wordpress
    end

    %% Plugin Boundary
    subgraph "OpenID Connect Generic Plugin"
        direction TB
        Entry["Plugin Entry Point"]:::plugin
        subgraph "Presentation Layer"
            LoginButton["Login Button Injector"]:::plugin
            SettingsPage["Settings Page UI"]:::plugin
            AdminCSS["Admin CSS Styling"]:::plugin
        end
        subgraph "Service Layer"
            ClientLogic["OAuth2/OpenID Connect Client Logic"]:::plugin
            HTTPWrapper["HTTP Client Wrapper"]:::plugin
        end
        subgraph "Persistence Layer"
            Config["Configuration Management"]:::plugin
            Logger["Logging Subcomponent"]:::plugin
        end
        HelperFuncs["Helper Functions & Hooks"]:::plugin
    end

    %% External Provider
    subgraph "External OpenID Connect Provider"
        direction TB
        AuthEP["Authorization Endpoint"]:::external
        TokenEP["Token Endpoint"]:::external
        UserInfoEP["UserInfo Endpoint"]:::external
    end

    %% Development & Testing
    subgraph "Development & Testing"
        direction TB
        DockerEnv["Local Env (Docker)"]:::dev
        ApacheConf["Apache Config"]:::dev
        Composer["Composer Config"]:::dev
        Grunt["Grunt Build Tasks"]:::dev
        subgraph "PHPUnit Tests"
            direction TB
            T1["client-wrapper_test"]:::dev
            T2["client_test"]:::dev
            T3["login-form_test"]:::dev
            T4["option-logger_test"]:::dev
            T5["option-settings_test"]:::dev
            T6["settings-page_test"]:::dev
            T7["plugin_test"]:::dev
        end
        PHPStan["PHPStan Bootstrap"]:::dev
    end

    %% Data Flows
    Browser -->|"requests login page"| LoginPage
    LoginPage -->|"inject login button"| LoginButton
    LoginButton -->|"user clicks"| Entry
    Entry -->|"builds auth URL"| ClientLogic
    ClientLogic -->|"HTTPS GET Auth"| AuthEP
    AuthEP -->|"redirect with code"| Browser
    Browser -->|"callback to"| AJAX
    AJAX -->|"calls"| HTTPWrapper
    HTTPWrapper -->|"POST code to"| TokenEP
    HTTPWrapper -->|"GET claims from"| UserInfoEP
    HTTPWrapper -->|"returns tokens/claims to"| ClientLogic
    ClientLogic -->|"map/create user"| DBUsers
    ClientLogic -->|"invoke hooks"| HelperFuncs
    ClientLogic -->|"store config"| Config
    Config -->|"stores to"| DBOptions
    ClientLogic -->|"log event"| Logger

    %% Test & Dev Relationships
    DockerEnv -->|uses| ApacheConf
    DockerEnv -->|runs tests| T1
    DockerEnv -->|runs tests| T2
    DockerEnv -->|runs tests| T3
    DockerEnv -->|runs tests| T4
    DockerEnv -->|runs tests| T5
    DockerEnv -->|runs tests| T6
    DockerEnv -->|runs tests| T7
    DockerEnv -->|sets up| PHPStan
    Composer -->|autoloads| Entry
    Grunt -->|builds| AdminCSS

    %% Click Events
    click Entry "https://github.com/oidc-wp/openid-connect-generic/blob/develop/openid-connect-generic.php"
    click LoginButton "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/openid-connect-generic-login-form.php"
    click SettingsPage "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/openid-connect-generic-settings-page.php"
    click ClientLogic "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/openid-connect-generic-client.php"
    click HTTPWrapper "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/openid-connect-generic-client-wrapper.php"
    click Config "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/openid-connect-generic-option-settings.php"
    click Logger "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/openid-connect-generic-option-logger.php"
    click HelperFuncs "https://github.com/oidc-wp/openid-connect-generic/blob/develop/includes/functions.php"
    click AdminCSS "https://github.com/oidc-wp/openid-connect-generic/blob/develop/css/styles-admin.css"
    click T1 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/includes/openid-connect-generic-client-wrapper_test.php"
    click T2 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/includes/openid-connect-generic-client_test.php"
    click T3 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/includes/openid-connect-generic-login-form_test.php"
    click T4 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/includes/openid-connect-generic-option-logger_test.php"
    click T5 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/includes/openid-connect-generic-option-settings_test.php"
    click T6 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/includes/openid-connect-generic-settings-page_test.php"
    click T7 "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpunit/openid-connect-generic_test.php"
    click PHPStan "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tests/phpstan-bootstrap.php"
    click DockerEnv "https://github.com/oidc-wp/openid-connect-generic/tree/develop/tools/local-env/"
    click ApacheConf "https://github.com/oidc-wp/openid-connect-generic/blob/develop/tools/apache/httpd.conf"
    click Composer "https://github.com/oidc-wp/openid-connect-generic/blob/develop/composer.json"
    click Grunt "https://github.com/oidc-wp/openid-connect-generic/blob/develop/Gruntfile.js"

    %% Styles
    classDef wordpress fill:#bbdefb,stroke:#1e88e5,color:#000;
    classDef plugin fill:#c8e6c9,stroke:#43a047,color:#000;
    classDef external fill:#ffe0b2,stroke:#fb8c00,color:#000;
    classDef dev fill:#eeeeee,stroke:#9e9e9e,color:#000;
```
