From cd379e1d95ce400ba7205353bec35d2aceee1e4e Mon Sep 17 00:00:00 2001 From: Lai Power Date: Wed, 9 Oct 2024 12:44:43 +0000 Subject: [PATCH] modified plugin `OpenID Connect Generic` version 3.10.0 --- .../.devcontainer/activate.sh | 12 + .../.devcontainer/devcontainer.json | 57 + .../welcome-message/devcontainer-feature.json | 8 + .../local-features/welcome-message/install.sh | 13 + .../.devcontainer/setup.sh | 37 + .../openid-connect-generic/.gitpod.yml | 17 + .../openid-connect-generic/.vscode/tasks.json | 16 + .../openid-connect-generic/CHANGELOG.md | 203 +++ .../plugins/openid-connect-generic/HOWTO.md | 383 ++++++ .../plugins/openid-connect-generic/README.md | 125 ++ .../openid-connect-generic/SECURITY.md | 17 + .../openid-connect-generic/codecov.yml | 10 + .../css/styles-admin.css | 32 + .../openid-connect-generic/docker-compose.yml | 95 ++ .../includes/functions.php | 30 + .../openid-connect-generic-client-wrapper.php | 1180 +++++++++++++++++ .../openid-connect-generic-client.php | 568 ++++++++ .../openid-connect-generic-login-form.php | 178 +++ .../openid-connect-generic-option-logger.php | 266 ++++ ...openid-connect-generic-option-settings.php | 213 +++ .../openid-connect-generic-settings-page.php | 603 +++++++++ .../languages/openid-connect-generic.pot | 531 ++++++++ .../openid-connect-generic.php | 434 ++++++ .../plugins/openid-connect-generic/readme.txt | 125 ++ .../plugins/openid-connect-generic/wp-cli.yml | 1 + 25 files changed, 5154 insertions(+) create mode 100644 wp-content/plugins/openid-connect-generic/.devcontainer/activate.sh create mode 100644 wp-content/plugins/openid-connect-generic/.devcontainer/devcontainer.json create mode 100644 wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/devcontainer-feature.json create mode 100644 wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/install.sh create mode 100644 wp-content/plugins/openid-connect-generic/.devcontainer/setup.sh create mode 100644 wp-content/plugins/openid-connect-generic/.gitpod.yml create mode 100644 wp-content/plugins/openid-connect-generic/.vscode/tasks.json create mode 100644 wp-content/plugins/openid-connect-generic/CHANGELOG.md create mode 100644 wp-content/plugins/openid-connect-generic/HOWTO.md create mode 100644 wp-content/plugins/openid-connect-generic/README.md create mode 100644 wp-content/plugins/openid-connect-generic/SECURITY.md create mode 100644 wp-content/plugins/openid-connect-generic/codecov.yml create mode 100644 wp-content/plugins/openid-connect-generic/css/styles-admin.css create mode 100644 wp-content/plugins/openid-connect-generic/docker-compose.yml create mode 100644 wp-content/plugins/openid-connect-generic/includes/functions.php create mode 100644 wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client-wrapper.php create mode 100644 wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client.php create mode 100644 wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-login-form.php create mode 100644 wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-option-logger.php create mode 100644 wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-option-settings.php create mode 100644 wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-settings-page.php create mode 100644 wp-content/plugins/openid-connect-generic/languages/openid-connect-generic.pot create mode 100644 wp-content/plugins/openid-connect-generic/openid-connect-generic.php create mode 100644 wp-content/plugins/openid-connect-generic/readme.txt create mode 100644 wp-content/plugins/openid-connect-generic/wp-cli.yml diff --git a/wp-content/plugins/openid-connect-generic/.devcontainer/activate.sh b/wp-content/plugins/openid-connect-generic/.devcontainer/activate.sh new file mode 100644 index 00000000..8b675afc --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.devcontainer/activate.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eu + +# Activate the plugin. +cd "/app" +echo "Activating plugin..." +if ! wp plugin is-active daggerhart-openid-connect-generic 2>/dev/null; then + wp plugin activate daggerhart-openid-connect-generic --quiet +fi + +echo "Done!" diff --git a/wp-content/plugins/openid-connect-generic/.devcontainer/devcontainer.json b/wp-content/plugins/openid-connect-generic/.devcontainer/devcontainer.json new file mode 100644 index 00000000..314f4b0f --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.devcontainer/devcontainer.json @@ -0,0 +1,57 @@ +// For format details, https://containers.dev/implementors/json_reference/. +{ + "name": "WordPress Development Environment", + "dockerComposeFile": "../docker-compose.yml", + "service": "app", + "mounts": ["source=dind-var-lib-docker,target=/var/lib/docker,type=volume"], + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + "customizations": { + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": {}, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": ["ms-azuretools.vscode-docker"] + } + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "./local-features/welcome-message": "latest" + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [8080, 8081, 8026, 3306], + + // Maps a port number, "host:port" value, range, or regular expression to a set of default options. See port attributes for available options + "portsAttributes": { + "8080": { + "label": "WordPress Development/Testing Site" + }, + "8081": { + "label": "phpMyAdmin" + }, + "8026": { + "label": "MailHog" + }, + "3306": { + "label": "MariaDB" + } + }, + + // Use `onCreateCommand` to run commands as part of the container creation. + //"onCreateCommand": "chmod +x .devcontainer/install.sh && .devcontainer/install.sh", + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh", + + // Use 'postStartCommand' to run commands after the container has started. + "postStartCommand": "chmod +x .devcontainer/activate.sh && .devcontainer/activate.sh", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "wp_php", + + // A set of name-value pairs that sets or overrides environment variables for the devcontainer.json supporting service / tool (or sub-processes like terminals) but not the container as a whole. + "remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" } +} diff --git a/wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/devcontainer-feature.json b/wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/devcontainer-feature.json new file mode 100644 index 00000000..c4f59354 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/devcontainer-feature.json @@ -0,0 +1,8 @@ +{ + "id": "welcome-message", + "name": "Install the First Start Welcome Message", + "install": { + "app": "", + "file": "install.sh" + } +} diff --git a/wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/install.sh b/wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/install.sh new file mode 100644 index 00000000..8df27c1c --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.devcontainer/local-features/welcome-message/install.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eux + +export DEBIAN_FRONTEND=noninteractive + +# Copy the welcome message +if [ ! -f /usr/local/etc/vscode-dev-containers/first-run-notice.txt ]; then + echo "Installing First Run Notice..." + echo -e "šŸ‘‹ Welcome to \"OpenID Connect for WP Development\" in Dev Containers!\n\nšŸ› ļø Your environment is fully setup with all the required software.\n\nšŸš€ To get started, wait for the \"postCreateCommand\" to finish setting things up, then open the portforwarded URL and append '/wp/wp-admin'. Login to the WordPress Dashboard using \`admin/password\` for the credentials.\n" | sudo tee /usr/local/etc/vscode-dev-containers/first-run-notice.txt +fi + +echo "Done!" diff --git a/wp-content/plugins/openid-connect-generic/.devcontainer/setup.sh b/wp-content/plugins/openid-connect-generic/.devcontainer/setup.sh new file mode 100644 index 00000000..a35da8f4 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.devcontainer/setup.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -eu + +# true is shell command and always return 0 +# false always return 1 +if [ -z "${CODESPACES}" ] ; then + SITE_HOST="http://localhost:8080" +else + SITE_HOST="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" +fi + +PLUGIN_DIR=/workspaces/openid-connect-generic + +# Attempt to make ipv4 traffic have a higher priority than ipv6. +sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf" + +# Install Composer dependencies. +cd "${PLUGIN_DIR}" +echo "Installing Composer dependencies..." +COMPOSER_NO_INTERACTION=1 COMPOSER_ALLOW_XDEBUG=0 COMPOSER_MEMORY_LIMIT=-1 composer install --no-progress --quiet + +# Install NPM dependencies. +cd "${PLUGIN_DIR}" +if [ ! -d "node_modules" ]; then + echo "Installing NPM dependencies..." + npm ci +fi + +# Setup the WordPress environment. +cd "/app" +if ! wp core is-installed 2>/dev/null; then + echo "Setting up WordPress at $SITE_HOST" + wp core install --url="$SITE_HOST" --title="OpenID Connect Development" --admin_user="admin" --admin_email="admin@example.com" --admin_password="password" --skip-email --quiet +fi + +echo "Done!" diff --git a/wp-content/plugins/openid-connect-generic/.gitpod.yml b/wp-content/plugins/openid-connect-generic/.gitpod.yml new file mode 100644 index 00000000..b5e460b7 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.gitpod.yml @@ -0,0 +1,17 @@ +# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/ +tasks: + - name: WordPress Development Environment + init: npm run setup # runs during prebuild + command: | + npm start -- --update + npm stop + npm start -- --update + +# List the ports to expose. Learn more https://www.gitpod.io/docs/config-ports/ +ports: + - port: 8888 + onOpen: notify + visibility: public + - port: 8889 + onOpen: notify + visibility: public diff --git a/wp-content/plugins/openid-connect-generic/.vscode/tasks.json b/wp-content/plugins/openid-connect-generic/.vscode/tasks.json new file mode 100644 index 00000000..62c02b1d --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "label": "npm: build", + "detail": "npm run grunt build" + } + ] +} \ No newline at end of file diff --git a/wp-content/plugins/openid-connect-generic/CHANGELOG.md b/wp-content/plugins/openid-connect-generic/CHANGELOG.md new file mode 100644 index 00000000..a7eadf7e --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/CHANGELOG.md @@ -0,0 +1,203 @@ +# OpenId Connect Generic Changelog + +**3.10.0** + +- Chore: @timnolte - Dependency updates. +- Fix: @drzraf - Prevents running the auth url filter twice. +- Fix: @timnolte - Updates the log cleanup handling to properly retain the configured number of log entries. +- Fix: @timnolte - Updates the log display output to reflect the log retention policy. +- Chore: @timnolte - Adds Unit Testing & New Local Development Environment. +- Feature: @timnolte - Updates logging to allow for tracking processing time. +- Feature: @menno-ll - Adds a remember me feature via a new filter. +- Improvement: @menno-ll - Updates WP Cookie Expiration to Same as Session Length. + +**3.9.1** + +- Improvement: @timnolte - Refactors Composer setup and GitHub Actions. +- Improvement: @timnolte - Bumps WordPress tested version compatibility. + +**3.9.0** + +- Feature: @matchaxnb - Added support for additional configuration constants. +- Feature: @schanzen - Added support for agregated claims. +- Fix: @rkcreation - Fixed access token not updating user metadata after login. +- Fix: @danc1248 - Fixed user creation issue on Multisite Networks. +- Feature: @RobjS - Added plugin singleton to support for more developer customization. +- Feature: @jkouris - Added action hook to allow custom handling of session expiration. +- Fix: @tommcc - Fixed admin CSS loading only on the plugin settings screen. +- Feature: @rkcreation - Added method to refresh the user claim. +- Feature: @Glowsome - Added acr_values support & verification checks that it when defined in options is honored. +- Fix: @timnolte - Fixed regression which caused improper fallback on missing claims. +- Fix: @slykar - Fixed missing query string handling in redirect URL. +- Fix: @timnolte - Fixed issue with some user linking and user creation handling. +- Improvement: @timnolte - Fixed plugin settings typos and screen formatting. +- Security: @timnolte - Updated build tooling security vulnerabilities. +- Improvement: @timnolte - Changed build tooling scripts. + +**3.8.5** + +- Fix: @timnolte - Fixed missing URL request validation before use & ensure proper current page URL is setup for Redirect Back. +- Fix: @timnolte - Fixed Redirect URL Logic to Handle Sub-directory Installs. +- Fix: @timnolte - Fixed issue with redirecting user back when the openid_connect_generic_auth_url shortcode is used. + +**3.8.4** + +- Fix: @timnolte - Fixed invalid State object access for redirection handling. +- Improvement: @timnolte - Fixed local wp-env Docker development environment. +- Improvement: @timnolte - Fixed Composer scripts for linting and static analysis. + +**3.8.3** + +- Fix: @timnolte - Fixed problems with proper redirect handling. +- Improvement: @timnolte - Changes redirect handling to use State instead of cookies. +- Improvement: @timnolte - Refactored additional code to meet coding standards. + +**3.8.2** + +- Fix: @timnolte - Fixed reported XSS vulnerability on WordPress login screen. + +**3.8.1** + +- Fix: @timnolte - Prevent SSO redirect on password protected posts. +- Fix: @timnolte - CI/CD build issues. +- Fix: @timnolte - Invalid redirect handling on logout for Auto Login setting. + +**3.8.0** + +- Feature: @timnolte - Ability to use 6 new constants for setting client configuration instead of storing in the DB. +- Improvement: @timnolte - NPM version requirements for development. +- Improvement: @timnolte - Travis CI build fixes. +- Improvement: @timnolte - GrumPHP configuration updates for code contributions. +- Improvement: @timnolte - Refactored to meet WordPress coding standards. +- Improvement: @timnolte - Refactored to provide localization. +- Improvement: @timnolte - Refactored to provide a Docker-based local development environment. + +**3.7.1** + +- Fix: Release Version Number. + +**3.7.0** + +- Feature: @timnolte - Ability to enable/disable token refresh. Useful for IDPs that don't support token refresh. +- Feature: @timnolte - Support custom redirect URL(`redirect_to`) with the authentication URL & login button shortcodes. +- Supports additional attribute overrides including login `button_text`, `endpoint_login`, `scope`, `redirect_uri`. + +**3.6.0** + +- Improvement: @RobjS - Improved error messages during login state failure. +- Improvement: @RobjS - New developer filter for login form button URL. +- Fix: @cs1m0n - Only increment username during new user creation if the "Link existing user" setting is enabled. +- Fix: @xRy-42 - Allow periods and spaces in usernames to match what WordPress core allows. +- Feature: @benochen - New setting named "Create user if does not exist" determines whether new users are created during login attempts. +- Improvement: @flat235 - Username transliteration and normalization. + +**3.5.1** + +- Fix: @daggerhart - New approach to state management using transients. + +**3.5.0** + +- Readme fix: @thijskh - Fix syntax error in example openid-connect-generic-login-button-text +- Feature: @slavicd - Allow override of the plugin by posting credentials to wp-login.php +- Feature: @gassan - New action on use login +- Fix: @daggerhart - Avoid double question marks in auth url query string +- Fix: @drzraf - wp-cli bootstrap must not inhibit custom rewrite rules +- Syntax change: @mullikine - Change PHP keywords to comply with PSR2 + +**3.4.1** + +- Minor documentation update and additional error checking. + +**3.4.0** + +- Feature: @drzraf - New filter hook: ability to filter claim and derived user data before user creation. +- Feature: @anttileppa - State time limit can now be changed on the settings page. +- Fix: @drzraf - Fix PHP notice when using traditional login, $token_response may be empty. +- Fix: @drzraf - Fixed a notice when cookie does not contain expected redirect_url + +**3.3.1** + +- Prefixing classes for more efficient autoloading. +- Avoid altering global wp_remote_post() parameters. +- Minor metadata updates for wp.org + +**3.3.0** + +- Fix: @pjeby - Handle multiple user sessions better by using the `WP_Session_Tokens` object. Predecessor to fixes for multiple other issues: #49, #50, #51 + +**3.2.1** + +- Bug fix: @svenvanhal - Exit after issuing redirect. Fixes #46 + +**3.2.0** + +- Feature: @robbiepaul - trigger core action `wp_login` when user is logged in through this plugin +- Feature: @moriyoshi - Determine the WP_User display name with replacement tokens on the settings page. Tokens can be any property of the user_claim. +- Feature: New setting to set redirect URL when session expires. +- Feature: @robbiepaul - New filter for modifying authentication URL +- Fix: @cedrox - Adding id_token_hint to logout URL according to spec +- Bug fix: Provide port to the request header when requesting the user_claim + +**3.1.0** + +- Feature: @rwasef1830 - Refresh tokens +- Feature: @rwasef1830 - Integrated logout support with end_session endpoint +- Feature: May use an alternate redirect_uri that doesn't rely on admin-ajax +- Feature: @ahatherly - Support for IDP behind reverse proxy +- Bug fix: @robertstaddon - case insensitive check for Bearer token +- Bug fix: @rwasef1830 - "redirect to origin when auto-sso" cookie issue +- Bug fix: @rwasef1830 - PHP Warnings headers already sent due to attempts to redirect and set cookies during login form message +- Bug fix: @rwasef1830 - expire session when access_token expires if no refresh token found +- UX fix: @rwasef1830 - Show login button on error redirect when using auto-sso + +**3.0.8** + +- Feature: @wgengarelly - Added `openid-connect-generic-update-user-using-current-claim` action hook allowing other plugins/themes + to take action using the fresh claims received when an existing user logs in. + +**3.0.7** + +- Bug fix: @wgengarelly - When requesting userinfo, send the access token using the Authorization header field as recommended in + section 5.3.1 of the specs. + +**3.0.6** + +- Bug fix: @robertstaddon - If "Link Existing Users" is enabled, allow users who login with OpenID Connect to also log in with WordPress credentials + +**3.0.5** + +- Feature: @robertstaddon - Added `[openid_connect_generic_login_button]` shortcode to allow the login button to be placed anywhere +- Feature: @robertstaddon - Added setting to "Redirect Back to Origin Page" after a successful login instead of redirecting to the home page. + +**3.0.4** + +- Feature: @robertstaddon - Added setting to allow linking existing WordPress user accounts with newly-authenticated OpenID Connect login + +**3.0.3** + +- Using WordPresss's is_ssl() for setcookie()'s "secure" parameter +- Bug fix: Incrementing username in case of collision. +- Bug fix: Wrong error sent when missing token body + +**3.0.2** + +- Added http_request_timeout setting + +**3.0.1** + +- Finalizing 3.0.x api + +**3.0** + +- Complete rewrite to separate concerns +- Changed settings keys for clarity (requires updating settings if upgrading from another version) +- Error logging + +**2.1** + +- Working my way closer to spec. Possible breaking change. Now checking for preferred_username as priority. +- New username determination to avoid collisions + +**2.0** + +Complete rewrite diff --git a/wp-content/plugins/openid-connect-generic/HOWTO.md b/wp-content/plugins/openid-connect-generic/HOWTO.md new file mode 100644 index 00000000..be34dfe1 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/HOWTO.md @@ -0,0 +1,383 @@ +# OpenID Connect Generic Client + +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +A simple client that provides SSO or opt-in authentication against a generic OAuth2 Server implementation. + +## Description + +This plugin allows to authenticate users against OpenID Connect OAuth2 API with Authorization Code Flow. +Once installed, it can be configured to automatically authenticate users (SSO), or provide a "Login with OpenID Connect" +button on the login form. After consent has been obtained, an existing user is automatically logged into WordPress, while +new users are created in WordPress database. + +Much of the documentation can be found on the Settings > OpenID Connect Generic dashboard page. + +## Table of Contents + +- [Installation](#installation) + - [Composer](#composer) +- [Frequently Asked Questions](#frequently-asked-questions) + - [What is the client's Redirect URI?](#what-is-the-clients-redirect-uri) + - [Can I change the client's Redirect URI?](#can-i-change-the-clients-redirect-uri) +- [Configuration Environment Variables/Constants](#configuration-environment-variables-constants) +- [Hooks](#hooks) + - [Filters](#filters) + - [openid-connect-generic-alter-request](#openid-connect-generic-alter-request) + - [openid-connect-generic-login-button-text](#openid-connect-generic-login-button-text) + - [openid-connect-generic-auth-url](#openid-connect-generic-auth-url) + - [openid-connect-generic-user-login-test](#openid-connect-generic-user-login-test) + - [openid-connect-generic-user-creation-test](#openid-connect-generic-user-creation-test) + - [openid-connect-generic-alter-user-claim](#openid-connect-generic-alter-user-claim) + - [openid-connect-generic-alter-user-data](#openid-connect-generic-alter-user-data) + - [openid-connect-generic-settings-fields](#openid-connect-generic-settings-fields) + - [Actions](#actions) + - [openid-connect-generic-user-create](#openid-connect-generic-user-create) + - [openid-connect-generic-user-update](#openid-connect-generic-user-update) + - [openid-connect-generic-update-user-using-current-claim](#openid-connect-generic-update-user-using-current-claim) + - [openid-connect-generic-redirect-user-back](#openid-connect-generic-redirect-user-back) + + +## Installation + +1. Upload to the `/wp-content/plugins/` directory +1. Activate the plugin +1. Visit Settings > OpenID Connect and configure to meet your needs + +### Composer + +[OpenID Connect Generic on packagist](https://packagist.org/packages/daggerhart/openid-connect-generic) + +Installation: + +`composer require daggerhart/openid-connect-generic` + + +## Frequently Asked Questions + +### What is the client's Redirect URI? + +Most OAuth2 servers should require a whitelist of redirect URIs for security purposes. The Redirect URI provided +by this client is like so: `https://example.com/wp-admin/admin-ajax.php?action=openid-connect-authorize` + +Replace `example.com` with your domain name and path to WordPress. + +### Can I change the client's Redirect URI? + +Some OAuth2 servers do not allow for a client redirect URI to contain a query string. The default URI provided by +this module leverages WordPress's `admin-ajax.php` endpoint as an easy way to provide a route that does not include +HTML, but this will naturally involve a query string. Fortunately, this plugin provides a setting that will make use of +an alternate redirect URI that does not include a query string. + +On the settings page for this plugin (Dashboard > Settings > OpenID Connect Generic) there is a checkbox for +**Alternate Redirect URI**. When checked, the plugin will use the Redirect URI +`https://example.com/openid-connect-authorize`. + +## Configuration Environment Variables/Constants + +- Client ID: `OIDC_CLIENT_ID` +- Client Secret Key: `OIDC_CLIENT_SECRET` +- Login Endpoint URL: `OIDC_ENDPOINT_LOGIN_URL` +- Userinfo Endpoint URL: `OIDC_ENDPOINT_USERINFO_URL` +- Token Validation Endpoint URL: `OIDC_ENDPOINT_TOKEN_URL` +- End Session Endpoint URL: `OIDC_ENDPOINT_LOGOUT_URL` +- OpenID scope: `OIDC_CLIENT_SCOPE` (space separated) +- OpenID login type: `OIDC_LOGIN_TYPE` ('button' or 'auto') +- Enforce privacy: `OIDC_ENFORCE_PRIVACY` (boolean) +- Create user if they do not exist: `OIDC_CREATE_IF_DOES_NOT_EXIST` (boolean) +- Link existing user: `OIDC_LINK_EXISTING_USERS` (boolean) +- Redirect user back to origin page: `OIDC_REDIRECT_USER_BACK` (boolean) +- Redirect on logout: `OIDC_REDIRECT_ON_LOGOUT` (boolean) + +## Hooks + +This plugin provides a number of hooks to allow for a significant amount of customization of the plugin operations from +elsewhere in the WordPress system. + +### Filters + +Filters are WordPress hooks that are used to modify data. The first argument in a filter hook is always expected to be +returned at the end of the hook. + +WordPress filters API - [`add_filter()`](https://developer.wordpress.org/reference/functions/add_filter/) and +[`apply_filters()`](https://developer.wordpress.org/reference/functions/apply_filters/). + +Most often you'll only need to use `add_filter()` to hook into this plugin's code. + +#### `openid-connect-generic-alter-request` + +Hooks directly into client before requests are sent to the OpenID Server. + +Provides 2 arguments: the request array being sent to the server, and the operation currently being executed by this +plugin. + +Possible operations: + +- get-authentication-token +- refresh-token +- get-userinfo + +``` +add_filter('openid-connect-generic-alter-request', function( $request, $operation ) { + if ( $operation == 'get-authentication-token' ) { + $request['some_key'] = 'modified value'; + } + + return $request; +}, 10, 2); +``` + +#### `openid-connect-generic-login-button-text` + +Modify the login button text. Default value is `__( 'Login with OpenID Connect' )`. + +Provides 1 argument: the current login button text. + +``` +add_filter('openid-connect-generic-login-button-text', function( $text ) { + $text = __('Login to my super cool IDP server'); + + return $text; +}); +``` + +#### `openid-connect-generic-auth-url` + +Modify the authentication URL before presented to the user. This is the URL that will send the user to the IDP server +for login. + +Provides 1 argument: the plugin generated URL. + +``` +add_filter('openid-connect-generic-auth-url', function( $url ) { + // Add some custom data to the url. + $url.= '&my_custom_data=123abc'; + return $url; +}); +``` + +#### `openid-connect-generic-user-login-test` + +Determine whether or not the user should be logged into WordPress. + +Provides 2 arguments: the boolean result of the test (default `TRUE`), and the `$user_claim` array from the server. + +``` +add_filter('openid-connect-generic-user-login-test', function( $result, $user_claim ) { + // Don't let Terry login. + if ( $user_claim['email'] == 'terry@example.com' ) { + $result = FALSE; + } + + return $result; +}, 10, 2); +``` + +#### `openid-connect-generic-user-creation-test` + +Determine whether or not the user should be created. This filter is called when a new user is trying to login and they +do not currently exist within WordPress. + +Provides 2 arguments: the boolean result of the test (default `TRUE`), and the `$user_claim` array from the server. + +``` +add_filter('', function( $result, $user_claim ) { + // Don't let anyone from example.com create an account. + $email_array = explode( '@', $user_claim['email'] ); + if ( $email_array[1] == 'example.com' ) { + $result = FALSE; + } + + return $result; +}, 10, 2) +``` + +#### `openid-connect-generic-alter-user-claim` + +Modify the `$user_claim` before the plugin builds the `$user_data` array for new user created. + +**Deprecated** - This filter is not very useful due to some changes that were added later. Recommend not using this +filter, and using the `openid-connect-generic-alter-user-data` filter instead. Practically, you can only change the +user's `first_name` and `last_name` values with this filter, but you could easily do that in +`openid-connect-generic-alter-user-data` as well. + +Provides 1 argument: the `$user_claim` from the server. + +``` +// Not a great example because the hook isn't very useful. +add_filter('openid-connect-generic-alter-user-claim', function( $user_claim ) { + // Use the beginning of the user's email address as the user's first name. + if ( empty( $user_claim['given_name'] ) ) { + $email_array = explode( '@', $user_claim['email'] ); + $user_claim['given_name'] = $email_array[0]; + } + + return $user_claim; +}); +``` + +#### `openid-connect-generic-alter-user-data` + +Modify a new user's data immediately before the user is created. + +Provides 2 arguments: the `$user_data` array that will be sent to `wp_insert_user()`, and the `$user_claim` from the +server. + +``` +add_filter('openid-connect-generic-alter-user-data', function( $user_data, $user_claim ) { + // Don't register any user with their real email address. Create a fake internal address. + if ( !empty( $user_data['user_email'] ) ) { + $email_array = explode( '@', $user_data['user_email'] ); + $email_array[1] = 'my-fake-domain.co'; + $user_data['user_email'] = implode( '@', $email_array ); + } + + return $user_data; +}, 10, 2); +``` + +#### `openid-connect-generic-settings-fields` + +For extending the plugin with a new setting field (found on Dashboard > Settings > OpenID Connect Generic) that the site +administrator can modify. Also useful to alter the existing settings fields. + +See `/includes/openid-connect-generic-settings-page.php` for how fields are constructed. + +New settings fields will be automatically saved into the wp_option for this plugin's settings, and will be available in +the `\OpenID_Connect_Generic_Option_Settings` object this plugin uses. + +**Note:** It can be difficult to get a copy of the settings from within other hooks. The easiest way to make use of +settings in your custom hooks is to call +`$settings = get_option('openid_connect_generic_settings', array());`. + +Provides 1 argument: the existing fields array. + +``` +add_filter('openid-connect-generic-settings-fields', function( $fields ) { + + // Modify an existing field's title. + $fields['endpoint_userinfo']['title'] = __('User information endpoint url'); + + // Add a new field that is a simple checkbox. + $fields['block_terry'] = array( + 'title' => __('Block Terry'), + 'description' => __('Prevent Terry from logging in'), + 'type' => 'checkbox', + 'section' => 'authorization_settings', + ); + + // A select field that provides options. + + $fields['deal_with_terry'] = array( + 'title' => __('Manage Terry'), + 'description' => __('How to deal with Terry when he tries to log in.'), + 'type' => 'select', + 'options' => array( + 'allow' => __('Allow login'), + 'block' => __('Block'), + 'redirect' => __('Redirect'), + ), + 'section' => 'authorization_settings', + ); + + return $fields; +}); +``` +"Sections" are where your setting appears on the admin settings page. Keys for settings sections: + +- client_settings +- user_settings +- authorization_settings +- log_settings + +Field types: + +- text +- checkbox +- select (requires an array of "options") + +### Actions + +WordPress actions are generic events that other plugins can react to. + +Actions API: [`add_action`](https://developer.wordpress.org/reference/functions/add_action/) and [`do_actions`](https://developer.wordpress.org/reference/functions/do_action/) + +You'll probably only ever want to use `add_action` when hooking into this plugin. + +#### `openid-connect-generic-user-create` + +React to a new user being created by this plugin. + +Provides 2 arguments: the `\WP_User` object that was created, and the `$user_claim` from the IDP server. + +``` +add_action('openid-connect-generic-user-create', function( $user, $user_claim ) { + // Send the user an email when their account is first created. + wp_mail( + $user->user_email, + __('Welcome to my web zone'), + "Hi {$user->first_name},\n\nYour account has been created at my cool website.\n\n Enjoy!" + ); +}, 10, 2); +``` + +#### `openid-connect-generic-user-update` + +React to the user being updated after login. This is the event that happens when a user logins and they already exist as +a user in WordPress, as opposed to a new WordPress user being created. + +Provides 1 argument: the user's WordPress user ID. + +``` +add_action('openid-connect-generic-user-update', function( $uid ) { + // Keep track of the number of times the user has logged into the site. + $login_count = get_user_meta( $uid, 'my-user-login-count', TRUE); + $login_count += 1; + add_user_meta( $uid, 'my-user-login-count', $login_count, TRUE); +}); +``` + +#### `openid-connect-generic-update-user-using-current-claim` + +React to an existing user logging in (after authentication and authorization). + +Provides 2 arguments: the `WP_User` object, and the `$user_claim` provided by the IDP server. + +``` +add_action('openid-connect-generic-update-user-using-current-claim', function( $user, $user_claim) { + // Based on some data in the user_claim, modify the user. + if ( !empty( $user_claim['wp_user_role'] ) ) { + if ( $user_claim['wp_user_role'] == 'should-be-editor' ) { + $user->set_role( 'editor' ); + } + } +}, 10, 2); +``` + +#### `openid-connect-generic-redirect-user-back` + +React to a user being redirected after a successful login. This hook is the last hook that will fire when a user logs +in. It will only fire if the plugin setting "Redirect Back to Origin Page" is enabled at Dashboard > Settings > +OpenID Connect Generic. It will fire for both new and existing users. + +Provides 2 arguments: the url where the user will be redirected, and the `WP_User` object. + +``` +add_action('openid-connect-generic-redirect-user-back', function( $redirect_url, $user ) { + // Take over the redirection complete. Send users somewhere special based on their capabilities. + if ( $user->has_cap( 'edit_users' ) ) { + wp_redirect( admin_url( 'users.php' ) ); + exit(); + } +}, 10, 2); +``` + +### User Meta Data + +This plugin stores meta data about the user for both practical and debugging purposes. + +* `openid-connect-generic-subject-identity` - The identity of the user provided by the IDP server. +* `openid-connect-generic-last-id-token-claim` - The user's most recent `id_token` claim, decoded and stored as an array. +* `openid-connect-generic-last-user-claim` - The user's most recent `user_claim`, stored as an array. +* `openid-connect-generic-last-token-response` - The user's most recent `token_response`, stored as an array. diff --git a/wp-content/plugins/openid-connect-generic/README.md b/wp-content/plugins/openid-connect-generic/README.md new file mode 100644 index 00000000..9ee73b2f --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/README.md @@ -0,0 +1,125 @@ +# OpenID Connect Generic Client # +**Contributors:** [daggerhart](https://profiles.wordpress.org/daggerhart/), [tnolte](https://profiles.wordpress.org/tnolte/) +**Donate link:** http://www.daggerhart.com/ +**Tags:** security, login, oauth2, openidconnect, apps, authentication, autologin, sso +**Requires at least:** 5.0 +**Tested up to:** 6.4.3 +**Stable tag:** 3.10.0 +**Requires PHP:** 7.4 +**License:** GPLv2 or later +**License URI:** http://www.gnu.org/licenses/gpl-2.0.html + +A simple client that provides SSO or opt-in authentication against a generic OAuth2 Server implementation. + +## Description ## + +This plugin allows to authenticate users against OpenID Connect OAuth2 API with Authorization Code Flow. +Once installed, it can be configured to automatically authenticate users (SSO), or provide a "Login with OpenID Connect" +button on the login form. After consent has been obtained, an existing user is automatically logged into WordPress, while +new users are created in WordPress database. + +Much of the documentation can be found on the Settings > OpenID Connect Generic dashboard page. + +Please submit issues to the Github repo: https://github.com/daggerhart/openid-connect-generic + +## Installation ## + +1. Upload to the `/wp-content/plugins/` directory +1. Activate the plugin +1. Visit Settings > OpenID Connect and configure to meet your needs + +## Frequently Asked Questions ## + +### What is the client's Redirect URI? ### + +Most OAuth2 servers will require whitelisting a set of redirect URIs for security purposes. The Redirect URI provided +by this client is like so: https://example.com/wp-admin/admin-ajax.php?action=openid-connect-authorize + +Replace `example.com` with your domain name and path to WordPress. + +### Can I change the client's Redirect URI? ### + +Some OAuth2 servers do not allow for a client redirect URI to contain a query string. The default URI provided by +this module leverages WordPress's `admin-ajax.php` endpoint as an easy way to provide a route that does not include +HTML, but this will naturally involve a query string. Fortunately, this plugin provides a setting that will make use of +an alternate redirect URI that does not include a query string. + +On the settings page for this plugin (Dashboard > Settings > OpenID Connect Generic) there is a checkbox for +**Alternate Redirect URI**. When checked, the plugin will use the Redirect URI +`https://example.com/openid-connect-authorize`. + + +## Changelog ## + +### 3.10.0 ### + +* Chore: @timnolte - Dependency updates. +* Fix: @drzraf - Prevents running the auth url filter twice. +* Fix: @timnolte - Updates the log cleanup handling to properly retain the configured number of log entries. +* Fix: @timnolte - Updates the log display output to reflect the log retention policy. +* Chore: @timnolte - Adds Unit Testing & New Local Development Environment. +* Feature: @timnolte - Updates logging to allow for tracking processing time. +* Feature: @menno-ll - Adds a remember me feature via a new filter. +* Improvement: @menno-ll - Updates WP Cookie Expiration to Same as Session Length. + +### 3.9.1 ### + +* Improvement: @timnolte - Refactors Composer setup and GitHub Actions. +* Improvement: @timnolte - Bumps WordPress tested version compatibility. + +### 3.9.0 ### + +* Feature: @matchaxnb - Added support for additional configuration constants. +* Feature: @schanzen - Added support for agregated claims. +* Fix: @rkcreation - Fixed access token not updating user metadata after login. +* Fix: @danc1248 - Fixed user creation issue on Multisite Networks. +* Feature: @RobjS - Added plugin singleton to support for more developer customization. +* Feature: @jkouris - Added action hook to allow custom handling of session expiration. +* Fix: @tommcc - Fixed admin CSS loading only on the plugin settings screen. +* Feature: @rkcreation - Added method to refresh the user claim. +* Feature: @Glowsome - Added acr_values support & verification checks that it when defined in options is honored. +* Fix: @timnolte - Fixed regression which caused improper fallback on missing claims. +* Fix: @slykar - Fixed missing query string handling in redirect URL. +* Fix: @timnolte - Fixed issue with some user linking and user creation handling. +* Improvement: @timnolte - Fixed plugin settings typos and screen formatting. +* Security: @timnolte - Updated build tooling security vulnerabilities. +* Improvement: @timnolte - Changed build tooling scripts. + +### 3.8.5 ### + +* Fix: @timnolte - Fixed missing URL request validation before use & ensure proper current page URL is setup for Redirect Back. +* Fix: @timnolte - Fixed Redirect URL Logic to Handle Sub-directory Installs. +* Fix: @timnolte - Fixed issue with redirecting user back when the openid_connect_generic_auth_url shortcode is used. + +### 3.8.4 ### + +* Fix: @timnolte - Fixed invalid State object access for redirection handling. +* Improvement: @timnolte - Fixed local wp-env Docker development environment. +* Improvement: @timnolte - Fixed Composer scripts for linting and static analysis. + +### 3.8.3 ### + +* Fix: @timnolte - Fixed problems with proper redirect handling. +* Improvement: @timnolte - Changes redirect handling to use State instead of cookies. +* Improvement: @timnolte - Refactored additional code to meet coding standards. + +### 3.8.2 ### + +* Fix: @timnolte - Fixed reported XSS vulnerability on WordPress login screen. + +### 3.8.1 ### + +* Fix: @timnolte - Prevent SSO redirect on password protected posts. +* Fix: @timnolte - CI/CD build issues. +* Fix: @timnolte - Invalid redirect handling on logout for Auto Login setting. + +### 3.8.0 ### + +* Feature: @timnolte - Ability to use 6 new constants for setting client configuration instead of storing in the DB. +* Improvement: @timnolte - Plugin development & contribution updates. +* Improvement: @timnolte - Refactored to meet WordPress coding standards. +* Improvement: @timnolte - Refactored to provide localization. + +-------- + +[See the previous changelogs here](https://github.com/oidc-wp/openid-connect-generic/blob/main/CHANGELOG.md#changelog) diff --git a/wp-content/plugins/openid-connect-generic/SECURITY.md b/wp-content/plugins/openid-connect-generic/SECURITY.md new file mode 100644 index 00000000..99ee0ea0 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/SECURITY.md @@ -0,0 +1,17 @@ +# Security Policy + +## Supported Versions + +We follow the [WordPress Core style of versioning](https://make.wordpress.org/core/handbook/about/release-cycle/version-numbering/) rather than traditional [SemVer](https://semver.org/). This means that a move from version 3.9 to 4.0 is no different from a move from version 3.8 to 3.9. When a **PATCH** version is released it represents a bug fix, or non-code, only change. + +The latest version released is the only version that will receive security updates, generally as a **PATCH** release unless a security issue requires a functionality change in which requires a minor/major version bump. + +## Reporting a Vulnerability + +For security reasons, the following are acceptable options for reporting all security issues. + +1. Via Keybase secure message to [timnolte](https://keybase.io/timnolte/chat) or [daggerhart](https://keybase.io/daggerhart/chat). +2. Send a DM via the [WordPress Slack](https://make.wordpress.org/chat/) to `tnolte`. +3. Via a private [security advisory](https://github.com/oidc-wp/openid-connect-generic/security/advisories) notice. + +Please disclose responsibly and not via public GitHub Issues (which allows for exploiting issues in the wild before the patch is released). diff --git a/wp-content/plugins/openid-connect-generic/codecov.yml b/wp-content/plugins/openid-connect-generic/codecov.yml new file mode 100644 index 00000000..2e3090aa --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/codecov.yml @@ -0,0 +1,10 @@ +coverage: + status: + project: + default: + target: auto + threshold: 0.5% + patch: off + +comment: + require_changes: true diff --git a/wp-content/plugins/openid-connect-generic/css/styles-admin.css b/wp-content/plugins/openid-connect-generic/css/styles-admin.css new file mode 100644 index 00000000..cc4c6f99 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/css/styles-admin.css @@ -0,0 +1,32 @@ +#logger-table .col-data { + width: 85% +} + +#logger-table .col-data pre { + margin: 0; + white-space: pre; /* CSS 2.0 */ + white-space: pre-wrap; /* CSS 2.1 */ + white-space: pre-line; /* CSS 3.0 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: -moz-pre-wrap; /* Mozilla */ + white-space: -hp-pre-wrap; /* HP Printers */ + word-wrap: break-word; /* IE 5+ */ +} + +#logger-table .col-details { + width: 200px; +} + +#logger-table .col-details div { + padding: 4px 0; + border-bottom: 1px solid #bbb; +} + +#logger-table .col-details div:last-child { + border-bottom: none; +} + +#logger-table .col-details label { + font-weight: bold; +} diff --git a/wp-content/plugins/openid-connect-generic/docker-compose.yml b/wp-content/plugins/openid-connect-generic/docker-compose.yml new file mode 100644 index 00000000..a2778087 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/docker-compose.yml @@ -0,0 +1,95 @@ +# This is the Compose file for command-line services. +# Anything that doesn't need to be run as part of the main `docker-compose up' +# command should reside in here and be invoked by a helper script. +version: "3.7" + +services: + app: + image: ghcr.io/ndigitals/wp-dev-container:php-8.0-node-16 + restart: always + depends_on: + - db + - phpmyadmin + - web + - mailhog + working_dir: /workspaces/openid-connect-generic + environment: &env + WORDPRESS_DB_HOST: db + WORDPRESS_DB_NAME: wordpress + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_TEST_DB_NAME: wordpress_test + CODESPACES: "${CODESPACES}" + CODESPACE_NAME: "${CODESPACE_NAME}" + GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN: "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" + volumes: + - .:/workspaces/openid-connect-generic:cached + - ./tools/local-env:/app:cached + - ./tools/php/php-cli.ini:/usr/local/etc/php/php-cli.ini:ro,cached + - .:/app/wp-content/plugins/daggerhart-openid-connect-generic:ro,cached + - ~/.composer:/root/.composer:cached + - ~/.npm:/root/.npm:cached + networks: + - oidcwp-net + + web: + image: httpd + restart: unless-stopped + depends_on: + - db + ports: + - 8080:80 + environment: + <<: *env + volumes: + - ./tools/local-env:/app:cached + - .:/app/wp-content/plugins/daggerhart-openid-connect-generic:ro,cached + - ./tools/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro,cached + networks: + - oidcwp-net + + db: + image: mariadb + restart: unless-stopped + ports: + - 3306:3306 + environment: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + volumes: + - db:/var/lib/mysql + - ./tests/db-wordpress_test.sql:/docker-entrypoint-initdb.d/db-wordpress_test.sql + networks: + - oidcwp-net + + phpmyadmin: + image: phpmyadmin + restart: unless-stopped + depends_on: + - db + ports: + - 8081:8081 + environment: + PMA_HOST: db + APACHE_PORT: 8081 + networks: + - oidcwp-net + + ## SMTP Server + Web Interface for viewing and testing emails during development. + mailhog: + image: mailhog/mailhog + restart: unless-stopped + ports: + - 1025:1025 # smtp server + - 8026:8025 # web ui + networks: + - oidcwp-net + +volumes: + db: + +networks: + oidcwp-net: + diff --git a/wp-content/plugins/openid-connect-generic/includes/functions.php b/wp-content/plugins/openid-connect-generic/includes/functions.php new file mode 100644 index 00000000..832328ff --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/includes/functions.php @@ -0,0 +1,30 @@ + + * @copyright 2015-2020 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * Return a single use authentication URL. + * + * @return string + */ +function oidcg_get_authentication_url() { + return \OpenID_Connect_Generic::instance()->client_wrapper->get_authentication_url(); +} + +/** + * Refresh a user claim and update the user metadata. + * + * @param WP_User $user The user object. + * @param array $token_response The token response. + * + * @return WP_Error|array + */ +function oidcg_refresh_user_claim( $user, $token_response ) { + return \OpenID_Connect_Generic::instance()->client_wrapper->refresh_user_claim( $user, $token_response ); +} diff --git a/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client-wrapper.php b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client-wrapper.php new file mode 100644 index 00000000..294d1b0e --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client-wrapper.php @@ -0,0 +1,1180 @@ + + * @copyright 2015-2020 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenID_Connect_Generic_Client_Wrapper class. + * + * Plugin OIDC/oAuth client wrapper class. + * + * @package OpenID_Connect_Generic + * @category Authentication + */ +class OpenID_Connect_Generic_Client_Wrapper { + + /** + * The client object instance. + * + * @var OpenID_Connect_Generic_Client + */ + private $client; + + /** + * The settings object instance. + * + * @var OpenID_Connect_Generic_Option_Settings + */ + private $settings; + + /** + * The logger object instance. + * + * @var OpenID_Connect_Generic_Option_Logger + */ + private $logger; + + /** + * The token refresh info cookie key. + * + * @var string + */ + private $cookie_token_refresh_key = 'openid-connect-generic-refresh'; + + /** + * The user redirect cookie key. + * + * @deprecated Redirection should be done via state transient and not cookies. + * + * @var string + */ + public $cookie_redirect_key = 'openid-connect-generic-redirect'; + + /** + * The return error onject. + * + * @example WP_Error if there was a problem, or false if no error + * + * @var bool|WP_Error + */ + private $error = false; + + /** + * Used to pass the openid token refresh expiration time to the auth_cookie_expiration filter. + * + * @var integer + */ + private $openid_token_refresh_expires_in = 0; + + /** + * Inject necessary objects and services into the client. + * + * @param OpenID_Connect_Generic_Client $client A plugin client object instance. + * @param OpenID_Connect_Generic_Option_Settings $settings A plugin settings object instance. + * @param OpenID_Connect_Generic_Option_Logger $logger A plugin logger object instance. + */ + public function __construct( OpenID_Connect_Generic_Client $client, OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ) { + $this->client = $client; + $this->settings = $settings; + $this->logger = $logger; + } + + /** + * Hook the client into WordPress. + * + * @param \OpenID_Connect_Generic_Client $client The plugin client instance. + * @param \OpenID_Connect_Generic_Option_Settings $settings The plugin settings instance. + * @param \OpenID_Connect_Generic_Option_Logger $logger The plugin logger instance. + * + * @return \OpenID_Connect_Generic_Client_Wrapper + */ + public static function register( OpenID_Connect_Generic_Client $client, OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ) { + $client_wrapper = new self( $client, $settings, $logger ); + + // Integrated logout. + if ( $settings->endpoint_end_session ) { + add_filter( 'allowed_redirect_hosts', array( $client_wrapper, 'update_allowed_redirect_hosts' ), 99, 1 ); + add_filter( 'logout_redirect', array( $client_wrapper, 'get_end_session_logout_redirect_url' ), 99, 3 ); + } + + // Alter the requests according to settings. + add_filter( 'openid-connect-generic-alter-request', array( $client_wrapper, 'alter_request' ), 10, 2 ); + + if ( is_admin() ) { + /* + * Use the ajax url to handle processing authorization without any html output + * this callback will occur when then IDP returns with an authenticated value + */ + add_action( 'wp_ajax_openid-connect-authorize', array( $client_wrapper, 'authentication_request_callback' ) ); + add_action( 'wp_ajax_nopriv_openid-connect-authorize', array( $client_wrapper, 'authentication_request_callback' ) ); + } + + if ( $settings->alternate_redirect_uri ) { + // Provide an alternate route for authentication_request_callback. + add_rewrite_rule( '^openid-connect-authorize/?', 'index.php?openid-connect-authorize=1', 'top' ); + add_rewrite_tag( '%openid-connect-authorize%', '1' ); + add_action( 'parse_request', array( $client_wrapper, 'alternate_redirect_uri_parse_request' ) ); + } + + // Verify token for any logged in user. + if ( is_user_logged_in() ) { + add_action( 'wp_loaded', array( $client_wrapper, 'ensure_tokens_still_fresh' ) ); + } + + return $client_wrapper; + } + + /** + * Implements WordPress parse_request action. + * + * @param WP_Query $query The WordPress query object. + * + * @return void + */ + public function alternate_redirect_uri_parse_request( $query ) { + if ( isset( $query->query_vars['openid-connect-authorize'] ) && + '1' === $query->query_vars['openid-connect-authorize'] ) { + $this->authentication_request_callback(); + exit; + } + } + + /** + * Get the client login redirect. + * + * @return string + */ + public function get_redirect_to() { + /* + * @var WP $wp + */ + global $wp; + + if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' == $GLOBALS['pagenow'] && isset( $_GET['action'] ) && 'logout' === $_GET['action'] ) { + return ''; + } + + // Default redirect to the homepage. + $redirect_url = home_url(); + + // If using the login form, default redirect to the admin dashboard. + if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' == $GLOBALS['pagenow'] ) { + $redirect_url = admin_url(); + } + + // Honor Core WordPress & other plugin redirects. + if ( isset( $_REQUEST['redirect_to'] ) ) { + $redirect_url = esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ); + } + + // Capture the current URL if set to redirect back to origin page. + if ( $this->settings->redirect_user_back ) { + if ( ! empty( $wp->query_string ) ) { + $redirect_url = home_url( '?' . $wp->query_string ); + } + if ( ! empty( $wp->request ) ) { + $redirect_url = home_url( add_query_arg( null, null ) ); + // @phpstan-ignore-next-line + if ( $wp->did_permalink ) { + $redirect_url = home_url( add_query_arg( $_GET, trailingslashit( $wp->request ) ) ); + } + } + } + + // This hook is being deprecated with the move away from cookies. + $redirect_url = apply_filters_deprecated( + 'openid-connect-generic-cookie-redirect-url', + array( $redirect_url ), + '3.8.2', + 'openid-connect-generic-client-redirect-to' + ); + + // This is the new hook to use with the transients version of redirection. + return apply_filters( 'openid-connect-generic-client-redirect-to', $redirect_url ); + } + + /** + * Create a single use authentication url + * + * @param array $atts An optional array of override/feature attributes. + * + * @return string + */ + public function get_authentication_url( $atts = array() ) { + + $atts = shortcode_atts( + array( + 'endpoint_login' => $this->settings->endpoint_login, + 'scope' => $this->settings->scope, + 'client_id' => $this->settings->client_id, + 'redirect_uri' => $this->client->get_redirect_uri(), + 'redirect_to' => $this->get_redirect_to(), + 'acr_values' => $this->settings->acr_values, + ), + $atts, + 'openid_connect_generic_auth_url' + ); + + // Validate the redirect to value to prevent a redirection attack. + if ( ! empty( $atts['redirect_to'] ) ) { + $atts['redirect_to'] = wp_validate_redirect( $atts['redirect_to'], home_url() ); + } + + $separator = '?'; + if ( stripos( $this->settings->endpoint_login, '?' ) !== false ) { + $separator = '&'; + } + + $url_format = '%1$s%2$sresponse_type=code&scope=%3$s&client_id=%4$s&state=%5$s&redirect_uri=%6$s'; + if ( ! empty( $atts['acr_values'] ) ) { + $url_format .= '&acr_values=%7$s'; + } + + $url = sprintf( + $url_format, + $atts['endpoint_login'], + $separator, + rawurlencode( $atts['scope'] ), + rawurlencode( $atts['client_id'] ), + $this->client->new_state( $atts['redirect_to'] ), + rawurlencode( $atts['redirect_uri'] ), + rawurlencode( $atts['acr_values'] ) + ); + + $url = apply_filters( 'openid-connect-generic-auth-url', $url ); + $this->logger->log( $url, 'make_authentication_url' ); + return $url; + } + + /** + * Handle retrieval and validation of refresh_token. + * + * @return void + */ + public function ensure_tokens_still_fresh() { + if ( ! is_user_logged_in() ) { + return; + } + + $user_id = wp_get_current_user()->ID; + $manager = WP_Session_Tokens::get_instance( $user_id ); + $token = wp_get_session_token(); + $session = $manager->get( $token ); + + if ( ! isset( $session[ $this->cookie_token_refresh_key ] ) ) { + // Not an OpenID-based session. + return; + } + + $current_time = time(); + $refresh_token_info = $session[ $this->cookie_token_refresh_key ]; + + $next_access_token_refresh_time = $refresh_token_info['next_access_token_refresh_time']; + + if ( $current_time < $next_access_token_refresh_time ) { + return; + } + + $refresh_token = $refresh_token_info['refresh_token']; + $refresh_expires = $refresh_token_info['refresh_expires']; + + if ( ! $refresh_token || ( $refresh_expires && $current_time > $refresh_expires ) ) { + if ( isset( $_SERVER['REQUEST_URI'] ) ) { + do_action( 'openid-connect-generic-session-expired', wp_get_current_user(), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); + wp_logout(); + + if ( $this->settings->redirect_on_logout ) { + $this->error_redirect( new WP_Error( 'access-token-expired', __( 'Session expired. Please login again.', 'daggerhart-openid-connect-generic' ) ) ); + } + + return; + } + } + + $token_result = $this->client->request_new_tokens( $refresh_token ); + + if ( is_wp_error( $token_result ) ) { + wp_logout(); + $this->error_redirect( $token_result ); + } + + $token_response = $this->client->get_token_response( $token_result ); + + if ( is_wp_error( $token_response ) ) { + wp_logout(); + $this->error_redirect( $token_response ); + } + + update_user_meta( $user_id, 'openid-connect-generic-last-token-response', $token_response ); + $this->save_refresh_token( $manager, $token, $token_response ); + } + + /** + * Handle errors by redirecting the user to the login form along with an + * error code + * + * @param WP_Error $error A WordPress error object. + * + * @return void + */ + public function error_redirect( $error ) { + $this->logger->log( $error ); + + // Redirect user back to login page. + wp_redirect( + wp_login_url() . + '?login-error=' . $error->get_error_code() . + '&message=' . urlencode( $error->get_error_message() ) + ); + exit; + } + + /** + * Get the current error state. + * + * @return bool|WP_Error + */ + public function get_error() { + return $this->error; + } + + /** + * Add the end_session endpoint to WordPress core's whitelist of redirect hosts. + * + * @param array $allowed The allowed redirect host names. + * + * @return array|bool + */ + public function update_allowed_redirect_hosts( $allowed ) { + $host = parse_url( $this->settings->endpoint_end_session, PHP_URL_HOST ); + if ( ! $host ) { + return false; + } + + $allowed[] = $host; + return $allowed; + } + + /** + * Handle the logout redirect for end_session endpoint. + * + * @param string $redirect_url The requested redirect URL. + * @param string $requested_redirect_to The user login source URL, or configured user redirect URL. + * @param WP_User $user The logged in user object. + * + * @return string + */ + public function get_end_session_logout_redirect_url( $redirect_url, $requested_redirect_to, $user ) { + $url = $this->settings->endpoint_end_session; + $query = parse_url( $url, PHP_URL_QUERY ); + $url .= $query ? '&' : '?'; + + // Prevent redirect back to the IDP when logging out in auto mode. + if ( 'auto' === $this->settings->login_type && strpos( $redirect_url, 'wp-login.php?loggedout=true' ) ) { + // By default redirect back to the site home. + $redirect_url = home_url(); + } + + $token_response = $user->get( 'openid-connect-generic-last-token-response' ); + if ( ! $token_response ) { + // Happens if non-openid login was used. + return $redirect_url; + } else if ( ! parse_url( $redirect_url, PHP_URL_HOST ) ) { + // Convert to absolute url if needed, site_url() to be friendly with non-standard (Bedrock) layout. + $redirect_url = site_url( $redirect_url ); + } + + $claim = $user->get( 'openid-connect-generic-last-id-token-claim' ); + + if ( isset( $claim['iss'] ) && 'https://accounts.google.com' == $claim['iss'] ) { + /* + * Google revoke endpoint + * 1. expects the *access_token* to be passed as "token" + * 2. does not support redirection (post_logout_redirect_uri) + * So just redirect to regular WP logout URL. + * (we would *not* disconnect the user from any Google service even + * if he was initially disconnected to them) + */ + return $redirect_url; + } else { + return $url . sprintf( 'id_token_hint=%s&post_logout_redirect_uri=%s', $token_response['id_token'], urlencode( $redirect_url ) ); + } + } + + /** + * Modify outgoing requests according to settings. + * + * @param array $request The outgoing request array. + * @param string $operation The request operation name. + * + * @return mixed + */ + public function alter_request( $request, $operation ) { + if ( ! empty( $this->settings->http_request_timeout ) ) { + $request['timeout'] = intval( $this->settings->http_request_timeout ); + } + + if ( $this->settings->no_sslverify ) { + $request['sslverify'] = false; + } + + return $request; + } + + /** + * Control the authentication and subsequent authorization of the user when + * returning from the IDP. + * + * @return void + */ + public function authentication_request_callback() { + $client = $this->client; + + // Start the authentication flow. + $authentication_request = $client->validate_authentication_request( $_GET ); + + if ( is_wp_error( $authentication_request ) ) { + $this->error_redirect( $authentication_request ); + } + + // Retrieve the authentication code from the authentication request. + $code = $client->get_authentication_code( $authentication_request ); + + if ( is_wp_error( $code ) ) { + $this->error_redirect( $code ); + } + + // Retrieve the authentication state from the authentication request. + $state = $client->get_authentication_state( $authentication_request ); + + if ( is_wp_error( $state ) ) { + $this->error_redirect( $state ); + } + + // Attempting to exchange an authorization code for an authentication token. + $token_result = $client->request_authentication_token( $code ); + + if ( is_wp_error( $token_result ) ) { + $this->error_redirect( $token_result ); + } + + // Get the decoded response from the authentication request result. + $token_response = $client->get_token_response( $token_result ); + + // Allow for other plugins to alter data before validation. + $token_response = apply_filters( 'openid-connect-modify-token-response-before-validation', $token_response ); + + if ( is_wp_error( $token_response ) ) { + $this->error_redirect( $token_response ); + } + + // Ensure the that response contains required information. + $valid = $client->validate_token_response( $token_response ); + + if ( is_wp_error( $valid ) ) { + $this->error_redirect( $valid ); + } + + /** + * The id_token is used to identify the authenticated user, e.g. for SSO. + * The access_token must be used to prove access rights to protected + * resources e.g. for the userinfo endpoint + */ + $id_token_claim = $client->get_id_token_claim( $token_response ); + + // Allow for other plugins to alter data before validation. + $id_token_claim = apply_filters( 'openid-connect-modify-id-token-claim-before-validation', $id_token_claim ); + + if ( is_wp_error( $id_token_claim ) ) { + $this->error_redirect( $id_token_claim ); + } + + // Validate our id_token has required values. + $valid = $client->validate_id_token_claim( $id_token_claim ); + + if ( is_wp_error( $valid ) ) { + $this->error_redirect( $valid ); + } + + // If userinfo endpoint is set, exchange the token_response for a user_claim. + if ( ! empty( $this->settings->endpoint_userinfo ) && isset( $token_response['access_token'] ) ) { + $user_claim = $client->get_user_claim( $token_response ); + } else { + $user_claim = $id_token_claim; + } + + if ( is_wp_error( $user_claim ) ) { + $this->error_redirect( $user_claim ); + } + + // Validate our user_claim has required values. + $valid = $client->validate_user_claim( $user_claim, $id_token_claim ); + + if ( is_wp_error( $valid ) ) { + $this->error_redirect( $valid ); + } + + /** + * End authorization + * - + * Request is authenticated and authorized - start user handling + */ + $subject_identity = $client->get_subject_identity( $id_token_claim ); + $user = $this->get_user_by_identity( $subject_identity ); + + // A pre-existing IDP mapped user wasn't found. + if ( ! $user ) { + // If linking existing users or creating new ones call the `create_new_user` method which handles both cases. + if ( $this->settings->link_existing_users || $this->settings->create_if_does_not_exist ) { + $user = $this->create_new_user( $subject_identity, $user_claim ); + if ( is_wp_error( $user ) ) { + $this->error_redirect( $user ); + } + } else { + $this->error_redirect( new WP_Error( 'identity-not-map-existing-user', __( 'User identity is not linked to an existing WordPress user.', 'daggerhart-openid-connect-generic' ), $user_claim ) ); + } + } + + // Validate the found / created user. + $valid = $this->validate_user( $user ); + + if ( is_wp_error( $valid ) ) { + $this->error_redirect( $valid ); + } + + // Login the found / created user. + $start_time = microtime( true ); + $this->login_user( $user, $token_response, $id_token_claim, $user_claim, $subject_identity ); + $end_time = microtime( true ); + // Log our success. + $this->logger->log( "Successful login for: {$user->user_login} ({$user->ID})", 'login-success', $end_time - $start_time ); + + // Allow plugins / themes to take action once a user is logged in. + $start_time = microtime( true ); + do_action( 'openid-connect-generic-user-logged-in', $user ); + $end_time = microtime( true ); + $this->logger->log( 'openid-connect-generic-user-logged-in', 'do_action', $end_time - $start_time ); + + // Default redirect to the homepage. + $redirect_url = home_url(); + // Redirect user according to redirect set in state. + $state_object = get_transient( 'openid-connect-generic-state--' . $state ); + // Get the redirect URL stored with the corresponding authentication request state. + if ( ! empty( $state_object ) && ! empty( $state_object[ $state ] ) && ! empty( $state_object[ $state ]['redirect_to'] ) ) { + $redirect_url = $state_object[ $state ]['redirect_to']; + } + + // Provide backwards compatibility for customization using the deprecated cookie method. + if ( ! empty( $_COOKIE[ $this->cookie_redirect_key ] ) ) { + $redirect_url = esc_url_raw( wp_unslash( $_COOKIE[ $this->cookie_redirect_key ] ) ); + } + + // Only do redirect-user-back action hook when the plugin is configured for it. + if ( $this->settings->redirect_user_back ) { + do_action( 'openid-connect-generic-redirect-user-back', $redirect_url, $user ); + } + + wp_redirect( $redirect_url ); + + exit; + } + + /** + * Validate the potential WP_User. + * + * @param WP_User|WP_Error|false $user The user object. + * + * @return true|WP_Error + */ + public function validate_user( $user ) { + // Ensure the found user is a real WP_User. + if ( ! is_a( $user, 'WP_User' ) || ! $user->exists() ) { + return new WP_Error( 'invalid-user', __( 'Invalid user.', 'daggerhart-openid-connect-generic' ), $user ); + } + + return true; + } + + /** + * Refresh user claim. + * + * @param WP_User $user The user object. + * @param array $token_response The token response. + * + * @return WP_Error|array + */ + public function refresh_user_claim( $user, $token_response ) { + $client = $this->client; + + /** + * The id_token is used to identify the authenticated user, e.g. for SSO. + * The access_token must be used to prove access rights to protected + * resources e.g. for the userinfo endpoint + */ + $id_token_claim = $client->get_id_token_claim( $token_response ); + + // Allow for other plugins to alter data before validation. + $id_token_claim = apply_filters( 'openid-connect-modify-id-token-claim-before-validation', $id_token_claim ); + + if ( is_wp_error( $id_token_claim ) ) { + return $id_token_claim; + } + + // Validate our id_token has required values. + $valid = $client->validate_id_token_claim( $id_token_claim ); + + if ( is_wp_error( $valid ) ) { + return $valid; + } + + // If userinfo endpoint is set, exchange the token_response for a user_claim. + if ( ! empty( $this->settings->endpoint_userinfo ) && isset( $token_response['access_token'] ) ) { + $user_claim = $client->get_user_claim( $token_response ); + } else { + $user_claim = $id_token_claim; + } + + if ( is_wp_error( $user_claim ) ) { + return $user_claim; + } + + // Validate our user_claim has required values. + $valid = $client->validate_user_claim( $user_claim, $id_token_claim ); + + if ( is_wp_error( $valid ) ) { + $this->error_redirect( $valid ); + return $valid; + } + + // Store the tokens for future reference. + update_user_meta( $user->ID, 'openid-connect-generic-last-token-response', $token_response ); + update_user_meta( $user->ID, 'openid-connect-generic-last-id-token-claim', $id_token_claim ); + update_user_meta( $user->ID, 'openid-connect-generic-last-user-claim', $user_claim ); + + return $user_claim; + } + + /** + * Record user meta data, and provide an authorization cookie. + * + * @param WP_User $user The user object. + * @param array $token_response The token response. + * @param array $id_token_claim The ID token claim. + * @param array $user_claim The authenticated user claim. + * @param string $subject_identity The subject identity from the IDP. + * + * @return void + */ + public function login_user( $user, $token_response, $id_token_claim, $user_claim, $subject_identity ) { + // Store the tokens for future reference. + update_user_meta( $user->ID, 'openid-connect-generic-last-token-response', $token_response ); + update_user_meta( $user->ID, 'openid-connect-generic-last-id-token-claim', $id_token_claim ); + update_user_meta( $user->ID, 'openid-connect-generic-last-user-claim', $user_claim ); + // Allow plugins / themes to take action using current claims on existing user (e.g. update role). + do_action( 'openid-connect-generic-update-user-using-current-claim', $user, $user_claim ); + + // Determine the amount of days before the cookie expires. + $remember_me = apply_filters( 'openid-connect-generic-remember-me', false, $user, $token_response, $id_token_claim, $user_claim, $subject_identity ); + $wp_expiration_days = $remember_me ? 14 : 2; + + // If remember-me is enabled, and using token expiration is enabled, + // add a filter to overwrite the default cookie expiration with the + // openid token expiration. + if ( + $remember_me + && apply_filters( 'openid-connect-generic-use-token-refresh-expiration', false ) + && ( $token_response['refresh_expires_in'] ?? 0 ) + ) { + $this->openid_token_refresh_expires_in = $token_response['refresh_expires_in']; + add_filter( 'auth_cookie_expiration', array( $this, 'set_cookie_expiration_to_openid_token_refresh_expiration' ) ); + } + + // Create the WP session, so we know its token. + $expiration = time() + apply_filters( 'auth_cookie_expiration', $wp_expiration_days * DAY_IN_SECONDS, $user->ID, false ); + $manager = WP_Session_Tokens::get_instance( $user->ID ); + $token = $manager->create( $expiration ); + + // Save the refresh token in the session. + $this->save_refresh_token( $manager, $token, $token_response ); + + // you did great, have a cookie! + wp_set_auth_cookie( $user->ID, $remember_me, '', $token ); + do_action( 'wp_login', $user->user_login, $user ); + + // Remove the filter for the auth cookie expiration after all the auth cookies are set. + remove_filter( 'auth_cookie_expiration', array( $this, 'set_cookie_expiration_to_openid_token_refresh_expiration' ) ); + } + + /** + * Filter callback to overwrite the default cookie expiration with the + * openid token refresh expiration. This is applied both when creating the session + * token as well as when wp_set_auth_cookie is called. + * + * @param integer $expiration_in_seconds The expiration time in seconds. + * @return integer + */ + public function set_cookie_expiration_to_openid_token_refresh_expiration( $expiration_in_seconds ) { + $expiration_in_seconds = $this->openid_token_refresh_expires_in; + return $expiration_in_seconds; + } + + /** + * Save refresh token to WP session tokens + * + * @param WP_Session_Tokens $manager A user session tokens manager. + * @param string $token The current users session token. + * @param array|WP_Error|null $token_response The authentication token response. + */ + public function save_refresh_token( $manager, $token, $token_response ) { + if ( ! $this->settings->token_refresh_enable ) { + return; + } + $session = $manager->get( $token ); + $now = time(); + $session[ $this->cookie_token_refresh_key ] = array( + 'next_access_token_refresh_time' => $token_response['expires_in'] + $now, + 'refresh_token' => isset( $token_response['refresh_token'] ) ? $token_response['refresh_token'] : false, + 'refresh_expires' => false, + ); + if ( isset( $token_response['refresh_expires_in'] ) ) { + $refresh_expires_in = $token_response['refresh_expires_in']; + if ( $refresh_expires_in > 0 ) { + // Leave enough time for the actual refresh request to go through. + $refresh_expires = $now + $refresh_expires_in - 5; + $session[ $this->cookie_token_refresh_key ]['refresh_expires'] = $refresh_expires; + } + } + $manager->update( $token, $session ); + return; + } + + /** + * Get the user that has meta data matching a + * + * @param string $subject_identity The IDP identity of the user. + * + * @return false|WP_User + */ + public function get_user_by_identity( $subject_identity ) { + // Look for user by their openid-connect-generic-subject-identity value. + $user_query = new WP_User_Query( + array( + 'meta_query' => array( + array( + 'key' => 'openid-connect-generic-subject-identity', + 'value' => $subject_identity, + ), + ), + // Override the default blog_id (get_current_blog_id) to find users on different sites of a multisite install. + 'blog_id' => 0, + ) + ); + + // If we found existing users, grab the first one returned. + if ( $user_query->get_total() > 0 ) { + $users = $user_query->get_results(); + return $users[0]; + } + + return false; + } + + /** + * Avoid user_login collisions by incrementing. + * + * @param array $user_claim The IDP authenticated user claim data. + * + * @return string|WP_Error + */ + private function get_username_from_claim( $user_claim ) { + + // @var string $desired_username + $desired_username = ''; + + // Allow settings to take first stab at username. + if ( ! empty( $this->settings->identity_key ) && isset( $user_claim[ $this->settings->identity_key ] ) ) { + $desired_username = $user_claim[ $this->settings->identity_key ]; + } + if ( empty( $desired_username ) && isset( $user_claim['preferred_username'] ) && ! empty( $user_claim['preferred_username'] ) ) { + $desired_username = $user_claim['preferred_username']; + } + if ( empty( $desired_username ) && isset( $user_claim['name'] ) && ! empty( $user_claim['name'] ) ) { + $desired_username = $user_claim['name']; + } + if ( empty( $desired_username ) && isset( $user_claim['email'] ) && ! empty( $user_claim['email'] ) ) { + $tmp = explode( '@', $user_claim['email'] ); + $desired_username = $tmp[0]; + } + if ( empty( $desired_username ) ) { + // Nothing to build a name from. + return new WP_Error( 'no-username', __( 'No appropriate username found.', 'daggerhart-openid-connect-generic' ), $user_claim ); + } + + // Don't use the full email address for a username. + $_desired_username = explode( '@', $desired_username ); + $desired_username = $_desired_username[0]; + // Use WordPress Core to sanitize the IDP username. + $sanitized_username = sanitize_user( $desired_username, true ); + if ( empty( $sanitized_username ) ) { + // translators: %1$s is the santitized version of the username from the IDP. + return new WP_Error( 'username-sanitization-failed', sprintf( __( 'Username %1$s could not be sanitized.', 'daggerhart-openid-connect-generic' ), $desired_username ), $desired_username ); + } + + return $sanitized_username; + } + + /** + * Get a nickname. + * + * @param array $user_claim The IDP authenticated user claim data. + * + * @return string|WP_Error|null + */ + private function get_nickname_from_claim( $user_claim ) { + $desired_nickname = null; + // Allow settings to take first stab at nickname. + if ( ! empty( $this->settings->nickname_key ) && isset( $user_claim[ $this->settings->nickname_key ] ) ) { + $desired_nickname = $user_claim[ $this->settings->nickname_key ]; + } + + if ( empty( $desired_nickname ) ) { + // translators: %1$s is the configured User Claim nickname key. + return new WP_Error( 'no-nickname', sprintf( __( 'No nickname found in user claim using key: %1$s.', 'daggerhart-openid-connect-generic' ), $this->settings->nickname_key ), $this->settings->nickname_key ); + } + + return $desired_nickname; + } + + /** + * Checks if $claimname is in the body or _claim_names of the userinfo. + * If yes, returns the claim value. Otherwise, returns false. + * + * @param string $claimname the claim name to look for. + * @param array $userinfo the JSON to look in. + * @param string $claimvalue the source claim value ( from the body of the JWT of the claim source). + * @return true|false + */ + private function get_claim( $claimname, $userinfo, &$claimvalue ) { + /** + * If we find a simple claim, return it. + */ + if ( array_key_exists( $claimname, $userinfo ) ) { + $claimvalue = $userinfo[ $claimname ]; + return true; + } + /** + * If there are no aggregated claims, it is over. + */ + if ( ! array_key_exists( '_claim_names', $userinfo ) || + ! array_key_exists( '_claim_sources', $userinfo ) ) { + return false; + } + $claim_src_ptr = $userinfo['_claim_names']; + if ( ! isset( $claim_src_ptr ) ) { + return false; + } + /** + * No reference found + */ + if ( ! array_key_exists( $claimname, $claim_src_ptr ) ) { + return false; + } + $src_name = $claim_src_ptr[ $claimname ]; + // Reference found, but no corresponding JWT. This is a malformed userinfo. + if ( ! array_key_exists( $src_name, $userinfo['_claim_sources'] ) ) { + return false; + } + $src = $userinfo['_claim_sources'][ $src_name ]; + // Source claim is not a JWT. Abort. + if ( ! array_key_exists( 'JWT', $src ) ) { + return false; + } + /** + * Extract claim from JWT. + * FIXME: We probably want to verify the JWT signature/issuer here. + * For example, using JWKS if applicable. For symmetrically signed + * JWTs (HMAC), we need a way to specify the acceptable secrets + * and each possible issuer in the config. + */ + $jwt = $src['JWT']; + list ( $header, $body, $rest ) = explode( '.', $jwt, 3 ); + $body_str = base64_decode( $body, false ); + if ( ! $body_str ) { + return false; + } + $body_json = json_decode( $body_str, true ); + if ( ! isset( $body_json ) ) { + return false; + } + if ( ! array_key_exists( $claimname, $body_json ) ) { + return false; + } + $claimvalue = $body_json[ $claimname ]; + return true; + } + + + /** + * Build a string from the user claim according to the specified format. + * + * @param string $format The format format of the user identity. + * @param array $user_claim The authorized user claim. + * @param bool $error_on_missing_key Whether to return and error on a missing key. + * + * @return string|WP_Error + */ + private function format_string_with_claim( $format, $user_claim, $error_on_missing_key = false ) { + $matches = null; + $string = ''; + $info = ''; + $i = 0; + if ( preg_match_all( '/\{[^}]*\}/u', $format, $matches, PREG_OFFSET_CAPTURE ) ) { + foreach ( $matches[0] as $match ) { + $key = substr( $match[0], 1, -1 ); + $string .= substr( $format, $i, $match[1] - $i ); + if ( ! $this->get_claim( $key, $user_claim, $info ) ) { + if ( $error_on_missing_key ) { + return new WP_Error( + 'incomplete-user-claim', + __( 'User claim incomplete.', 'daggerhart-openid-connect-generic' ), + array( + 'message' => 'Unable to find key: ' . $key . ' in user_claim', + 'hint' => 'Verify OpenID Scope includes a scope with the attributes you need', + 'user_claim' => $user_claim, + 'format' => $format, + ) + ); + } + } else { + $string .= $info; + } + $i = $match[1] + strlen( $match[0] ); + } + } + $string .= substr( $format, $i ); + return $string; + } + + /** + * Get a displayname. + * + * @param array $user_claim The authorized user claim. + * @param bool $error_on_missing_key Whether to return and error on a missing key. + * + * @return string|null|WP_Error + */ + private function get_displayname_from_claim( $user_claim, $error_on_missing_key = false ) { + if ( ! empty( $this->settings->displayname_format ) ) { + return $this->format_string_with_claim( $this->settings->displayname_format, $user_claim, $error_on_missing_key ); + } + return null; + } + + /** + * Get an email. + * + * @param array $user_claim The authorized user claim. + * @param bool $error_on_missing_key Whether to return and error on a missing key. + * + * @return string|null|WP_Error + */ + private function get_email_from_claim( $user_claim, $error_on_missing_key = false ) { + if ( ! empty( $this->settings->email_format ) ) { + return $this->format_string_with_claim( $this->settings->email_format, $user_claim, $error_on_missing_key ); + } + return null; + } + + /** + * Create a new user from details in a user_claim. + * + * @param string $subject_identity The authenticated user's identity with the IDP. + * @param array $user_claim The authorized user claim. + * + * @return \WP_Error | \WP_User + */ + public function create_new_user( $subject_identity, $user_claim ) { + $start_time = microtime( true ); + $user_claim = apply_filters( 'openid-connect-generic-alter-user-claim', $user_claim ); + + // Default username & email to the subject identity. + $username = $subject_identity; + $email = $subject_identity; + $nickname = $subject_identity; + $displayname = $subject_identity; + $values_missing = false; + + // Allow claim details to determine username, email, nickname and displayname. + $_email = $this->get_email_from_claim( $user_claim, true ); + if ( is_wp_error( $_email ) || empty( $_email ) ) { + $values_missing = true; + } else { + $email = $_email; + } + + $_username = $this->get_username_from_claim( $user_claim ); + if ( is_wp_error( $_username ) || empty( $_username ) ) { + $values_missing = true; + } else { + $username = $_username; + } + + $_nickname = $this->get_nickname_from_claim( $user_claim ); + if ( is_wp_error( $_nickname ) || empty( $_nickname ) ) { + $values_missing = true; + } else { + $nickname = $_nickname; + } + + $_displayname = $this->get_displayname_from_claim( $user_claim, true ); + if ( is_wp_error( $_displayname ) || empty( $_displayname ) ) { + $values_missing = true; + } else { + $displayname = $_displayname; + } + + // Attempt another request for userinfo if some values are missing. + if ( $values_missing && isset( $user_claim['access_token'] ) && ! empty( $this->settings->endpoint_userinfo ) ) { + $user_claim_result = $this->client->request_userinfo( $user_claim['access_token'] ); + + // Make sure we didn't get an error. + if ( is_wp_error( $user_claim_result ) ) { + return new WP_Error( 'bad-user-claim-result', __( 'Bad user claim result.', 'daggerhart-openid-connect-generic' ), $user_claim_result ); + } + + $user_claim = json_decode( $user_claim_result['body'], true ); + } + + $_email = $this->get_email_from_claim( $user_claim, true ); + if ( is_wp_error( $_email ) ) { + return $_email; + } + // Use the email address from the latest userinfo request if not empty. + if ( ! empty( $_email ) ) { + $email = $_email; + } + + $_username = $this->get_username_from_claim( $user_claim ); + if ( is_wp_error( $_username ) ) { + return $_username; + } + // Use the username from the latest userinfo request if not empty. + if ( ! empty( $_username ) ) { + $username = $_username; + } + + $_nickname = $this->get_nickname_from_claim( $user_claim ); + if ( is_wp_error( $_nickname ) ) { + return $_nickname; + } + // Use the username as the nickname if the userinfo request nickname is empty. + if ( empty( $_nickname ) ) { + $nickname = $username; + } + + $_displayname = $this->get_displayname_from_claim( $user_claim, true ); + if ( is_wp_error( $_displayname ) ) { + return $_displayname; + } + // Use the nickname as the displayname if the userinfo request displayname is empty. + if ( empty( $_displayname ) ) { + $displayname = $nickname; + } + + // Before trying to create the user, first check if a matching user exists. + if ( $this->settings->link_existing_users ) { + $uid = null; + if ( $this->settings->identify_with_username ) { + $uid = username_exists( $username ); + } else { + $uid = email_exists( $email ); + } + if ( ! empty( $uid ) ) { + $user = $this->update_existing_user( $uid, $subject_identity ); + do_action( 'openid-connect-generic-update-user-using-current-claim', $user, $user_claim ); + $end_time = microtime( true ); + $this->logger->log( "Existing user updated: {$user->user_login} ($uid)", __METHOD__, $end_time - $start_time ); + return $user; + } + } + + /** + * Allow other plugins / themes to determine authorization of new accounts + * based on the returned user claim. + */ + $create_user = apply_filters( 'openid-connect-generic-user-creation-test', $this->settings->create_if_does_not_exist, $user_claim ); + + if ( ! $create_user ) { + return new WP_Error( 'cannot-authorize', __( 'Can not authorize.', 'daggerhart-openid-connect-generic' ), $create_user ); + } + + // Copy the username for incrementing. + $_username = $username; + // Ensure prevention of linking usernames & collisions by incrementing the username if it exists. + // @example Original user gets "name", second user gets "name2", etc. + $count = 1; + while ( username_exists( $username ) ) { + $count++; + $username = $_username . $count; + } + + $user_data = array( + 'user_login' => $username, + 'user_pass' => wp_generate_password( 32, true, true ), + 'user_email' => $email, + 'display_name' => $displayname, + 'nickname' => $nickname, + 'first_name' => isset( $user_claim['given_name'] ) ? $user_claim['given_name'] : '', + 'last_name' => isset( $user_claim['family_name'] ) ? $user_claim['family_name'] : '', + ); + $user_data = apply_filters( 'openid-connect-generic-alter-user-data', $user_data, $user_claim ); + + // Create the new user. + $uid = wp_insert_user( $user_data ); + + // Make sure we didn't fail in creating the user. + if ( is_wp_error( $uid ) ) { + return new WP_Error( 'failed-user-creation', __( 'Failed user creation.', 'daggerhart-openid-connect-generic' ), $uid ); + } + + // Retrieve our new user. + $user = get_user_by( 'id', $uid ); + + // Save some meta data about this new user for the future. + add_user_meta( $user->ID, 'openid-connect-generic-subject-identity', (string) $subject_identity, true ); + + // Log the results. + $end_time = microtime( true ); + $this->logger->log( "New user created: {$user->user_login} ($uid)", __METHOD__, $end_time - $start_time ); + + // Allow plugins / themes to take action on new user creation. + do_action( 'openid-connect-generic-user-create', $user, $user_claim ); + + return $user; + } + + /** + * Update an existing user with OpenID Connect meta data + * + * @param int $uid The WordPress User ID. + * @param string $subject_identity The subject identity from the IDP. + * + * @return WP_Error|WP_User + */ + public function update_existing_user( $uid, $subject_identity ) { + // Add the OpenID Connect meta data. + update_user_meta( $uid, 'openid-connect-generic-subject-identity', strval( $subject_identity ) ); + + // Allow plugins / themes to take action on user update. + do_action( 'openid-connect-generic-user-update', $uid ); + + // Return our updated user. + return get_user_by( 'id', $uid ); + } +} diff --git a/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client.php b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client.php new file mode 100644 index 00000000..70250b03 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-client.php @@ -0,0 +1,568 @@ + + * @copyright 2015-2020 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenID_Connect_Generic_Client class. + * + * Plugin OIDC/oAuth client class. + * + * @package OpenID_Connect_Generic + * @category Authentication + */ +class OpenID_Connect_Generic_Client { + + /** + * The OIDC/oAuth client ID. + * + * @see OpenID_Connect_Generic_Option_Settings::client_id + * + * @var string + */ + private $client_id; + + /** + * The OIDC/oAuth client secret. + * + * @see OpenID_Connect_Generic_Option_Settings::client_secret + * + * @var string + */ + private $client_secret; + + /** + * The OIDC/oAuth scopes. + * + * @see OpenID_Connect_Generic_Option_Settings::scope + * + * @var string + */ + private $scope; + + /** + * The OIDC/oAuth authorization endpoint URL. + * + * @see OpenID_Connect_Generic_Option_Settings::endpoint_login + * + * @var string + */ + private $endpoint_login; + + /** + * The OIDC/oAuth User Information endpoint URL. + * + * @see OpenID_Connect_Generic_Option_Settings::endpoint_userinfo + * + * @var string + */ + private $endpoint_userinfo; + + /** + * The OIDC/oAuth token validation endpoint URL. + * + * @see OpenID_Connect_Generic_Option_Settings::endpoint_token + * + * @var string + */ + private $endpoint_token; + + /** + * The login flow "ajax" endpoint URI. + * + * @see OpenID_Connect_Generic_Option_Settings::redirect_uri + * + * @var string + */ + private $redirect_uri; + + /** + * The specifically requested authentication contract at the IDP + * + * @see OpenID_Connect_Generic_Option_Settings::acr_values + * + * @var string + */ + private $acr_values; + + /** + * The state time limit. States are only valid for 3 minutes. + * + * @see OpenID_Connect_Generic_Option_Settings::state_time_limit + * + * @var int + */ + private $state_time_limit = 180; + + /** + * The logger object instance. + * + * @var OpenID_Connect_Generic_Option_Logger + */ + private $logger; + + /** + * Client constructor. + * + * @param string $client_id @see OpenID_Connect_Generic_Option_Settings::client_id for description. + * @param string $client_secret @see OpenID_Connect_Generic_Option_Settings::client_secret for description. + * @param string $scope @see OpenID_Connect_Generic_Option_Settings::scope for description. + * @param string $endpoint_login @see OpenID_Connect_Generic_Option_Settings::endpoint_login for description. + * @param string $endpoint_userinfo @see OpenID_Connect_Generic_Option_Settings::endpoint_userinfo for description. + * @param string $endpoint_token @see OpenID_Connect_Generic_Option_Settings::endpoint_token for description. + * @param string $redirect_uri @see OpenID_Connect_Generic_Option_Settings::redirect_uri for description. + * @param string $acr_values @see OpenID_Connect_Generic_Option_Settings::acr_values for description. + * @param int $state_time_limit @see OpenID_Connect_Generic_Option_Settings::state_time_limit for description. + * @param OpenID_Connect_Generic_Option_Logger $logger The plugin logging object instance. + */ + public function __construct( $client_id, $client_secret, $scope, $endpoint_login, $endpoint_userinfo, $endpoint_token, $redirect_uri, $acr_values, $state_time_limit, $logger ) { + $this->client_id = $client_id; + $this->client_secret = $client_secret; + $this->scope = $scope; + $this->endpoint_login = $endpoint_login; + $this->endpoint_userinfo = $endpoint_userinfo; + $this->endpoint_token = $endpoint_token; + $this->redirect_uri = $redirect_uri; + $this->acr_values = $acr_values; + $this->state_time_limit = $state_time_limit; + $this->logger = $logger; + } + + /** + * Provides the configured Redirect URI supplied to the IDP. + * + * @return string + */ + public function get_redirect_uri() { + return $this->redirect_uri; + } + + /** + * Provide the configured IDP endpoint login URL. + * + * @return string + */ + public function get_endpoint_login_url() { + return $this->endpoint_login; + } + + /** + * Validate the request for login authentication + * + * @param array $request The authentication request results. + * + * @return array|WP_Error + */ + public function validate_authentication_request( $request ) { + // Look for an existing error of some kind. + if ( isset( $request['error'] ) ) { + return new WP_Error( 'unknown-error', 'An unknown error occurred.', $request ); + } + + // Make sure we have a legitimate authentication code and valid state. + if ( ! isset( $request['code'] ) ) { + return new WP_Error( 'no-code', 'No authentication code present in the request.', $request ); + } + + // Check the client request state. + if ( ! isset( $request['state'] ) ) { + do_action( 'openid-connect-generic-no-state-provided' ); + return new WP_Error( 'missing-state', __( 'Missing state.', 'daggerhart-openid-connect-generic' ), $request ); + } + + if ( ! $this->check_state( $request['state'] ) ) { + return new WP_Error( 'invalid-state', __( 'Invalid state.', 'daggerhart-openid-connect-generic' ), $request ); + } + + return $request; + } + + /** + * Get the authorization code from the request + * + * @param array|WP_Error $request The authentication request results. + * + * @return string|WP_Error + */ + public function get_authentication_code( $request ) { + if ( ! isset( $request['code'] ) ) { + return new WP_Error( 'missing-authentication-code', __( 'Missing authentication code.', 'daggerhart-openid-connect-generic' ), $request ); + } + + return $request['code']; + } + + /** + * Using the authorization_code, request an authentication token from the IDP. + * + * @param string|WP_Error $code The authorization code. + * + * @return array|WP_Error + */ + public function request_authentication_token( $code ) { + + // Add Host header - required for when the openid-connect endpoint is behind a reverse-proxy. + $parsed_url = parse_url( $this->endpoint_token ); + $host = $parsed_url['host']; + + $request = array( + 'body' => array( + 'code' => $code, + 'client_id' => $this->client_id, + 'client_secret' => $this->client_secret, + 'redirect_uri' => $this->redirect_uri, + 'grant_type' => 'authorization_code', + 'scope' => $this->scope, + ), + 'headers' => array( 'Host' => $host ), + ); + + if ( ! empty( $this->acr_values ) ) { + $request['body'] += array( 'acr_values' => $this->acr_values ); + } + + // Allow modifications to the request. + $request = apply_filters( 'openid-connect-generic-alter-request', $request, 'get-authentication-token' ); + + // Call the server and ask for a token. + $start_time = microtime( true ); + $response = wp_remote_post( $this->endpoint_token, $request ); + $end_time = microtime( true ); + $this->logger->log( $this->endpoint_token, 'request_authentication_token', $end_time - $start_time ); + + if ( is_wp_error( $response ) ) { + $response->add( 'request_authentication_token', __( 'Request for authentication token failed.', 'daggerhart-openid-connect-generic' ) ); + } + + return $response; + } + + /** + * Using the refresh token, request new tokens from the idp + * + * @param string $refresh_token The refresh token previously obtained from token response. + * + * @return array|WP_Error + */ + public function request_new_tokens( $refresh_token ) { + $request = array( + 'body' => array( + 'refresh_token' => $refresh_token, + 'client_id' => $this->client_id, + 'client_secret' => $this->client_secret, + 'grant_type' => 'refresh_token', + ), + ); + + // Allow modifications to the request. + $request = apply_filters( 'openid-connect-generic-alter-request', $request, 'refresh-token' ); + + // Call the server and ask for new tokens. + $start_time = microtime( true ); + $response = wp_remote_post( $this->endpoint_token, $request ); + $end_time = microtime( true ); + $this->logger->log( $this->endpoint_token, 'request_new_tokens', $end_time - $start_time ); + + if ( is_wp_error( $response ) ) { + $response->add( 'refresh_token', __( 'Refresh token failed.', 'daggerhart-openid-connect-generic' ) ); + } + + return $response; + } + + /** + * Extract and decode the token body of a token response + * + * @param array|WP_Error $token_result The token response. + * + * @return array|WP_Error|null + */ + public function get_token_response( $token_result ) { + if ( ! isset( $token_result['body'] ) ) { + return new WP_Error( 'missing-token-body', __( 'Missing token body.', 'daggerhart-openid-connect-generic' ), $token_result ); + } + + // Extract the token response from token. + $token_response = json_decode( $token_result['body'], true ); + + // Check that the token response body was able to be parsed. + if ( is_null( $token_response ) ) { + return new WP_Error( 'invalid-token', __( 'Invalid token.', 'daggerhart-openid-connect-generic' ), $token_result ); + } + + if ( isset( $token_response['error'] ) ) { + $error = $token_response['error']; + $error_description = $error; + if ( isset( $token_response['error_description'] ) ) { + $error_description = $token_response['error_description']; + } + return new WP_Error( $error, $error_description, $token_result ); + } + + return $token_response; + } + + /** + * Exchange an access_token for a user_claim from the userinfo endpoint + * + * @param string $access_token The access token supplied from authentication user claim. + * + * @return array|WP_Error + */ + public function request_userinfo( $access_token ) { + // Allow modifications to the request. + $request = apply_filters( 'openid-connect-generic-alter-request', array(), 'get-userinfo' ); + + /* + * Section 5.3.1 of the spec recommends sending the access token using the authorization header + * a filter may or may not have already added headers - make sure they exist then add the token. + */ + if ( ! array_key_exists( 'headers', $request ) || ! is_array( $request['headers'] ) ) { + $request['headers'] = array(); + } + + $request['headers']['Authorization'] = 'Bearer ' . $access_token; + + // Add Host header - required for when the openid-connect endpoint is behind a reverse-proxy. + $parsed_url = parse_url( $this->endpoint_userinfo ); + $host = $parsed_url['host']; + + if ( ! empty( $parsed_url['port'] ) ) { + $host .= ":{$parsed_url['port']}"; + } + + $request['headers']['Host'] = $host; + + // Attempt the request including the access token in the query string for backwards compatibility. + $start_time = microtime( true ); + $response = wp_remote_post( $this->endpoint_userinfo, $request ); + $end_time = microtime( true ); + $this->logger->log( $this->endpoint_userinfo, 'request_userinfo', $end_time - $start_time ); + + if ( is_wp_error( $response ) ) { + $response->add( 'request_userinfo', __( 'Request for userinfo failed.', 'daggerhart-openid-connect-generic' ) ); + } + + return $response; + } + + /** + * Generate a new state, save it as a transient, and return the state hash. + * + * @param string $redirect_to The redirect URL to be used after IDP authentication. + * + * @return string + */ + public function new_state( $redirect_to ) { + // New state w/ timestamp. + $state = md5( mt_rand() . microtime( true ) ); + $state_value = array( + $state => array( + 'redirect_to' => $redirect_to, + ), + ); + set_transient( 'openid-connect-generic-state--' . $state, $state_value, $this->state_time_limit ); + + return $state; + } + + /** + * Check the existence of a given state transient. + * + * @param string $state The state hash to validate. + * + * @return bool + */ + public function check_state( $state ) { + + $state_found = true; + + if ( ! get_option( '_transient_openid-connect-generic-state--' . $state ) ) { + do_action( 'openid-connect-generic-state-not-found', $state ); + $state_found = false; + } + + $valid = get_transient( 'openid-connect-generic-state--' . $state ); + + if ( ! $valid && $state_found ) { + do_action( 'openid-connect-generic-state-expired', $state ); + } + + return boolval( $valid ); + } + + /** + * Get the authorization state from the request + * + * @param array|WP_Error $request The authentication request results. + * + * @return string|WP_Error + */ + public function get_authentication_state( $request ) { + if ( ! isset( $request['state'] ) ) { + return new WP_Error( 'missing-authentication-state', __( 'Missing authentication state.', 'daggerhart-openid-connect-generic' ), $request ); + } + + return $request['state']; + } + + /** + * Ensure that the token meets basic requirements. + * + * @param array $token_response The token response. + * + * @return bool|WP_Error + */ + public function validate_token_response( $token_response ) { + /* + * Ensure 2 specific items exist with the token response in order + * to proceed with confidence: id_token and token_type == 'Bearer' + */ + if ( ! isset( $token_response['id_token'] ) || + ! isset( $token_response['token_type'] ) || strcasecmp( $token_response['token_type'], 'Bearer' ) + ) { + return new WP_Error( 'invalid-token-response', 'Invalid token response', $token_response ); + } + + return true; + } + + /** + * Extract the id_token_claim from the token_response. + * + * @param array $token_response The token response. + * + * @return array|WP_Error + */ + public function get_id_token_claim( $token_response ) { + // Validate there is an id_token. + if ( ! isset( $token_response['id_token'] ) ) { + return new WP_Error( 'no-identity-token', __( 'No identity token.', 'daggerhart-openid-connect-generic' ), $token_response ); + } + + // Break apart the id_token in the response for decoding. + $tmp = explode( '.', $token_response['id_token'] ); + + if ( ! isset( $tmp[1] ) ) { + return new WP_Error( 'missing-identity-token', __( 'Missing identity token.', 'daggerhart-openid-connect-generic' ), $token_response ); + } + + // Extract the id_token's claims from the token. + $id_token_claim = json_decode( + base64_decode( + str_replace( // Because token is encoded in base64 URL (and not just base64). + array( '-', '_' ), + array( '+', '/' ), + $tmp[1] + ) + ), + true + ); + + return $id_token_claim; + } + + /** + * Ensure the id_token_claim contains the required values. + * + * @param array $id_token_claim The ID token claim. + * + * @return bool|WP_Error + */ + public function validate_id_token_claim( $id_token_claim ) { + if ( ! is_array( $id_token_claim ) ) { + return new WP_Error( 'bad-id-token-claim', __( 'Bad ID token claim.', 'daggerhart-openid-connect-generic' ), $id_token_claim ); + } + + // Validate the identification data and it's value. + if ( ! isset( $id_token_claim['sub'] ) || empty( $id_token_claim['sub'] ) ) { + return new WP_Error( 'no-subject-identity', __( 'No subject identity.', 'daggerhart-openid-connect-generic' ), $id_token_claim ); + } + + // Validate acr values when the option is set in the configuration. + if ( ! empty( $this->acr_values ) && isset( $id_token_claim['acr'] ) ) { + if ( $this->acr_values != $id_token_claim['acr'] ) { + return new WP_Error( 'no-match-acr', __( 'No matching acr values.', 'daggerhart-openid-connect-generic' ), $id_token_claim ); + } + } + + return true; + } + + /** + * Attempt to exchange the access_token for a user_claim. + * + * @param array $token_response The token response. + * + * @return array|WP_Error|null + */ + public function get_user_claim( $token_response ) { + // Send a userinfo request to get user claim. + $user_claim_result = $this->request_userinfo( $token_response['access_token'] ); + + // Make sure we didn't get an error, and that the response body exists. + if ( is_wp_error( $user_claim_result ) || ! isset( $user_claim_result['body'] ) ) { + return new WP_Error( 'bad-claim', __( 'Bad user claim.', 'daggerhart-openid-connect-generic' ), $user_claim_result ); + } + + $user_claim = json_decode( $user_claim_result['body'], true ); + + return $user_claim; + } + + /** + * Make sure the user_claim has all required values, and that the subject + * identity matches of the id_token matches that of the user_claim. + * + * @param array $user_claim The authenticated user claim. + * @param array $id_token_claim The ID token claim. + * + * @return bool|WP_Error + */ + public function validate_user_claim( $user_claim, $id_token_claim ) { + // Validate the user claim. + if ( ! is_array( $user_claim ) ) { + return new WP_Error( 'invalid-user-claim', __( 'Invalid user claim.', 'daggerhart-openid-connect-generic' ), $user_claim ); + } + + // Allow for errors from the IDP. + if ( isset( $user_claim['error'] ) ) { + $message = __( 'Error from the IDP.', 'daggerhart-openid-connect-generic' ); + if ( ! empty( $user_claim['error_description'] ) ) { + $message = $user_claim['error_description']; + } + return new WP_Error( 'invalid-user-claim-' . $user_claim['error'], $message, $user_claim ); + } + + // Make sure the id_token sub equals the user_claim sub, according to spec. + if ( $id_token_claim['sub'] !== $user_claim['sub'] ) { + return new WP_Error( 'incorrect-user-claim', __( 'Incorrect user claim.', 'daggerhart-openid-connect-generic' ), func_get_args() ); + } + + // Allow for other plugins to alter the login success. + $login_user = apply_filters( 'openid-connect-generic-user-login-test', true, $user_claim ); + + if ( ! $login_user ) { + return new WP_Error( 'unauthorized', __( 'Unauthorized access.', 'daggerhart-openid-connect-generic' ), $login_user ); + } + + return true; + } + + /** + * Retrieve the subject identity from the id_token. + * + * @param array $id_token_claim The ID token claim. + * + * @return mixed + */ + public function get_subject_identity( $id_token_claim ) { + return $id_token_claim['sub']; + } +} diff --git a/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-login-form.php b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-login-form.php new file mode 100644 index 00000000..9ef81d8a --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-login-form.php @@ -0,0 +1,178 @@ + + * @copyright 2015-2020 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenID_Connect_Generic_Login_Form class. + * + * Login form and login button handling. + * + * @package OpenID_Connect_Generic + * @category Login + */ +class OpenID_Connect_Generic_Login_Form { + + /** + * Plugin settings object. + * + * @var OpenID_Connect_Generic_Option_Settings + */ + private $settings; + + /** + * Plugin client wrapper instance. + * + * @var OpenID_Connect_Generic_Client_Wrapper + */ + private $client_wrapper; + + /** + * The class constructor. + * + * @param OpenID_Connect_Generic_Option_Settings $settings A plugin settings object instance. + * @param OpenID_Connect_Generic_Client_Wrapper $client_wrapper A plugin client wrapper object instance. + */ + public function __construct( $settings, $client_wrapper ) { + $this->settings = $settings; + $this->client_wrapper = $client_wrapper; + } + + /** + * Create an instance of the OpenID_Connect_Generic_Login_Form class. + * + * @param OpenID_Connect_Generic_Option_Settings $settings A plugin settings object instance. + * @param OpenID_Connect_Generic_Client_Wrapper $client_wrapper A plugin client wrapper object instance. + * + * @return void + */ + public static function register( $settings, $client_wrapper ) { + $login_form = new self( $settings, $client_wrapper ); + + // Alter the login form as dictated by settings. + add_filter( 'login_message', array( $login_form, 'handle_login_page' ), 99 ); + + // Add a shortcode for the login button. + add_shortcode( 'openid_connect_generic_login_button', array( $login_form, 'make_login_button' ) ); + + $login_form->handle_redirect_login_type_auto(); + } + + /** + * Auto Login redirect. + * + * @return void + */ + public function handle_redirect_login_type_auto() { + + if ( 'wp-login.php' == $GLOBALS['pagenow'] + && ( 'auto' == $this->settings->login_type || ! empty( $_GET['force_redirect'] ) ) + // Don't send users to the IDP on logout or post password protected authentication. + && ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], array( 'logout', 'postpass' ) ) ) + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- WP Login Form doesn't have a nonce. + && ! isset( $_POST['wp-submit'] ) ) { + if ( ! isset( $_GET['login-error'] ) ) { + wp_redirect( $this->client_wrapper->get_authentication_url() ); + exit; + } else { + add_action( 'login_footer', array( $this, 'remove_login_form' ), 99 ); + } + } + } + + /** + * Implements filter login_message. + * + * @param string $message The text message to display on the login page. + * + * @return string + */ + public function handle_login_page( $message ) { + + if ( isset( $_GET['login-error'] ) ) { + $error_message = ! empty( $_GET['message'] ) ? sanitize_text_field( wp_unslash( $_GET['message'] ) ) : 'Unknown error.'; + $message .= $this->make_error_output( sanitize_text_field( wp_unslash( $_GET['login-error'] ) ), $error_message ); + } + + // Login button is appended to existing messages in case of error. + $message .= $this->make_login_button(); + + return $message; + } + + /** + * Display an error message to the user. + * + * @param string $error_code The error code. + * @param string $error_message The error message test. + * + * @return string + */ + public function make_error_output( $error_code, $error_message ) { + + ob_start(); + ?> +
+ : + +
+ __( 'Login with OpenID Connect', 'daggerhart-openid-connect-generic' ), + ), + $atts, + 'openid_connect_generic_login_button' + ); + + $text = apply_filters( 'openid-connect-generic-login-button-text', $atts['button_text'] ); + $text = esc_html( $text ); + + $href = $this->client_wrapper->get_authentication_url( $atts ); + $href = esc_url_raw( $href ); + + $login_button = << + {$text} + +HTML; + + return $login_button; + } + + /** + * Removes the login form from the HTML DOM + * + * @return void + */ + public function remove_login_form() { + ?> + + + * @copyright 2015-2023 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenID_Connect_Generic_Option_Logger class. + * + * Simple class for logging messages to the options table. + * + * @package OpenID_Connect_Generic + * @category Logging + */ +class OpenID_Connect_Generic_Option_Logger { + + /** + * Thw WordPress option name/key. + * + * @var string + */ + const OPTION_NAME = 'openid-connect-generic-logs'; + + /** + * The default message type. + * + * @var string + */ + private $default_message_type = 'none'; + + /** + * The number of items to keep in the log. + * + * @var int + */ + private $log_limit = 1000; + + /** + * Whether or not logging is enabled. + * + * @var bool + */ + private $logging_enabled = true; + + /** + * Internal cache of logs. + * + * @var array + */ + private $logs; + + /** + * Setup the logger according to the needs of the instance. + * + * @param string|null $default_message_type The log message type. + * @param bool|TRUE|null $logging_enabled Whether logging is enabled. + * @param int|null $log_limit The log entry limit. + */ + public function __construct( $default_message_type = null, $logging_enabled = null, $log_limit = null ) { + if ( ! is_null( $default_message_type ) ) { + $this->default_message_type = $default_message_type; + } + if ( ! is_null( $logging_enabled ) ) { + $this->logging_enabled = boolval( $logging_enabled ); + } + if ( ! is_null( $log_limit ) ) { + $this->log_limit = intval( $log_limit ); + } + } + + /** + * Save an array of data to the logs. + * + * @param string|array|WP_Error $data The log message data. + * @param string|null $type The log message type. + * @param float|null $processing_time Optional event processing time. + * @param int|null $time The log message timestamp (default: time()). + * @param int|null $user_ID The current WordPress user ID (default: get_current_user_id()). + * @param string|null $request_uri The related HTTP request URI (default: $_SERVER['REQUEST_URI']|'Unknown'). + * + * @return bool + */ + public function log( $data, $type = null, $processing_time = null, $time = null, $user_ID = null, $request_uri = null ) { + if ( boolval( $this->logging_enabled ) ) { + $logs = $this->get_logs(); + $logs[] = $this->make_message( $data, $type, $processing_time, $time, $user_ID, $request_uri ); + $logs = $this->upkeep_logs( $logs ); + return $this->save_logs( $logs ); + } + + return false; + } + + /** + * Retrieve all log messages. + * + * @return array + */ + public function get_logs() { + if ( empty( $this->logs ) ) { + $this->logs = get_option( self::OPTION_NAME, array() ); + } + + // Call the upkeep_logs function to give the appearance that logs have been reduced to the $this->log_limit. + // The logs are actually limited during a logging action but the logger isn't available during a simple settings update. + return $this->upkeep_logs( $this->logs ); + } + + /** + * Get the name of the option where this log is stored. + * + * @return string + */ + public function get_option_name() { + return self::OPTION_NAME; + } + + /** + * Create a message array containing the data and other information. + * + * @param string|array|WP_Error $data The log message data. + * @param string|null $type The log message type. + * @param float|null $processing_time Optional event processing time. + * @param int|null $time The log message timestamp (default: time()). + * @param int|null $user_ID The current WordPress user ID (default: get_current_user_id()). + * @param string|null $request_uri The related HTTP request URI (default: $_SERVER['REQUEST_URI']|'Unknown'). + * + * @return array + */ + private function make_message( $data, $type, $processing_time, $time, $user_ID, $request_uri ) { + // Determine the type of message. + if ( empty( $type ) ) { + $type = $this->default_message_type; + + if ( is_array( $data ) && isset( $data['type'] ) ) { + $type = $data['type']; + unset( $data['type'] ); + } + + if ( is_wp_error( $data ) ) { + $type = $data->get_error_code(); + $data = $data->get_error_message( $type ); + } + } + + if ( empty( $request_uri ) ) { + $request_uri = ( ! empty( $_SERVER['REQUEST_URI'] ) ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : 'Unknown'; + $request_uri = preg_replace( '/code=([^&]+)/i', 'code=', $request_uri ); + } + + // Construct the message. + $message = array( + 'type' => $type, + 'time' => ! empty( $time ) ? $time : time(), + 'user_ID' => ! is_null( $user_ID ) ? $user_ID : get_current_user_id(), + 'uri' => $request_uri, + 'data' => $data, + 'processing_time' => $processing_time, + ); + + return $message; + } + + /** + * Keep the log count under the limit. + * + * @param array $logs The plugin logs. + * + * @return array + */ + private function upkeep_logs( $logs ) { + $items_to_remove = count( $logs ) - $this->log_limit; + + if ( $items_to_remove > 0 ) { + // Only keep the last $log_limit messages from the end. + $logs = array_slice( $logs, $items_to_remove ); + } + + return $logs; + } + + /** + * Save the log messages. + * + * @param array $logs The array of log messages. + * + * @return bool + */ + private function save_logs( $logs ) { + // Save the logs. + $this->logs = $logs; + return update_option( self::OPTION_NAME, $logs, false ); + } + + /** + * Clear all log messages. + * + * @return void + */ + public function clear_logs() { + $this->save_logs( array() ); + } + + /** + * Get a simple html table of all the logs. + * + * @param array $logs The array of log messages. + * + * @return string + */ + public function get_logs_table( $logs = array() ) { + if ( empty( $logs ) ) { + $logs = $this->get_logs(); + } + $logs = array_reverse( $logs ); + + ini_set( 'xdebug.var_display_max_depth', '-1' ); + + ob_start(); + ?> + + + + + + + + + + + + + +
+
+ + +
+
+ + +
+
+ + user_login : '0' ); ?> +
+
+ + +
+
+ + +
+
+ + * @copyright 2015-2023 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenId_Connect_Generic_Option_Settings class. + * + * WordPress options handling. + * + * @package OpenID_Connect_Generic + * @category Settings + * + * Legacy Settings: + * + * @property string $ep_login The login endpoint. + * @property string $ep_token The token endpoint. + * @property string $ep_userinfo The userinfo endpoint. + * + * OAuth Client Settings: + * + * @property string $login_type How the client (login form) should provide login options. + * @property string $client_id The ID the client will be recognized as when connecting the to Identity provider server. + * @property string $client_secret The secret key the IDP server expects from the client. + * @property string $scope The list of scopes this client should access. + * @property string $endpoint_login The IDP authorization endpoint URL. + * @property string $endpoint_userinfo The IDP User information endpoint URL. + * @property string $endpoint_token The IDP token validation endpoint URL. + * @property string $endpoint_end_session The IDP logout endpoint URL. + * @property string $acr_values The Authentication contract as defined on the IDP. + * + * Non-standard Settings: + * + * @property bool $no_sslverify The flag to enable/disable SSL verification during authorization. + * @property int $http_request_timeout The timeout for requests made to the IDP. Default value is 5. + * @property string $identity_key The key in the user claim array to find the user's identification data. + * @property string $nickname_key The key in the user claim array to find the user's nickname. + * @property string $email_format The key(s) in the user claim array to formulate the user's email address. + * @property string $displayname_format The key(s) in the user claim array to formulate the user's display name. + * @property bool $identify_with_username The flag which indicates how the user's identity will be determined. + * @property int $state_time_limit The valid time limit of the state, in seconds. Defaults to 180 seconds. + * + * Plugin Settings: + * + * @property bool $enforce_privacy The flag to indicates whether a user us required to be authenticated to access the site. + * @property bool $alternate_redirect_uri The flag to indicate whether to use the alternative redirect URI. + * @property bool $token_refresh_enable The flag whether to support refresh tokens by IDPs. + * @property bool $link_existing_users The flag to indicate whether to link to existing WordPress-only accounts or greturn an error. + * @property bool $create_if_does_not_exist The flag to indicate whether to create new users or not. + * @property bool $redirect_user_back The flag to indicate whether to redirect the user back to the page on which they started. + * @property bool $redirect_on_logout The flag to indicate whether to redirect to the login screen on session expiration. + * @property bool $enable_logging The flag to enable/disable logging. + * @property int $log_limit The maximum number of log entries to keep. + */ +class OpenID_Connect_Generic_Option_Settings { + + /** + * WordPress option name/key. + * + * @var string + */ + const OPTION_NAME = 'openid_connect_generic_settings'; + + /** + * Stored option values array. + * + * @var array + */ + private $values; + + /** + * Default plugin settings values. + * + * @var array + */ + private $default_settings; + + /** + * List of settings that can be defined by environment variables. + * + * @var array + */ + private $environment_settings = array( + 'client_id' => 'OIDC_CLIENT_ID', + 'client_secret' => 'OIDC_CLIENT_SECRET', + 'endpoint_end_session' => 'OIDC_ENDPOINT_LOGOUT_URL', + 'endpoint_login' => 'OIDC_ENDPOINT_LOGIN_URL', + 'endpoint_token' => 'OIDC_ENDPOINT_TOKEN_URL', + 'endpoint_userinfo' => 'OIDC_ENDPOINT_USERINFO_URL', + 'login_type' => 'OIDC_LOGIN_TYPE', + 'scope' => 'OIDC_CLIENT_SCOPE', + 'create_if_does_not_exist' => 'OIDC_CREATE_IF_DOES_NOT_EXIST', + 'enforce_privacy' => 'OIDC_ENFORCE_PRIVACY', + 'link_existing_users' => 'OIDC_LINK_EXISTING_USERS', + 'redirect_on_logout' => 'OIDC_REDIRECT_ON_LOGOUT', + 'redirect_user_back' => 'OIDC_REDIRECT_USER_BACK', + 'acr_values' => 'OIDC_ACR_VALUES', + 'enable_logging' => 'OIDC_ENABLE_LOGGING', + 'log_limit' => 'OIDC_LOG_LIMIT', + ); + + /** + * The class constructor. + * + * @param array $default_settings The default plugin settings values. + * @param bool $granular_defaults The granular defaults. + */ + public function __construct( $default_settings = array(), $granular_defaults = true ) { + $this->default_settings = $default_settings; + $this->values = array(); + + $this->values = (array) get_option( self::OPTION_NAME, $this->default_settings ); + + // For each defined environment variable/constant be sure the settings key is set. + foreach ( $this->environment_settings as $key => $constant ) { + if ( defined( $constant ) ) { + $this->__set( $key, constant( $constant ) ); + } + } + + if ( $granular_defaults ) { + $this->values = array_replace_recursive( $this->default_settings, $this->values ); + } + } + + /** + * Magic getter for settings. + * + * @param string $key The array key/option name. + * + * @return mixed + */ + public function __get( $key ) { + if ( isset( $this->values[ $key ] ) ) { + return $this->values[ $key ]; + } + } + + /** + * Magic setter for settings. + * + * @param string $key The array key/option name. + * @param mixed $value The option value. + * + * @return void + */ + public function __set( $key, $value ) { + $this->values[ $key ] = $value; + } + + /** + * Magic method to check is an attribute isset. + * + * @param string $key The array key/option name. + * + * @return bool + */ + public function __isset( $key ) { + return isset( $this->values[ $key ] ); + } + + /** + * Magic method to clear an attribute. + * + * @param string $key The array key/option name. + * + * @return void + */ + public function __unset( $key ) { + unset( $this->values[ $key ] ); + } + + /** + * Get the plugin settings array. + * + * @return array + */ + public function get_values() { + return $this->values; + } + + /** + * Get the plugin WordPress options name. + * + * @return string + */ + public function get_option_name() { + return self::OPTION_NAME; + } + + /** + * Save the plugin options to the WordPress options table. + * + * @return void + */ + public function save() { + + // For each defined environment variable/constant be sure it isn't saved to the database. + foreach ( $this->environment_settings as $key => $constant ) { + if ( defined( $constant ) ) { + $this->__unset( $key ); + } + } + + update_option( self::OPTION_NAME, $this->values ); + } +} diff --git a/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-settings-page.php b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-settings-page.php new file mode 100644 index 00000000..9543dd26 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/includes/openid-connect-generic-settings-page.php @@ -0,0 +1,603 @@ + + * @copyright 2015-2023 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenID_Connect_Generic_Settings_Page class. + * + * Admin settings page. + * + * @package OpenID_Connect_Generic + * @category Settings + */ +class OpenID_Connect_Generic_Settings_Page { + + /** + * Local copy of the settings provided by the base plugin. + * + * @var OpenID_Connect_Generic_Option_Settings + */ + private $settings; + + /** + * Instance of the plugin logger. + * + * @var OpenID_Connect_Generic_Option_Logger + */ + private $logger; + + /** + * The controlled list of settings & associated defined during + * construction for i18n reasons. + * + * @var array + */ + private $settings_fields = array(); + + /** + * Options page slug. + * + * @var string + */ + private $options_page_name = 'openid-connect-generic-settings'; + + /** + * Options page settings group name. + * + * @var string + */ + private $settings_field_group; + + /** + * Settings page class constructor. + * + * @param OpenID_Connect_Generic_Option_Settings $settings The plugin settings object. + * @param OpenID_Connect_Generic_Option_Logger $logger The plugin logging class object. + */ + public function __construct( OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ) { + + $this->settings = $settings; + $this->logger = $logger; + $this->settings_field_group = $this->settings->get_option_name() . '-group'; + + $fields = $this->get_settings_fields(); + + // Some simple pre-processing. + foreach ( $fields as $key => &$field ) { + $field['key'] = $key; + $field['name'] = $this->settings->get_option_name() . '[' . $key . ']'; + } + + // Allow alterations of the fields. + $this->settings_fields = $fields; + } + + /** + * Hook the settings page into WordPress. + * + * @param OpenID_Connect_Generic_Option_Settings $settings A plugin settings object instance. + * @param OpenID_Connect_Generic_Option_Logger $logger A plugin logger object instance. + * + * @return void + */ + public static function register( OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ) { + $settings_page = new self( $settings, $logger ); + + // Add our options page the the admin menu. + add_action( 'admin_menu', array( $settings_page, 'admin_menu' ) ); + + // Register our settings. + add_action( 'admin_init', array( $settings_page, 'admin_init' ) ); + } + + /** + * Implements hook admin_menu to add our options/settings page to the + * dashboard menu. + * + * @return void + */ + public function admin_menu() { + add_options_page( + __( 'OpenID Connect - Generic Client', 'daggerhart-openid-connect-generic' ), + __( 'OpenID Connect Client', 'daggerhart-openid-connect-generic' ), + 'manage_options', + $this->options_page_name, + array( $this, 'settings_page' ) + ); + } + + /** + * Implements hook admin_init to register our settings. + * + * @return void + */ + public function admin_init() { + register_setting( + $this->settings_field_group, + $this->settings->get_option_name(), + array( + $this, + 'sanitize_settings', + ) + ); + + add_settings_section( + 'client_settings', + __( 'Client Settings', 'daggerhart-openid-connect-generic' ), + array( $this, 'client_settings_description' ), + $this->options_page_name + ); + + add_settings_section( + 'user_settings', + __( 'WordPress User Settings', 'daggerhart-openid-connect-generic' ), + array( $this, 'user_settings_description' ), + $this->options_page_name + ); + + add_settings_section( + 'authorization_settings', + __( 'Authorization Settings', 'daggerhart-openid-connect-generic' ), + array( $this, 'authorization_settings_description' ), + $this->options_page_name + ); + + add_settings_section( + 'log_settings', + __( 'Log Settings', 'daggerhart-openid-connect-generic' ), + array( $this, 'log_settings_description' ), + $this->options_page_name + ); + + // Preprocess fields and add them to the page. + foreach ( $this->settings_fields as $key => $field ) { + // Make sure each key exists in the settings array. + if ( ! isset( $this->settings->{ $key } ) ) { + $this->settings->{ $key } = null; + } + + // Determine appropriate output callback. + switch ( $field['type'] ) { + case 'checkbox': + $callback = 'do_checkbox'; + break; + + case 'select': + $callback = 'do_select'; + break; + + case 'text': + default: + $callback = 'do_text_field'; + break; + } + + // Add the field. + add_settings_field( + $key, + $field['title'], + array( $this, $callback ), + $this->options_page_name, + $field['section'], + $field + ); + } + } + + /** + * Get the plugin settings fields definition. + * + * @return array + */ + private function get_settings_fields() { + + /** + * Simple settings fields have: + * + * - title + * - description + * - type ( checkbox | text | select ) + * - section - settings/option page section ( client_settings | authorization_settings ) + * - example (optional example will appear beneath description and be wrapped in ) + */ + $fields = array( + 'login_type' => array( + 'title' => __( 'Login Type', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Select how the client (login form) should provide login options.', 'daggerhart-openid-connect-generic' ), + 'type' => 'select', + 'options' => array( + 'button' => __( 'OpenID Connect button on login form', 'daggerhart-openid-connect-generic' ), + 'auto' => __( 'Auto Login - SSO', 'daggerhart-openid-connect-generic' ), + ), + 'disabled' => defined( 'OIDC_LOGIN_TYPE' ), + 'section' => 'client_settings', + ), + 'client_id' => array( + 'title' => __( 'Client ID', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'The ID this client will be recognized as when connecting the to Identity provider server.', 'daggerhart-openid-connect-generic' ), + 'example' => 'my-wordpress-client-id', + 'type' => 'text', + 'disabled' => defined( 'OIDC_CLIENT_ID' ), + 'section' => 'client_settings', + ), + 'client_secret' => array( + 'title' => __( 'Client Secret Key', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Arbitrary secret key the server expects from this client. Can be anything, but should be very unique.', 'daggerhart-openid-connect-generic' ), + 'type' => 'text', + 'disabled' => defined( 'OIDC_CLIENT_SECRET' ), + 'section' => 'client_settings', + ), + 'scope' => array( + 'title' => __( 'OpenID Scope', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Space separated list of scopes this client should access.', 'daggerhart-openid-connect-generic' ), + 'example' => 'email profile openid offline_access', + 'type' => 'text', + 'disabled' => defined( 'OIDC_CLIENT_SCOPE' ), + 'section' => 'client_settings', + ), + 'endpoint_login' => array( + 'title' => __( 'Login Endpoint URL', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Identify provider authorization endpoint.', 'daggerhart-openid-connect-generic' ), + 'example' => 'https://example.com/oauth2/authorize', + 'type' => 'text', + 'disabled' => defined( 'OIDC_ENDPOINT_LOGIN_URL' ), + 'section' => 'client_settings', + ), + 'endpoint_userinfo' => array( + 'title' => __( 'Userinfo Endpoint URL', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Identify provider User information endpoint.', 'daggerhart-openid-connect-generic' ), + 'example' => 'https://example.com/oauth2/UserInfo', + 'type' => 'text', + 'disabled' => defined( 'OIDC_ENDPOINT_USERINFO_URL' ), + 'section' => 'client_settings', + ), + 'endpoint_token' => array( + 'title' => __( 'Token Validation Endpoint URL', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Identify provider token endpoint.', 'daggerhart-openid-connect-generic' ), + 'example' => 'https://example.com/oauth2/token', + 'type' => 'text', + 'disabled' => defined( 'OIDC_ENDPOINT_TOKEN_URL' ), + 'section' => 'client_settings', + ), + 'endpoint_end_session' => array( + 'title' => __( 'End Session Endpoint URL', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Identify provider logout endpoint.', 'daggerhart-openid-connect-generic' ), + 'example' => 'https://example.com/oauth2/logout', + 'type' => 'text', + 'disabled' => defined( 'OIDC_ENDPOINT_LOGOUT_URL' ), + 'section' => 'client_settings', + ), + 'acr_values' => array( + 'title' => __( 'ACR values', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Use a specific defined authentication contract from the IDP - optional.', 'daggerhart-openid-connect-generic' ), + 'type' => 'text', + 'disabled' => defined( 'OIDC_ACR_VALUES' ), + 'section' => 'client_settings', + ), + 'identity_key' => array( + 'title' => __( 'Identity Key', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Where in the user claim array to find the user\'s identification data. Possible standard values: preferred_username, name, or sub. If you\'re having trouble, use "sub".', 'daggerhart-openid-connect-generic' ), + 'example' => 'preferred_username', + 'type' => 'text', + 'section' => 'client_settings', + ), + 'no_sslverify' => array( + 'title' => __( 'Disable SSL Verify', 'daggerhart-openid-connect-generic' ), + // translators: %1$s HTML tags for layout/styles, %2$s closing HTML tag for styles. + 'description' => sprintf( __( 'Do not require SSL verification during authorization. The OAuth extension uses curl to make the request. By default CURL will generally verify the SSL certificate to see if its valid an issued by an accepted CA. This setting disabled that verification.%1$sNot recommended for production sites.%2$s', 'daggerhart-openid-connect-generic' ), '
', '' ), + 'type' => 'checkbox', + 'section' => 'client_settings', + ), + 'http_request_timeout' => array( + 'title' => __( 'HTTP Request Timeout', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Set the timeout for requests made to the IDP. Default value is 5.', 'daggerhart-openid-connect-generic' ), + 'example' => 30, + 'type' => 'text', + 'section' => 'client_settings', + ), + 'enforce_privacy' => array( + 'title' => __( 'Enforce Privacy', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Require users be logged in to see the site.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'disabled' => defined( 'OIDC_ENFORCE_PRIVACY' ), + 'section' => 'authorization_settings', + ), + 'alternate_redirect_uri' => array( + 'title' => __( 'Alternate Redirect URI', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Provide an alternative redirect route. Useful if your server is causing issues with the default admin-ajax method. You must flush rewrite rules after changing this setting. This can be done by saving the Permalinks settings page.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'section' => 'authorization_settings', + ), + 'nickname_key' => array( + 'title' => __( 'Nickname Key', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Where in the user claim array to find the user\'s nickname. Possible standard values: preferred_username, name, or sub.', 'daggerhart-openid-connect-generic' ), + 'example' => 'preferred_username', + 'type' => 'text', + 'section' => 'client_settings', + ), + 'email_format' => array( + 'title' => __( 'Email Formatting', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'String from which the user\'s email address is built. Specify "{email}" as long as the user claim contains an email claim.', 'daggerhart-openid-connect-generic' ), + 'example' => '{email}', + 'type' => 'text', + 'section' => 'client_settings', + ), + 'displayname_format' => array( + 'title' => __( 'Display Name Formatting', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'String from which the user\'s display name is built.', 'daggerhart-openid-connect-generic' ), + 'example' => '{given_name} {family_name}', + 'type' => 'text', + 'section' => 'client_settings', + ), + 'identify_with_username' => array( + 'title' => __( 'Identify with User Name', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'If checked, the user\'s identity will be determined by the user name instead of the email address.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'section' => 'client_settings', + ), + 'state_time_limit' => array( + 'title' => __( 'State time limit', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'State valid time in seconds. Defaults to 180', 'daggerhart-openid-connect-generic' ), + 'type' => 'number', + 'section' => 'client_settings', + ), + 'token_refresh_enable' => array( + 'title' => __( 'Enable Refresh Token', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'If checked, support refresh tokens used to obtain access tokens from supported IDPs.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'section' => 'client_settings', + ), + 'link_existing_users' => array( + 'title' => __( 'Link Existing Users', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'If a WordPress account already exists with the same identity as a newly-authenticated user over OpenID Connect, login as that user instead of generating an error.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'disabled' => defined( 'OIDC_LINK_EXISTING_USERS' ), + 'section' => 'user_settings', + ), + 'create_if_does_not_exist' => array( + 'title' => __( 'Create user if does not exist', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'If the user identity is not linked to an existing WordPress user, it is created. If this setting is not enabled, and if the user authenticates with an account which is not linked to an existing WordPress user, then the authentication will fail.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'disabled' => defined( 'OIDC_CREATE_IF_DOES_NOT_EXIST' ), + 'section' => 'user_settings', + ), + 'redirect_user_back' => array( + 'title' => __( 'Redirect Back to Origin Page', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'After a successful OpenID Connect authentication, this will redirect the user back to the page on which they clicked the OpenID Connect login button. This will cause the login process to proceed in a traditional WordPress fashion. For example, users logging in through the default wp-login.php page would end up on the WordPress Dashboard and users logging in through the WooCommerce "My Account" page would end up on their account page.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'disabled' => defined( 'OIDC_REDIRECT_USER_BACK' ), + 'section' => 'user_settings', + ), + 'redirect_on_logout' => array( + 'title' => __( 'Redirect to the login screen when session is expired', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'When enabled, this will automatically redirect the user back to the WordPress login page if their access token has expired.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'disabled' => defined( 'OIDC_REDIRECT_ON_LOGOUT' ), + 'section' => 'user_settings', + ), + 'enable_logging' => array( + 'title' => __( 'Enable Logging', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Very simple log messages for debugging purposes.', 'daggerhart-openid-connect-generic' ), + 'type' => 'checkbox', + 'disabled' => defined( 'OIDC_ENABLE_LOGGING' ), + 'section' => 'log_settings', + ), + 'log_limit' => array( + 'title' => __( 'Log Limit', 'daggerhart-openid-connect-generic' ), + 'description' => __( 'Number of items to keep in the log. These logs are stored as an option in the database, so space is limited.', 'daggerhart-openid-connect-generic' ), + 'type' => 'number', + 'disabled' => defined( 'OIDC_LOG_LIMIT' ), + 'section' => 'log_settings', + ), + ); + + return apply_filters( 'openid-connect-generic-settings-fields', $fields ); + } + + /** + * Sanitization callback for settings/option page. + * + * @param array $input The submitted settings values. + * + * @return array + */ + public function sanitize_settings( $input ) { + $options = array(); + + // Loop through settings fields to control what we're saving. + foreach ( $this->settings_fields as $key => $field ) { + if ( isset( $input[ $key ] ) ) { + $options[ $key ] = sanitize_text_field( trim( $input[ $key ] ) ); + } else { + $options[ $key ] = ''; + } + } + + return $options; + } + + /** + * Output the options/settings page. + * + * @return void + */ + public function settings_page() { + wp_enqueue_style( 'daggerhart-openid-connect-generic-admin', plugin_dir_url( __DIR__ ) . 'css/styles-admin.css', array(), OpenID_Connect_Generic::VERSION, 'all' ); + + $redirect_uri = admin_url( 'admin-ajax.php?action=openid-connect-authorize' ); + + if ( $this->settings->alternate_redirect_uri ) { + $redirect_uri = site_url( '/openid-connect-authorize' ); + } + ?> +
+

+ +
+ settings_field_group ); + do_settings_sections( $this->options_page_name ); + submit_button(); + + // Simple debug to view settings array. + if ( isset( $_GET['debug'] ) ) { + var_dump( $this->settings->get_values() ); + } + ?> +
+ +

+ +

+ + +

+

+ + [openid_connect_generic_login_button] +

+

+ + [openid_connect_generic_auth_url] +

+ + settings->enable_logging ) { ?> +

+
+ logger->get_logs_table() ); ?> +
+ + +
+ + + value="settings->{ $field['key'] } ); ?>"> + do_field_description( $field ); + } + + /** + * Output a checkbox for a boolean setting. + * - hidden field is default value so we don't have to check isset() on save. + * + * @param array $field The settings field definition array. + * + * @return void + */ + public function do_checkbox( $field ) { + $hidden_value = 0; + if ( ! empty( $field['disabled'] ) && boolval( $field['disabled'] ) === true ) { + $hidden_value = intval( $this->settings->{ $field['key'] } ); + } + ?> + + + value="1" + settings->{ $field['key'] }, 1 ); ?>> + do_field_description( $field ); + } + + /** + * Output a select control. + * + * @param array $field The settings field definition array. + * + * @return void + */ + public function do_select( $field ) { + $current_value = isset( $this->settings->{ $field['key'] } ) ? $this->settings->{ $field['key'] } : ''; + ?> + + do_field_description( $field ); + } + + /** + * Output the field description, and example if present. + * + * @param array $field The settings field definition array. + * + * @return void + */ + public function do_field_description( $field ) { + ?> +

+ + +
: + + +

+ \n" +"Language-Team: LANGUAGE \n" +"Language: en\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Poedit-Country: United States\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: " +"__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_" +"attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n" +"X-Poedit-Basepath: ../\n" +"X-Poedit-SearchPath-0: .\n" +"X-Poedit-Bookmarks: \n" +"X-Textdomain-Support: yes\n" +"X-Generator: grunt-wp-i18n 1.0.3\n" + +#: includes/openid-connect-generic-client-wrapper.php:293 +msgid "Session expired. Please login again." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:540 +msgid "User identity is not linked to an existing WordPress user." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:598 +msgid "Invalid user." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:816 +msgid "No appropriate username found." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:826 +#. translators: %1$s is the santitized version of the username from the IDP. +msgid "Username %1$s could not be sanitized." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:848 +#. translators: %1$s is the configured User Claim nickname key. +msgid "No nickname found in user claim using key: %1$s." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:945 +msgid "User claim incomplete." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:1048 +msgid "Bad user claim result." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:1114 +msgid "Can not authorize." +msgstr "" + +#: includes/openid-connect-generic-client-wrapper.php:1143 +msgid "Failed user creation." +msgstr "" + +#: includes/openid-connect-generic-client.php:176 +msgid "Missing state." +msgstr "" + +#: includes/openid-connect-generic-client.php:180 +msgid "Invalid state." +msgstr "" + +#: includes/openid-connect-generic-client.php:195 +msgid "Missing authentication code." +msgstr "" + +#: includes/openid-connect-generic-client.php:240 +msgid "Request for authentication token failed." +msgstr "" + +#: includes/openid-connect-generic-client.php:273 +msgid "Refresh token failed." +msgstr "" + +#: includes/openid-connect-generic-client.php:288 +msgid "Missing token body." +msgstr "" + +#: includes/openid-connect-generic-client.php:296 +msgid "Invalid token." +msgstr "" + +#: includes/openid-connect-generic-client.php:349 +msgid "Request for userinfo failed." +msgstr "" + +#: includes/openid-connect-generic-client.php:409 +msgid "Missing authentication state." +msgstr "" + +#: includes/openid-connect-generic-client.php:446 +msgid "No identity token." +msgstr "" + +#: includes/openid-connect-generic-client.php:453 +msgid "Missing identity token." +msgstr "" + +#: includes/openid-connect-generic-client.php:480 +msgid "Bad ID token claim." +msgstr "" + +#: includes/openid-connect-generic-client.php:485 +msgid "No subject identity." +msgstr "" + +#: includes/openid-connect-generic-client.php:491 +msgid "No matching acr values." +msgstr "" + +#: includes/openid-connect-generic-client.php:511 +msgid "Bad user claim." +msgstr "" + +#: includes/openid-connect-generic-client.php:531 +msgid "Invalid user claim." +msgstr "" + +#: includes/openid-connect-generic-client.php:536 +msgid "Error from the IDP." +msgstr "" + +#: includes/openid-connect-generic-client.php:545 +msgid "Incorrect user claim." +msgstr "" + +#: includes/openid-connect-generic-client.php:552 +msgid "Unauthorized access." +msgstr "" + +#: includes/openid-connect-generic-login-form.php:122 +#. translators: %1$s is the error code from the IDP. +msgid "ERROR (%1$s)" +msgstr "" + +#: includes/openid-connect-generic-login-form.php:141 +msgid "Login with OpenID Connect" +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:228 +msgid "Details" +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:229 +msgid "Data" +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:236 +msgid "Date" +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:240 +msgid "Type" +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:244 +msgid "User" +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:248 +msgid "URI " +msgstr "" + +#: includes/openid-connect-generic-option-logger.php:252 +msgid "Response Time (sec)" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:108 +msgid "OpenID Connect - Generic Client" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:109 +msgid "OpenID Connect Client" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:133 +msgid "Client Settings" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:140 +msgid "WordPress User Settings" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:147 +msgid "Authorization Settings" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:154 +msgid "Log Settings" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:212 +msgid "Login Type" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:213 +msgid "Select how the client (login form) should provide login options." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:216 +msgid "OpenID Connect button on login form" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:217 +msgid "Auto Login - SSO" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:223 +msgid "Client ID" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:224 +msgid "" +"The ID this client will be recognized as when connecting the to Identity " +"provider server." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:231 +msgid "Client Secret Key" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:232 +msgid "" +"Arbitrary secret key the server expects from this client. Can be anything, " +"but should be very unique." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:238 +msgid "OpenID Scope" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:239 +msgid "Space separated list of scopes this client should access." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:246 +msgid "Login Endpoint URL" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:247 +msgid "Identify provider authorization endpoint." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:254 +msgid "Userinfo Endpoint URL" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:255 +msgid "Identify provider User information endpoint." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:262 +msgid "Token Validation Endpoint URL" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:263 +msgid "Identify provider token endpoint." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:270 +msgid "End Session Endpoint URL" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:271 +msgid "Identify provider logout endpoint." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:278 +msgid "ACR values" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:279 +msgid "Use a specific defined authentication contract from the IDP - optional." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:285 +msgid "Identity Key" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:286 +msgid "" +"Where in the user claim array to find the user's identification data. " +"Possible standard values: preferred_username, name, or sub. If you're " +"having trouble, use \"sub\"." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:292 +msgid "Disable SSL Verify" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:294 +#. translators: %1$s HTML tags for layout/styles, %2$s closing HTML tag for +#. styles. +msgid "" +"Do not require SSL verification during authorization. The OAuth extension " +"uses curl to make the request. By default CURL will generally verify the " +"SSL certificate to see if its valid an issued by an accepted CA. This " +"setting disabled that verification.%1$sNot recommended for production " +"sites.%2$s" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:299 +msgid "HTTP Request Timeout" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:300 +msgid "Set the timeout for requests made to the IDP. Default value is 5." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:306 +msgid "Enforce Privacy" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:307 +msgid "Require users be logged in to see the site." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:313 +msgid "Alternate Redirect URI" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:314 +msgid "" +"Provide an alternative redirect route. Useful if your server is causing " +"issues with the default admin-ajax method. You must flush rewrite rules " +"after changing this setting. This can be done by saving the Permalinks " +"settings page." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:319 +msgid "Nickname Key" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:320 +msgid "" +"Where in the user claim array to find the user's nickname. Possible " +"standard values: preferred_username, name, or sub." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:326 +msgid "Email Formatting" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:327 +msgid "" +"String from which the user's email address is built. Specify \"{email}\" as " +"long as the user claim contains an email claim." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:333 +msgid "Display Name Formatting" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:334 +msgid "String from which the user's display name is built." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:340 +msgid "Identify with User Name" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:341 +msgid "" +"If checked, the user's identity will be determined by the user name instead " +"of the email address." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:346 +msgid "State time limit" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:347 +msgid "State valid time in seconds. Defaults to 180" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:352 +msgid "Enable Refresh Token" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:353 +msgid "" +"If checked, support refresh tokens used to obtain access tokens from " +"supported IDPs." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:358 +msgid "Link Existing Users" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:359 +msgid "" +"If a WordPress account already exists with the same identity as a " +"newly-authenticated user over OpenID Connect, login as that user instead of " +"generating an error." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:365 +msgid "Create user if does not exist" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:366 +msgid "" +"If the user identity is not linked to an existing WordPress user, it is " +"created. If this setting is not enabled, and if the user authenticates with " +"an account which is not linked to an existing WordPress user, then the " +"authentication will fail." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:372 +msgid "Redirect Back to Origin Page" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:373 +msgid "" +"After a successful OpenID Connect authentication, this will redirect the " +"user back to the page on which they clicked the OpenID Connect login " +"button. This will cause the login process to proceed in a traditional " +"WordPress fashion. For example, users logging in through the default " +"wp-login.php page would end up on the WordPress Dashboard and users logging " +"in through the WooCommerce \"My Account\" page would end up on their " +"account page." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:379 +msgid "Redirect to the login screen when session is expired" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:380 +msgid "" +"When enabled, this will automatically redirect the user back to the " +"WordPress login page if their access token has expired." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:386 +msgid "Enable Logging" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:387 +msgid "Very simple log messages for debugging purposes." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:393 +msgid "Log Limit" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:394 +msgid "" +"Number of items to keep in the log. These logs are stored as an option in " +"the database, so space is limited." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:456 +msgid "Notes" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:459 +msgid "Redirect URI" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:463 +msgid "Login Button Shortcode" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:467 +msgid "Authentication URL Shortcode" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:472 +msgid "Logs" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:561 +msgid "Example" +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:574 +msgid "Enter your OpenID Connect identity provider settings." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:583 +msgid "Modify the interaction between OpenID Connect and WordPress users." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:592 +msgid "Control the authorization mechanics of the site." +msgstr "" + +#: includes/openid-connect-generic-settings-page.php:601 +msgid "Log information about login attempts through OpenID Connect Generic." +msgstr "" + +#: openid-connect-generic.php:242 +msgid "Private site" +msgstr "" + +#. Plugin Name of the plugin/theme +msgid "OpenID Connect Generic" +msgstr "" + +#. Plugin URI of the plugin/theme +msgid "https://github.com/daggerhart/openid-connect-generic" +msgstr "" + +#. Description of the plugin/theme +msgid "" +"Connect to an OpenID Connect identity provider using Authorization Code " +"Flow." +msgstr "" + +#. Author of the plugin/theme +msgid "daggerhart" +msgstr "" + +#. Author URI of the plugin/theme +msgid "http://www.daggerhart.com" +msgstr "" \ No newline at end of file diff --git a/wp-content/plugins/openid-connect-generic/openid-connect-generic.php b/wp-content/plugins/openid-connect-generic/openid-connect-generic.php new file mode 100644 index 00000000..bcf67390 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/openid-connect-generic.php @@ -0,0 +1,434 @@ + + * @copyright 2015-2023 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + * @link https://github.com/daggerhart + * + * @wordpress-plugin + * Plugin Name: OpenID Connect Generic + * Plugin URI: https://github.com/daggerhart/openid-connect-generic + * Description: Connect to an OpenID Connect identity provider using Authorization Code Flow. + * Version: 3.10.0 + * Requires at least: 5.0 + * Requires PHP: 7.4 + * Author: daggerhart + * Author URI: http://www.daggerhart.com + * Text Domain: daggerhart-openid-connect-generic + * Domain Path: /languages + * License: GPL-2.0+ + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt + * GitHub Plugin URI: https://github.com/daggerhart/openid-connect-generic + */ + +/* +Notes + Spec Doc - http://openid.net/specs/openid-connect-basic-1_0-32.html + + Filters + - openid-connect-generic-alter-request - 3 args: request array, plugin settings, specific request op + - openid-connect-generic-settings-fields - modify the fields provided on the settings page + - openid-connect-generic-login-button-text - modify the login button text + - openid-connect-generic-cookie-redirect-url - modify the redirect url stored as a cookie + - openid-connect-generic-user-login-test - (bool) should the user be logged in based on their claim + - openid-connect-generic-user-creation-test - (bool) should the user be created based on their claim + - openid-connect-generic-auth-url - modify the authentication url + - openid-connect-generic-alter-user-claim - modify the user_claim before a new user is created + - openid-connect-generic-alter-user-data - modify user data before a new user is created + - openid-connect-modify-token-response-before-validation - modify the token response before validation + - openid-connect-modify-id-token-claim-before-validation - modify the token claim before validation + + Actions + - openid-connect-generic-user-create - 2 args: fires when a new user is created by this plugin + - openid-connect-generic-user-update - 1 arg: user ID, fires when user is updated by this plugin + - openid-connect-generic-update-user-using-current-claim - 2 args: fires every time an existing user logs in and the claims are updated. + - openid-connect-generic-redirect-user-back - 2 args: $redirect_url, $user. Allows interruption of redirect during login. + - openid-connect-generic-user-logged-in - 1 arg: $user, fires when user is logged in. + - openid-connect-generic-cron-daily - daily cron action + - openid-connect-generic-state-not-found - the given state does not exist in the database, regardless of its expiration. + - openid-connect-generic-state-expired - the given state exists, but expired before this login attempt. + + Callable actions + + User Meta + - openid-connect-generic-subject-identity - the identity of the user provided by the idp + - openid-connect-generic-last-id-token-claim - the user's most recent id_token claim, decoded + - openid-connect-generic-last-user-claim - the user's most recent user_claim + - openid-connect-generic-last-token-response - the user's most recent token response + + Options + - openid_connect_generic_settings - plugin settings + - openid-connect-generic-valid-states - locally stored generated states +*/ + + +/** + * OpenID_Connect_Generic class. + * + * Defines plugin initialization functionality. + * + * @package OpenID_Connect_Generic + * @category General + */ +class OpenID_Connect_Generic { + + /** + * Singleton instance of self + * + * @var OpenID_Connect_Generic + */ + protected static $_instance = null; + + /** + * Plugin version. + * + * @var string + */ + const VERSION = '3.10.0'; + + /** + * Plugin settings. + * + * @var OpenID_Connect_Generic_Option_Settings + */ + private $settings; + + /** + * Plugin logs. + * + * @var OpenID_Connect_Generic_Option_Logger + */ + private $logger; + + /** + * Openid Connect Generic client + * + * @var OpenID_Connect_Generic_Client + */ + private $client; + + /** + * Client wrapper. + * + * @var OpenID_Connect_Generic_Client_Wrapper + */ + public $client_wrapper; + + /** + * Setup the plugin + * + * @param OpenID_Connect_Generic_Option_Settings $settings The settings object. + * @param OpenID_Connect_Generic_Option_Logger $logger The loggin object. + * + * @return void + */ + public function __construct( OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ) { + $this->settings = $settings; + $this->logger = $logger; + self::$_instance = $this; + } + + // @codeCoverageIgnoreStart + + /** + * WordPress Hook 'init'. + * + * @return void + */ + public function init() { + + $this->client = new OpenID_Connect_Generic_Client( + $this->settings->client_id, + $this->settings->client_secret, + $this->settings->scope, + $this->settings->endpoint_login, + $this->settings->endpoint_userinfo, + $this->settings->endpoint_token, + $this->get_redirect_uri( $this->settings ), + $this->settings->acr_values, + $this->get_state_time_limit( $this->settings ), + $this->logger + ); + + $this->client_wrapper = OpenID_Connect_Generic_Client_Wrapper::register( $this->client, $this->settings, $this->logger ); + if ( defined( 'WP_CLI' ) && WP_CLI ) { + return; + } + + OpenID_Connect_Generic_Login_Form::register( $this->settings, $this->client_wrapper ); + + // Add a shortcode to get the auth URL. + add_shortcode( 'openid_connect_generic_auth_url', array( $this->client_wrapper, 'get_authentication_url' ) ); + + // Add actions to our scheduled cron jobs. + add_action( 'openid-connect-generic-cron-daily', array( $this, 'cron_states_garbage_collection' ) ); + + $this->upgrade(); + + if ( is_admin() ) { + OpenID_Connect_Generic_Settings_Page::register( $this->settings, $this->logger ); + } + } + + /** + * Get the default redirect URI. + * + * @param OpenID_Connect_Generic_Option_Settings $settings The settings object. + * + * @return string + */ + public function get_redirect_uri( OpenID_Connect_Generic_Option_Settings $settings ) { + $redirect_uri = admin_url( 'admin-ajax.php?action=openid-connect-authorize' ); + + if ( $settings->alternate_redirect_uri ) { + $redirect_uri = site_url( '/openid-connect-authorize' ); + } + + return $redirect_uri; + } + + /** + * Get the default state time limit. + * + * @param OpenID_Connect_Generic_Option_Settings $settings The settings object. + * + * @return int + */ + public function get_state_time_limit( OpenID_Connect_Generic_Option_Settings $settings ) { + $state_time_limit = 180; + // State time limit cannot be zero. + if ( $settings->state_time_limit ) { + $state_time_limit = intval( $settings->state_time_limit ); + } + + return $state_time_limit; + } + + /** + * Check if privacy enforcement is enabled, and redirect users that aren't + * logged in. + * + * @return void + */ + public function enforce_privacy_redirect() { + if ( $this->settings->enforce_privacy && ! is_user_logged_in() ) { + // The client endpoint relies on the wp-admin ajax endpoint. + if ( + ! defined( 'DOING_AJAX' ) || + ! boolval( constant( 'DOING_AJAX' ) ) || + ! isset( $_GET['action'] ) || + 'openid-connect-authorize' != $_GET['action'] ) { + auth_redirect(); + } + } + } + + /** + * Enforce privacy settings for rss feeds. + * + * @param string $content The content. + * + * @return mixed + */ + public function enforce_privacy_feeds( $content ) { + if ( $this->settings->enforce_privacy && ! is_user_logged_in() ) { + $content = __( 'Private site', 'daggerhart-openid-connect-generic' ); + } + return $content; + } + + /** + * Handle plugin upgrades + * + * @return void + */ + public function upgrade() { + $last_version = get_option( 'openid-connect-generic-plugin-version', 0 ); + $settings = $this->settings; + + if ( version_compare( self::VERSION, $last_version, '>' ) ) { + // An upgrade is required. + self::setup_cron_jobs(); + + // @todo move this to another file for upgrade scripts + if ( isset( $settings->ep_login ) ) { + $settings->endpoint_login = $settings->ep_login; + $settings->endpoint_token = $settings->ep_token; + $settings->endpoint_userinfo = $settings->ep_userinfo; + + unset( $settings->ep_login, $settings->ep_token, $settings->ep_userinfo ); + $settings->save(); + } + + // Update the stored version number. + update_option( 'openid-connect-generic-plugin-version', self::VERSION ); + } + } + + /** + * Expire state transients by attempting to access them and allowing the + * transient's own mechanisms to delete any that have expired. + * + * @return void + */ + public function cron_states_garbage_collection() { + global $wpdb; + $states = $wpdb->get_col( "SELECT `option_name` FROM {$wpdb->options} WHERE `option_name` LIKE '_transient_openid-connect-generic-state--%'" ); + + if ( ! empty( $states ) ) { + foreach ( $states as $state ) { + $transient = str_replace( '_transient_', '', $state ); + get_transient( $transient ); + } + } + } + + /** + * Ensure cron jobs are added to the schedule. + * + * @return void + */ + public static function setup_cron_jobs() { + if ( ! wp_next_scheduled( 'openid-connect-generic-cron-daily' ) ) { + wp_schedule_event( time(), 'daily', 'openid-connect-generic-cron-daily' ); + } + } + + /** + * Activation hook. + * + * @return void + */ + public static function activation() { + self::setup_cron_jobs(); + } + + /** + * Deactivation hook. + * + * @return void + */ + public static function deactivation() { + wp_clear_scheduled_hook( 'openid-connect-generic-cron-daily' ); + } + + /** + * Simple autoloader. + * + * @param string $class The class name. + * + * @return void + */ + public static function autoload( $class ) { + $prefix = 'OpenID_Connect_Generic_'; + + if ( stripos( $class, $prefix ) !== 0 ) { + return; + } + + $filename = $class . '.php'; + + // Internal files are all lowercase and use dashes in filenames. + if ( false === strpos( $filename, '\\' ) ) { + $filename = strtolower( str_replace( '_', '-', $filename ) ); + } else { + $filename = str_replace( '\\', DIRECTORY_SEPARATOR, $filename ); + } + + $filepath = __DIR__ . '/includes/' . $filename; + + if ( file_exists( $filepath ) ) { + require_once $filepath; + } + } + + /** + * Instantiate the plugin and hook into WordPress. + * + * @return void + */ + public static function bootstrap() { + /** + * This is a documented valid call for spl_autoload_register. + * + * @link https://www.php.net/manual/en/function.spl-autoload-register.php#71155 + */ + spl_autoload_register( array( 'OpenID_Connect_Generic', 'autoload' ) ); + + $settings = new OpenID_Connect_Generic_Option_Settings( + // Default settings values. + array( + // OAuth client settings. + 'login_type' => defined( 'OIDC_LOGIN_TYPE' ) ? OIDC_LOGIN_TYPE : 'button', + 'client_id' => defined( 'OIDC_CLIENT_ID' ) ? OIDC_CLIENT_ID : '', + 'client_secret' => defined( 'OIDC_CLIENT_SECRET' ) ? OIDC_CLIENT_SECRET : '', + 'scope' => defined( 'OIDC_CLIENT_SCOPE' ) ? OIDC_CLIENT_SCOPE : '', + 'endpoint_login' => defined( 'OIDC_ENDPOINT_LOGIN_URL' ) ? OIDC_ENDPOINT_LOGIN_URL : '', + 'endpoint_userinfo' => defined( 'OIDC_ENDPOINT_USERINFO_URL' ) ? OIDC_ENDPOINT_USERINFO_URL : '', + 'endpoint_token' => defined( 'OIDC_ENDPOINT_TOKEN_URL' ) ? OIDC_ENDPOINT_TOKEN_URL : '', + 'endpoint_end_session' => defined( 'OIDC_ENDPOINT_LOGOUT_URL' ) ? OIDC_ENDPOINT_LOGOUT_URL : '', + 'acr_values' => defined( 'OIDC_ACR_VALUES' ) ? OIDC_ACR_VALUES : '', + + // Non-standard settings. + 'no_sslverify' => 0, + 'http_request_timeout' => 5, + 'identity_key' => 'preferred_username', + 'nickname_key' => 'preferred_username', + 'email_format' => '{email}', + 'displayname_format' => '', + 'identify_with_username' => false, + 'state_time_limit' => 180, + + // Plugin settings. + 'enforce_privacy' => defined( 'OIDC_ENFORCE_PRIVACY' ) ? intval( OIDC_ENFORCE_PRIVACY ) : 0, + 'alternate_redirect_uri' => 0, + 'token_refresh_enable' => 1, + 'link_existing_users' => defined( 'OIDC_LINK_EXISTING_USERS' ) ? intval( OIDC_LINK_EXISTING_USERS ) : 0, + 'create_if_does_not_exist' => defined( 'OIDC_CREATE_IF_DOES_NOT_EXIST' ) ? intval( OIDC_CREATE_IF_DOES_NOT_EXIST ) : 1, + 'redirect_user_back' => defined( 'OIDC_REDIRECT_USER_BACK' ) ? intval( OIDC_REDIRECT_USER_BACK ) : 0, + 'redirect_on_logout' => defined( 'OIDC_REDIRECT_ON_LOGOUT' ) ? intval( OIDC_REDIRECT_ON_LOGOUT ) : 1, + 'enable_logging' => defined( 'OIDC_ENABLE_LOGGING' ) ? intval( OIDC_ENABLE_LOGGING ) : 0, + 'log_limit' => defined( 'OIDC_LOG_LIMIT' ) ? intval( OIDC_LOG_LIMIT ) : 1000, + ) + ); + + $logger = new OpenID_Connect_Generic_Option_Logger( 'error', $settings->enable_logging, $settings->log_limit ); + + $plugin = new self( $settings, $logger ); + + add_action( 'init', array( $plugin, 'init' ) ); + + // Privacy hooks. + add_action( 'template_redirect', array( $plugin, 'enforce_privacy_redirect' ), 0 ); + add_filter( 'the_content_feed', array( $plugin, 'enforce_privacy_feeds' ), 999 ); + add_filter( 'the_excerpt_rss', array( $plugin, 'enforce_privacy_feeds' ), 999 ); + add_filter( 'comment_text_rss', array( $plugin, 'enforce_privacy_feeds' ), 999 ); + } + + /** + * Create (if needed) and return a singleton of self. + * + * @return OpenID_Connect_Generic + */ + public static function instance() { + if ( null === self::$_instance ) { + self::bootstrap(); + } + return self::$_instance; + } +} + +OpenID_Connect_Generic::instance(); + +register_activation_hook( __FILE__, array( 'OpenID_Connect_Generic', 'activation' ) ); +register_deactivation_hook( __FILE__, array( 'OpenID_Connect_Generic', 'deactivation' ) ); + +// Provide publicly accessible plugin helper functions. +require_once 'includes/functions.php'; diff --git a/wp-content/plugins/openid-connect-generic/readme.txt b/wp-content/plugins/openid-connect-generic/readme.txt new file mode 100644 index 00000000..f1941df6 --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/readme.txt @@ -0,0 +1,125 @@ +=== OpenID Connect Generic Client === +Contributors: daggerhart, tnolte +Donate link: http://www.daggerhart.com/ +Tags: security, login, oauth2, openidconnect, apps, authentication, autologin, sso +Requires at least: 5.0 +Tested up to: 6.4.3 +Stable tag: 3.10.0 +Requires PHP: 7.4 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +A simple client that provides SSO or opt-in authentication against a generic OAuth2 Server implementation. + +== Description == + +This plugin allows to authenticate users against OpenID Connect OAuth2 API with Authorization Code Flow. +Once installed, it can be configured to automatically authenticate users (SSO), or provide a "Login with OpenID Connect" +button on the login form. After consent has been obtained, an existing user is automatically logged into WordPress, while +new users are created in WordPress database. + +Much of the documentation can be found on the Settings > OpenID Connect Generic dashboard page. + +Please submit issues to the Github repo: https://github.com/daggerhart/openid-connect-generic + +== Installation == + +1. Upload to the `/wp-content/plugins/` directory +1. Activate the plugin +1. Visit Settings > OpenID Connect and configure to meet your needs + +== Frequently Asked Questions == + += What is the client's Redirect URI? = + +Most OAuth2 servers will require whitelisting a set of redirect URIs for security purposes. The Redirect URI provided +by this client is like so: https://example.com/wp-admin/admin-ajax.php?action=openid-connect-authorize + +Replace `example.com` with your domain name and path to WordPress. + += Can I change the client's Redirect URI? = + +Some OAuth2 servers do not allow for a client redirect URI to contain a query string. The default URI provided by +this module leverages WordPress's `admin-ajax.php` endpoint as an easy way to provide a route that does not include +HTML, but this will naturally involve a query string. Fortunately, this plugin provides a setting that will make use of +an alternate redirect URI that does not include a query string. + +On the settings page for this plugin (Dashboard > Settings > OpenID Connect Generic) there is a checkbox for +**Alternate Redirect URI**. When checked, the plugin will use the Redirect URI +`https://example.com/openid-connect-authorize`. + + +== Changelog == + += 3.10.0 = + +* Chore: @timnolte - Dependency updates. +* Fix: @drzraf - Prevents running the auth url filter twice. +* Fix: @timnolte - Updates the log cleanup handling to properly retain the configured number of log entries. +* Fix: @timnolte - Updates the log display output to reflect the log retention policy. +* Chore: @timnolte - Adds Unit Testing & New Local Development Environment. +* Feature: @timnolte - Updates logging to allow for tracking processing time. +* Feature: @menno-ll - Adds a remember me feature via a new filter. +* Improvement: @menno-ll - Updates WP Cookie Expiration to Same as Session Length. + += 3.9.1 = + +* Improvement: @timnolte - Refactors Composer setup and GitHub Actions. +* Improvement: @timnolte - Bumps WordPress tested version compatibility. + += 3.9.0 = + +* Feature: @matchaxnb - Added support for additional configuration constants. +* Feature: @schanzen - Added support for agregated claims. +* Fix: @rkcreation - Fixed access token not updating user metadata after login. +* Fix: @danc1248 - Fixed user creation issue on Multisite Networks. +* Feature: @RobjS - Added plugin singleton to support for more developer customization. +* Feature: @jkouris - Added action hook to allow custom handling of session expiration. +* Fix: @tommcc - Fixed admin CSS loading only on the plugin settings screen. +* Feature: @rkcreation - Added method to refresh the user claim. +* Feature: @Glowsome - Added acr_values support & verification checks that it when defined in options is honored. +* Fix: @timnolte - Fixed regression which caused improper fallback on missing claims. +* Fix: @slykar - Fixed missing query string handling in redirect URL. +* Fix: @timnolte - Fixed issue with some user linking and user creation handling. +* Improvement: @timnolte - Fixed plugin settings typos and screen formatting. +* Security: @timnolte - Updated build tooling security vulnerabilities. +* Improvement: @timnolte - Changed build tooling scripts. + += 3.8.5 = + +* Fix: @timnolte - Fixed missing URL request validation before use & ensure proper current page URL is setup for Redirect Back. +* Fix: @timnolte - Fixed Redirect URL Logic to Handle Sub-directory Installs. +* Fix: @timnolte - Fixed issue with redirecting user back when the openid_connect_generic_auth_url shortcode is used. + += 3.8.4 = + +* Fix: @timnolte - Fixed invalid State object access for redirection handling. +* Improvement: @timnolte - Fixed local wp-env Docker development environment. +* Improvement: @timnolte - Fixed Composer scripts for linting and static analysis. + += 3.8.3 = + +* Fix: @timnolte - Fixed problems with proper redirect handling. +* Improvement: @timnolte - Changes redirect handling to use State instead of cookies. +* Improvement: @timnolte - Refactored additional code to meet coding standards. + += 3.8.2 = + +* Fix: @timnolte - Fixed reported XSS vulnerability on WordPress login screen. + += 3.8.1 = + +* Fix: @timnolte - Prevent SSO redirect on password protected posts. +* Fix: @timnolte - CI/CD build issues. +* Fix: @timnolte - Invalid redirect handling on logout for Auto Login setting. + += 3.8.0 = + +* Feature: @timnolte - Ability to use 6 new constants for setting client configuration instead of storing in the DB. +* Improvement: @timnolte - Plugin development & contribution updates. +* Improvement: @timnolte - Refactored to meet WordPress coding standards. +* Improvement: @timnolte - Refactored to provide localization. + +-------- + +[See the previous changelogs here](https://github.com/oidc-wp/openid-connect-generic/blob/main/CHANGELOG.md#changelog) diff --git a/wp-content/plugins/openid-connect-generic/wp-cli.yml b/wp-content/plugins/openid-connect-generic/wp-cli.yml new file mode 100644 index 00000000..3f430d6f --- /dev/null +++ b/wp-content/plugins/openid-connect-generic/wp-cli.yml @@ -0,0 +1 @@ +path: /app/wp