How oidc-wp/openid-connect-generic works
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)