|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Coudflare Access SSO |
| 4 | + * |
| 5 | + * @package CloudflareAccessSSO |
| 6 | + * @link https://github.com/jamesmorrison/cloudflare-access-sso |
| 7 | + * @author James Morrison |
| 8 | + * @copyright James Morrison 2023 |
| 9 | + * @license GPL v2 or later |
| 10 | + * |
| 11 | + * Plugin Name: Cloudflare Access SSO |
| 12 | + * Description: Facilitates automatic login to WordPress when domain is protected with Cloudflare Access |
| 13 | + * Version: 0.1.0 |
| 14 | + * Plugin URI: https://github.com/jamesmorrison/cloudflare-access-sso |
| 15 | + * Author: James Morrison |
| 16 | + * Author URI: https://jamesmorrison.uk/ |
| 17 | + * Text Domain: cloudflare-access-sso |
| 18 | + * Domain Path: /languages/ |
| 19 | + * |
| 20 | + * This program is free software; you can redistribute it and/or modify |
| 21 | + * it under the terms of the GNU General Public License as published by |
| 22 | + * the Free Software Foundation; either version 2 of the License, or |
| 23 | + * (at your option) any later version. |
| 24 | + * |
| 25 | + * This program is distributed in the hope that it will be useful, |
| 26 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | + * GNU General Public License for more details. |
| 29 | + **/ |
| 30 | + |
| 31 | +// Security check |
| 32 | +defined( 'ABSPATH' ) || exit; |
| 33 | + |
| 34 | +// The Cloudflare Team Name is required. |
| 35 | +if ( ! defined( 'CF_ACCESS_TEAM_NAME' ) ) { |
| 36 | + error_log( 'Cloudflare Access SSO Error: CF_ACCESS_TEAM_NAME is not defined.' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 37 | + return; |
| 38 | +} |
| 39 | + |
| 40 | +// The Cloudflare Application ID is required. |
| 41 | +if ( ! defined( 'CF_ACCESS_AUD' ) ) { |
| 42 | + error_log( 'Cloudflare Access SSO Error: CF_ACCESS_AUD is not defined.' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 43 | + return; |
| 44 | +} |
| 45 | + |
| 46 | +// Default to not enforcing SSO (which redirects wp-login => wp-admin) |
| 47 | +if ( ! defined( 'CF_ACCESS_ENFORCE_SSO' ) ) { |
| 48 | + define( 'CF_ACCESS_ENFORCE_SSO', false ); |
| 49 | +} |
| 50 | + |
| 51 | +// Default to 3 attempts to complete authentication |
| 52 | +if ( ! defined( 'CF_ACCESS_ATTEMPTS' ) ) { |
| 53 | + define( 'CF_ACCESS_ATTEMPTS', 3 ); |
| 54 | +} |
| 55 | + |
| 56 | +// Default to 60 second leeway |
| 57 | +if ( ! defined( 'CF_ACCESS_LEEWAY' ) ) { |
| 58 | + define( 'CF_ACCESS_LEEWAY', 60 ); |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +// Useful global constants. |
| 63 | +define( 'CLOUDFLARE_ACCESS_SSO_PLUGIN_VERSION', '0.1.0' ); |
| 64 | +define( 'CLOUDFLARE_ACCESS_SSO_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 65 | +define( 'CLOUDFLARE_ACCESS_SSO_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); |
| 66 | +define( 'CLOUDFLARE_ACCESS_SSO_PLUGIN_INC', CLOUDFLARE_ACCESS_SSO_PLUGIN_PATH . 'includes/' ); |
| 67 | + |
| 68 | +// Require Composer autoloader if it exists. |
| 69 | +if ( file_exists( CLOUDFLARE_ACCESS_SSO_PLUGIN_PATH . 'vendor/autoload.php' ) ) { |
| 70 | + require_once CLOUDFLARE_ACCESS_SSO_PLUGIN_PATH . 'vendor/autoload.php'; |
| 71 | +} |
| 72 | + |
| 73 | +// Include files. |
| 74 | +require_once CLOUDFLARE_ACCESS_SSO_PLUGIN_INC . '/core.php'; |
| 75 | + |
| 76 | +// Activation/Deactivation. |
| 77 | +register_activation_hook( __FILE__, '\CloudflareAccessSSO\Core\activate' ); |
| 78 | +register_deactivation_hook( __FILE__, '\CloudflareAccessSSO\Core\deactivate' ); |
| 79 | + |
| 80 | +// Bootstrap. |
| 81 | +CloudflareAccessSSO\Core\setup(); |
0 commit comments