diff --git a/WP_Auth0.php b/WP_Auth0.php old mode 100755 new mode 100644 index a6e5471cc..dd6a5e0e2 --- a/WP_Auth0.php +++ b/WP_Auth0.php @@ -11,227 +11,432 @@ define('WPA0_PLUGIN_DIR', trailingslashit(plugin_dir_path(__FILE__))); define('WPA0_PLUGIN_URL', trailingslashit(plugin_dir_url(__FILE__) )); define('WPA0_LANG', 'wp-auth0'); +define('AUTH0_DB_VERSION', 2); class WP_Auth0 { - public static function init(){ - spl_autoload_register(array(__CLASS__, 'autoloader')); - register_shutdown_function(array('WP_Auth0_Utils', 'log_crash')); - - WP_Auth0_Referer_Check::init(); - WP_Auth0_Ip_Check::init(); - - add_action( 'init', array(__CLASS__, 'wp_init') ); - - register_activation_hook( WPA0_PLUGIN_FILE, array(__CLASS__, 'install') ); - register_deactivation_hook( WPA0_PLUGIN_FILE, array(__CLASS__, 'uninstall') ); - - add_action( 'plugins_loaded', array(__CLASS__, 'initialize_wpdb_tables')); - add_action( 'template_redirect', array(__CLASS__, 'init_auth0'), 1 ); - - add_filter( 'login_message', array(__CLASS__, 'render_form') ); - add_shortcode( 'auth0', array(__CLASS__, 'shortcode' ) ); - - add_action( 'wp_enqueue_scripts', array(__CLASS__, 'wp_enqueue')); - - WP_Auth0_Admin::init(); - } - - public static function wp_enqueue(){ - $activated = absint(WP_Auth0_Options::get( 'active' )); - if(!$activated) - return; - - $auto_login = absint(WP_Auth0_Options::get( 'auto_login' )); - - if(!$auto_login){ - wp_enqueue_style( 'auth0-widget', WPA0_PLUGIN_URL . 'assets/css/main.css' ); - - if(WP_Auth0_Options::get('wp_login_form')){ - wp_enqueue_script( 'auth0-wp-login-form', WPA0_PLUGIN_URL . 'assets/js/wp-login.js', array('jquery') ); - wp_localize_script( 'auth0-wp-login-form', 'wpa0', array( - 'wp_btn' => WP_Auth0_Options::get('wp_login_btn_text') - )); - } - }else{ - wp_enqueue_script( 'auth0-wp-login-form', WPA0_PLUGIN_URL . 'assets/js/auth0.min.js', array('jquery') ); - } - } - - public static function shortcode( $atts ){ - ob_start(); - include WPA0_PLUGIN_DIR . 'templates/login-form.php'; - $html = ob_get_clean(); - return $html; - } - - public static function render_form( $html ){ - $activated = absint(WP_Auth0_Options::get( 'active' )); - $auto_login = absint(WP_Auth0_Options::get( 'auto_login' )); - - if(!$activated) - return $html; - - ob_start(); - - if(!$auto_login) - include WPA0_PLUGIN_DIR . 'templates/login-form.php'; - else - include WPA0_PLUGIN_DIR . 'templates/login-auto.php'; - - $html = ob_get_clean(); - return $html; - } - - public static function init_auth0(){ - global $wp_query; - - if(!isset($wp_query->query_vars['auth0']) || $wp_query->query_vars['auth0'] != '1') - return; - - $code = $wp_query->query_vars['code']; - $state = $wp_query->query_vars['state']; - $endpoint = WP_Auth0_Options::get( 'endpoint' ); - $client_id = WP_Auth0_Options::get( 'client_id' ); - $client_secret = WP_Auth0_Options::get( 'client_secret' ); - - if(empty($client_id)) wp_die(__('Error: Your Auth0 Client ID has not been entered in the Auth0 SSO plugin settings.', WPA0_LANG)); - if(empty($client_secret)) wp_die(__('Error: Your Auth0 Client Secret has not been entered in the Auth0 SSO plugin settings.', WPA0_LANG)); - if(empty($endpoint)) wp_die(__('Error: No Auth0 Endpoint defined in Wordpress Administration!', WPA0_LANG)); - - $body = array( - 'client_id' => $client_id, - 'redirect_uri' => home_url(), - 'client_secret' => $client_secret, - 'code' => $code, - 'grant_type' => 'authorization_code' - ); - - $headers = array( - 'content-type' => 'application/x-www-form-urlencoded' - ); - - $response = wp_remote_post( $endpoint . 'oauth/token', array( - 'headers' => $headers, - 'body' => $body - )); - - $data = json_decode( $response['body'] ); - - if(isset($data->access_token)){ - $response = wp_remote_get( $endpoint . 'userinfo/?access_token=' . $data->access_token ); - $userinfo = json_decode( $response['body'] ); - - self::login_user($userinfo); - }else{ - // Login failed! - wp_redirect( home_url() . '?message=' . $data->error_description ); - //echo "Error logging in! Description received was:
" . $data->error_description; - } - exit(); - } - - private static function login_user( $userinfo ){ - $user = get_user_by( 'email', $userinfo->email ); - - // Check if we got an instance of a WP_User, which means the user exists - if($user instanceof WP_User){ - // User exists! Log in - wp_set_auth_cookie( $user->ID ); - wp_redirect( home_url() ); - exit(); - }else{ - // User doesn't exist - create it! - $user_id = (int)WP_Auth0_Users::create_user($userinfo); - - // Check if user was created - if($user_id > 0){ - // User created! Login and redirect - wp_set_auth_cookie( $user_id ); - wp_redirect( home_url() ); - exit(); - }elseif($user_id == -2){ - $msg = __('Error: Could not create user. The registration process were rejected. Please verify that your account is whitelisted for this system.', WPA0_LANG); - $msg .= '

'; - $msg .= '' . __('← Go back', WPA0_LANG) . ''; - - wp_die($msg); - }else{ - $msg = __('Error: Could not create user.', WPA0_LANG); - $msg .= '

'; - $msg .= '' . __('← Go back', WPA0_LANG) . ''; - wp_die($msg); - } - } - } - - public static function wp_init(){ - self::setup_rewrites(); - } - - private static function setup_rewrites(){ - add_rewrite_tag('%auth0%', '([^&]+)'); - add_rewrite_tag('%code%', '([^&]+)'); - add_rewrite_tag('%state%', '([^&]+)'); - add_rewrite_rule('^auth0', 'index.php?auth0=1', 'top'); - } - - public static function install(){ - self::install_db(); - self::setup_rewrites(); - - flush_rewrite_rules(); - } - - public static function uninstall(){ - flush_rewrite_rules(); - } - - private static function install_db(){ - global $wpdb; - - self::initialize_wpdb_tables(); - - $sql = array(); - - $sql[] = "CREATE TABLE ".$wpdb->auth0_log." ( - id INT(11) AUTO_INCREMENT NOT NULL, - event VARCHAR(100) NOT NULL, - level VARCHAR(100) NOT NULL DEFAULT 'notice', - description TEXT, - details LONGTEXT, - logtime INT(11) NOT NULL, - PRIMARY KEY (id) - );"; - - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - - foreach($sql as $s) - dbDelta($s); - } - - public static function initialize_wpdb_tables(){ - global $wpdb; - - $wpdb->auth0_log = $wpdb->prefix."auth0_log"; - } - - private static function autoloader($class){ - $path = WPA0_PLUGIN_DIR; - $paths = array(); - $exts = array('.php', '.class.php'); - - $paths[] = $path; - $paths[] = $path.'lib/'; - - foreach($paths as $p) - foreach($exts as $ext){ - if(file_exists($p.$class.$ext)){ - require_once($p.$class.$ext); - return true; - } - } - - return false; - } + public static function init(){ + spl_autoload_register(array(__CLASS__, 'autoloader')); + register_shutdown_function(array('WP_Auth0_Utils', 'log_crash')); + + // WP_Auth0_Referer_Check::init(); + WP_Auth0_Ip_Check::init(); + + add_action( 'init', array(__CLASS__, 'wp_init') ); + + // Add hooks for clear up session + add_action( 'wp_logout', array(__CLASS__, 'logout') ); + add_action( 'wp_login', array(__CLASS__, 'end_session') ); + + // Add hooks for install uninstall and update + register_activation_hook( WPA0_PLUGIN_FILE, array(__CLASS__, 'install') ); + register_deactivation_hook( WPA0_PLUGIN_FILE, array(__CLASS__, 'uninstall') ); + add_action( 'plugins_loaded', array(__CLASS__, 'check_update')); + + + add_action( 'plugins_loaded', array(__CLASS__, 'initialize_wpdb_tables')); + add_action( 'template_redirect', array(__CLASS__, 'init_auth0'), 1 ); + + add_filter( 'login_message', array(__CLASS__, 'render_form') ); + // Add hook to redirect directly on login auto + add_action('login_init', array(__CLASS__, 'login_auto')); + // Add hook to handle when a user is deleted + add_action( 'delete_user', array(__CLASS__, 'delete_user') ); + + add_shortcode( 'auth0', array(__CLASS__, 'shortcode' ) ); + + add_action( 'wp_enqueue_scripts', array(__CLASS__, 'wp_enqueue')); + + WP_Auth0_Admin::init(); + } + + public static function wp_enqueue(){ + $activated = absint(WP_Auth0_Options::get( 'active' )); + if(!$activated) { + return; + } + + wp_enqueue_style( 'auth0-widget', WPA0_PLUGIN_URL . 'assets/css/main.css' ); + } + + public static function shortcode( $atts ){ + ob_start(); + include WPA0_PLUGIN_DIR . 'templates/login-form.php'; + $html = ob_get_clean(); + return $html; + } + + public static function login_auto() { + $auto_login = absint(WP_Auth0_Options::get( 'auto_login' )); + + if ($auto_login && $_GET["action"] != "logout") { + + $stateObj = array("interim" => false, "uuid" =>uniqid()); + $state = $_SESSION['auth0_state'] = json_encode($stateObj); + // Create the link to log in + + $login_url = "https://". WP_Auth0_Options::get('domain') . + "/authorize?response_type=code&scope=openid%20profile". + "&client_id=".WP_Auth0_Options::get('client_id') . + "&redirect_uri=".site_url('/index.php?auth0=1') . + "&state=".urlencode($state). + "&connection=".WP_Auth0_Options::get('auto_login_method'); + + wp_redirect($login_url); + die(); + } + } + + public static function logout() { + self::end_session(); + + $auto_login = absint(WP_Auth0_Options::get( 'auto_login' )); + if ($auto_login) { + wp_redirect(home_url()); + die(); + } + + } + + + public static function render_form( $html ){ + $activated = absint(WP_Auth0_Options::get( 'active' )); + + if(!$activated) + return $html; + + ob_start(); + + include WPA0_PLUGIN_DIR . 'templates/login-form.php'; + + $html = ob_get_clean(); + return $html; + } + + public static function init_auth0(){ + global $wp_query; + + if(!isset($wp_query->query_vars['auth0']) || $wp_query->query_vars['auth0'] != '1') { + return; + } + + $code = $wp_query->query_vars['code']; + $state = $wp_query->query_vars['state']; + $stateFromGet = json_decode(stripcslashes($state)); + $stateFromSession = json_decode($_SESSION['auth0_state']); + + $domain = WP_Auth0_Options::get( 'domain' ); + $endpoint = "https://" . $domain . "/"; + $client_id = WP_Auth0_Options::get( 'client_id' ); + $client_secret = WP_Auth0_Options::get( 'client_secret' ); + + if(empty($client_id)) wp_die(__('Error: Your Auth0 Client ID has not been entered in the Auth0 SSO plugin settings.', WPA0_LANG)); + if(empty($client_secret)) wp_die(__('Error: Your Auth0 Client Secret has not been entered in the Auth0 SSO plugin settings.', WPA0_LANG)); + if(empty($domain)) wp_die(__('Error: No Domain defined in Wordpress Administration!', WPA0_LANG)); + + if ($stateFromSession->uuid != $stateFromGet->uuid) + wp_die(__('Error: The state code doesn\'t match! Are you sure you are comming from the page?', WPA0_LANG)); + + $body = array( + 'client_id' => $client_id, + 'redirect_uri' => home_url(), + 'client_secret' => $client_secret, + 'code' => $code, + 'grant_type' => 'authorization_code' + ); + + $headers = array( + 'content-type' => 'application/x-www-form-urlencoded' + ); + + + $response = wp_remote_post( $endpoint . 'oauth/token', array( + 'headers' => $headers, + 'body' => $body + )); + + if ($response instanceof WP_Error) { + error_log($response->get_error_message()); + $msg = __('Sorry. There was a problem logging you in.', WPA0_LANG); + $msg .= '

'; + $msg .= '' . __('← Login', WPA0_LANG) . ''; + wp_die($msg); + } + + $data = json_decode( $response['body'] ); + if(isset($data->access_token)){ + // Get the user information + $response = wp_remote_get( $endpoint . 'userinfo/?access_token=' . $data->access_token ); + if ($response instanceof WP_Error) { + error_log($response->get_error_message()); + $msg = __('Sorry, there was a problem logging you in.', WPA0_LANG); + $msg .= '

'; + $msg .= '' . __('← Login', WPA0_LANG) . ''; + wp_die($msg); + } + + $userinfo = json_decode( $response['body'] ); + if (self::login_user($userinfo, $data)) { + if ($stateFromGet->interim) { + include WPA0_PLUGIN_DIR . 'templates/login-interim.php'; + exit(); + + } else { + wp_safe_redirect( home_url() ); + } + } + }else{ + // Login failed! + wp_redirect( home_url() . '?message=' . $data->error_description ); + //echo "Error logging in! Description received was:
" . $data->error_description; + } + + exit(); + } + + private static function findAuth0User($id) { + global $wpdb; + $sql = 'SELECT u.* + FROM ' . $wpdb->auth0_user .' a + JOIN ' . $wpdb->users . ' u ON a.wp_id = u.id + WHERE a.auth0_id = %s'; + $userRow = $wpdb->get_row($wpdb->prepare($sql, $id)); + if (is_null($userRow) || $userRow instanceof WP_Error ) { + return null; + } + $user = new WP_User(); + $user->init($userRow); + return $user; + } + + private static function insertAuth0User($userinfo, $user_id) { + global $wpdb; + $wpdb->insert( + $wpdb->auth0_user, + array( + 'auth0_id' => $userinfo->user_id, + 'wp_id' => $user_id, + 'auth0_obj' => serialize($userinfo) + ), + array( + '%s', + '%d', + '%s' + ) + ); + } + + private static function updateAuth0Object($userinfo) { + global $wpdb; + $wpdb->update( + $wpdb->auth0_user, + array( + 'auth0_obj' => serialize($userinfo) + ), + array( 'auth0_id' => $userinfo->user_id ), + array( '%s' ), + array( '%s' ) + ); + } + + public static function delete_user ($user_id) { + global $wpdb; + $wpdb->delete( $wpdb->auth0_user, array( 'wp_id' => $user_id), array( '%d' ) ); + } + + private static function dieWithVerifyEmail($userinfo, $data) { + + ob_start(); + $domain = WP_Auth0_Options::get( 'domain' ); + $token = $data->id_token; + $email = $userinfo->email; + include WPA0_PLUGIN_DIR . 'templates/verify-email.php'; + + $html = ob_get_clean(); + + wp_die($html); + + } + private static function login_user( $userinfo, $data ){ + // If the userinfo has an unverified email, and in the options we require a verified email + // notify the user he cant login until he does so. + if (!$userinfo->email_verified && WP_Auth0_Options::get( 'requires_verified_email' )) { + self::dieWithVerifyEmail($userinfo, $data); + } + + // See if there is a user in the auth0_user table with the user info client id + $user = self::findAuth0User($userinfo->user_id); + if (!is_null($user)) { + // User exists! Log in + self::updateAuth0Object($userinfo); + wp_set_auth_cookie( $user->ID ); + return true; + } else { + // If the user doesn't exist we need to either create a new one, or asign him to an existing one + $isDatabaseUser = false; + foreach ($userinfo->identities as $identity) { + if ($identity->connection == "Username-Password-Authentication") { + $isDatabaseUser = true; + } + } + $joinUser = null; + // If the user has a verified email or is a database user try to see if there is + // a user to join with. The isDatabase is because we don't want to allow database + // user creation if there is an existing one with no verified email + if ($userinfo->email_verified || $isDatabaseUser) { + $joinUser = get_user_by( 'email', $userinfo->email ); + } + + if (!is_null($joinUser) && $joinUser instanceof WP_User) { + // If we are here, we have a potential join user + // Don't allow creation or assignation of user if the email is not verified, that would + // be hijacking + if (!$userinfo->email_verified) { + self::dieWithVerifyEmail($userinfo, $data); + } + $user_id = $joinUser->ID; + } else { + // If we are here, we need to create the user + $user_id = (int)WP_Auth0_Users::create_user($userinfo); + + // Check if user was created + + if($user_id == -2){ + $msg = __('Error: Could not create user. The registration process were rejected. Please verify that your account is whitelisted for this system.', WPA0_LANG); + $msg .= '

'; + $msg .= '' . __('← Go back', WPA0_LANG) . ''; + + wp_die($msg); + }elseif ($user_id <0){ + $msg = __('Error: Could not create user.', WPA0_LANG); + $msg .= '

'; + $msg .= '' . __('← Go back', WPA0_LANG) . ''; + wp_die($msg); + } + } + // If we are here we should have a valid $user_id with a new user or an existing one + // log him in, and update the auth0_user table + self::insertAuth0User($userinfo, $user_id); + wp_set_auth_cookie( $user_id ); + return true; + } + + } + + public static function wp_init(){ + self::setup_rewrites(); + // Initialize session + if(!session_id()) { + session_start(); + } + } + public static function end_session() { + session_destroy (); + } + + private static function setup_rewrites(){ + add_rewrite_tag('%auth0%', '([^&]+)'); + add_rewrite_tag('%code%', '([^&]+)'); + add_rewrite_tag('%state%', '([^&]+)'); + add_rewrite_tag('%auth0_error%', '([^&]+)'); + add_rewrite_rule('^auth0', 'index.php?auth0=1', 'top'); + } + + public static function install(){ + self::install_db(); + self::setup_rewrites(); + + flush_rewrite_rules(); + } + + public static function uninstall(){ + flush_rewrite_rules(); + } + + private static function install_db(){ + global $wpdb; + + self::initialize_wpdb_tables(); + + $sql = array(); + + $sql[] = "CREATE TABLE ".$wpdb->auth0_log." ( + id INT(11) AUTO_INCREMENT NOT NULL, + event VARCHAR(100) NOT NULL, + level VARCHAR(100) NOT NULL DEFAULT 'notice', + description TEXT, + details LONGTEXT, + logtime INT(11) NOT NULL, + PRIMARY KEY (id) + );"; + + $sql[] = "CREATE TABLE ".$wpdb->auth0_user." ( + auth0_id VARCHAR(100) NOT NULL, + wp_id INT(11) NOT NULL, + auth0_obj TEXT, + PRIMARY KEY (auth0_id) + );"; + + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + + foreach($sql as $s) { + dbDelta($s); + } + update_option( "auth0_db_version", AUTH0_DB_VERSION ); + + } + + public static function check_update() { + if ( get_site_option( 'auth0_db_version' ) !== AUTH0_DB_VERSION) { + self::install_db(); + } + } + + public static function initialize_wpdb_tables(){ + global $wpdb; + + $wpdb->auth0_log = $wpdb->prefix."auth0_log"; + $wpdb->auth0_user = $wpdb->prefix."auth0_user"; + } + + private static function autoloader($class){ + $path = WPA0_PLUGIN_DIR; + $paths = array(); + $exts = array('.php', '.class.php'); + + $paths[] = $path; + $paths[] = $path.'lib/'; + + foreach($paths as $p) + foreach($exts as $ext){ + if(file_exists($p.$class.$ext)){ + require_once($p.$class.$ext); + return true; + } + } + + return false; + } +} + + +if ( !function_exists('get_currentauth0userinfo') ) : + +function get_currentauth0userinfo() { + global $current_user; + global $currentauth0_user; + global $wpdb; + + get_currentuserinfo(); + if ($current_user instanceof WP_User && $current_user->ID > 0 ) { + $sql = 'SELECT auth0_obj + FROM ' . $wpdb->auth0_user .' + WHERE wp_id = %d'; + $result = $wpdb->get_row($wpdb->prepare($sql, $current_user->ID)); + if (is_null($result) || $result instanceof WP_Error ) { + return null; + } + $currentauth0_user = unserialize($result->auth0_obj); + } } +endif; WP_Auth0::init(); \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index e784bcf2c..415e06e49 100755 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -1,31 +1,52 @@ jQuery(document).ready(function($) { - //uploading files variable - var media_frame; - $(document).on('click', '#wpa0_choose_icon', function(event) { - event.preventDefault(); - //If the frame already exists, reopen it - if (typeof(media_frame)!=="undefined") + //uploading files variable + var media_frame; + $(document).on('click', '#wpa0_choose_icon', function(event) { + event.preventDefault(); + //If the frame already exists, reopen it + if (typeof(media_frame)!=="undefined") media_frame.close(); - //Create WP media frame. - media_frame = wp.media.frames.customHeader = wp.media({ - title: wpa0.media_title, - library: { - type: 'image' - }, - button: { - text: wpa0.media_button - }, - multiple: false - }); - - // Set the frame callback - media_frame.on('select', function() { - var attachment = media_frame.state().get('selection').first().toJSON(); - $('#wpa0_icon_url').val(attachment.url); - }); - - //Open modal - media_frame.open(); - }); + //Create WP media frame. + media_frame = wp.media.frames.customHeader = wp.media({ + title: wpa0.media_title, + library: { + type: 'image' + }, + button: { + text: wpa0.media_button + }, + multiple: false + }); + + // Set the frame callback + media_frame.on('select', function() { + var attachment = media_frame.state().get('selection').first().toJSON(); + $('#wpa0_icon_url').val(attachment.url); + }); + + //Open modal + media_frame.open(); + }); + + function configureHideShowAutoLogin() { + // Hide/Show login method depending on auto login + var $loginMethodField = $("#wpa0_auto_login_method").closest("tr"); + var $autoLoginCheckbox = $("#wpa0_auto_login"); + if (!$autoLoginCheckbox.prop("checked")) { + $loginMethodField.hide(); + } + + $autoLoginCheckbox.change(function() { + if (!$autoLoginCheckbox.prop("checked")) { + $loginMethodField.hide(); + } else { + $loginMethodField.show(); + } + + }); + } + + configureHideShowAutoLogin(); + }); \ No newline at end of file diff --git a/assets/js/wp-login.js b/assets/js/wp-login.js deleted file mode 100755 index eb1863901..000000000 --- a/assets/js/wp-login.js +++ /dev/null @@ -1,24 +0,0 @@ -var a0_wp_login = (function($){ - - var login_click = function(){ - $('#wp-login-form-wrapper').fadeIn(); - return false; - } - - var add_login_method_btn = function(){ - var btn = $('').addClass('a0-zocial a0-block a0-wp-login').text(wpa0.wp_btn); - $(btn).click(login_click); - $('#a0-widget .a0-iconlist').append(btn); - }; - - return { - initialize: function(){ - add_login_method_btn(); - setTimeout(function(){ - $('#a0-widget #a0-onestep').attr('style', ''); - $('#a0-widget form, #a0-widget .a0-iconlist').attr('style', 'margin-top: 0!important;'); - }, 100); - - } - }; -})(jQuery); \ No newline at end of file diff --git a/lib/WP_Auth0_Admin.php b/lib/WP_Auth0_Admin.php old mode 100755 new mode 100644 index 52f6298d0..0d6074ae3 --- a/lib/WP_Auth0_Admin.php +++ b/lib/WP_Auth0_Admin.php @@ -1,267 +1,309 @@ __('Choose your icon', WPA0_LANG), - 'media_button' => __('Choose icon', WPA0_LANG) - )); - } - - public static function init_admin(){ - add_settings_section( - 'wp_auth0_settings_section', - __('Auth0 Settings', WPA0_LANG), - array(__CLASS__, 'render_description'), - WP_Auth0_Options::OPTIONS_NAME - ); - - add_settings_field( - 'wpa0_active', - __('Activate Auth0', WPA0_LANG), - array(__CLASS__, 'render_activate'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_active') - ); - - add_settings_field( - 'wpa0_auto_login', - __('Auto Login (no widget)', WPA0_LANG), - array(__CLASS__, 'render_auto_login'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_auto_login') - ); - - $auto_login = absint(WP_Auth0_Options::get( 'auto_login' )) == 1; - if($auto_login) - add_settings_field( - 'wpa0_auto_login_method', - __('Auto Login Method', WPA0_LANG), - array(__CLASS__, 'render_auto_login_method'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_auto_login_method') - ); - + public static function init(){ + add_action( 'admin_menu', array(__CLASS__, 'init_menu') ); + add_action( 'admin_init', array(__CLASS__, 'init_admin')); + add_action( 'admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue')); + } + + public static function admin_enqueue(){ + if(!isset($_REQUEST['page']) || $_REQUEST['page'] != 'wpa0') + return; + + wp_enqueue_media(); + wp_enqueue_script( 'wpa0_admin', WPA0_PLUGIN_URL . 'assets/js/admin.js', array('jquery')); + wp_enqueue_style('media'); + + wp_localize_script( 'wpa0_admin', 'wpa0', array( + 'media_title' => __('Choose your icon', WPA0_LANG), + 'media_button' => __('Choose icon', WPA0_LANG) + )); + } + + public static function init_admin(){ + add_settings_section( + 'wp_auth0_basic_settings_section', + __('Basic', WPA0_LANG), + array(__CLASS__, 'render_basic_description'), + WP_Auth0_Options::OPTIONS_NAME + ); + + + + add_settings_field( + 'wpa0_active', + __('Activate Auth0', WPA0_LANG), + array(__CLASS__, 'render_activate'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_basic_settings_section', + array('label_for' => 'wpa0_active') + ); + + add_settings_field( + 'wpa0_domain', + __('Domain', WPA0_LANG), + array(__CLASS__, 'render_domain'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_basic_settings_section', + array('label_for' => 'wpa0_domain') + ); + + add_settings_field( + 'wpa0_client_id', + __('Client ID', WPA0_LANG), + array(__CLASS__, 'render_client_id'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_basic_settings_section', + array('label_for' => 'wpa0_client_id') + ); + + add_settings_field( + 'wpa0_client_secret', + __('Client Secret', WPA0_LANG), + array(__CLASS__, 'render_client_secret'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_basic_settings_section', + array('label_for' => 'wpa0_client_secret') + ); + + + + add_settings_section( + 'wp_auth0_advanced_settings_section', + __('Advanced', WPA0_LANG), + array(__CLASS__, 'render_advanced_description'), + WP_Auth0_Options::OPTIONS_NAME + ); + + add_settings_field( + 'wpa0_form_title', + __('Form Title', WPA0_LANG), + array(__CLASS__, 'render_form_title'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_form_title') + ); + + add_settings_field( + 'wpa0_verified_email', + __('Requires verified email', WPA0_LANG), + array(__CLASS__, 'render_verified_email'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_verified_email') + ); + add_settings_field( - 'wpa0_redirect_referer', - __('Enable on /sso/ Redirect', WPA0_LANG), - array(__CLASS__, 'render_redirect_referer'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_redirect_referer') - ); - - add_settings_field( - 'wpa0_ip_range_check', - __('Enable on IP Ranges', WPA0_LANG), - array(__CLASS__, 'render_ip_range_check'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_ip_range_check') - ); - - $use_ip_ranges = absint(WP_Auth0_Options::get( 'ip_range_check' )) == 1; - if($use_ip_ranges) - add_settings_field( - 'wpa0_ip_ranges', - __('IP Ranges', WPA0_LANG), - array(__CLASS__, 'render_ip_ranges'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_ip_ranges') - ); + 'wpa0_allow_signup', + __('Allow signup', WPA0_LANG), + array(__CLASS__, 'render_allow_signup'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_allow_signup') + ); + add_settings_field( - 'wpa0_wp_login_form', - __('Show WP Login Method', WPA0_LANG), - array(__CLASS__, 'render_wp_login_form'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_wp_login_form') - ); + 'wpa0_auto_login', + __('Auto Login (no widget)', WPA0_LANG), + array(__CLASS__, 'render_auto_login'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_auto_login') + ); + add_settings_field( - 'wpa0_wp_login_btn_text', - __('WP Login Button Text', WPA0_LANG), - array(__CLASS__, 'render_wp_login_btn_text'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_wp_login_btn_text') - ); - - add_settings_field( - 'wpa0_client_id', - __('Client ID', WPA0_LANG), - array(__CLASS__, 'render_client_id'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_client_id') - ); - add_settings_field( - 'wpa0_client_secret', - __('Client Secret', WPA0_LANG), - array(__CLASS__, 'render_client_secret'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_client_secret') - ); - add_settings_field( - 'wpa0_endpoint', - __('Auth0 OAuth Endpoint', WPA0_LANG), - array(__CLASS__, 'render_endpoint'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_endpoint') - ); - add_settings_field( - 'wpa0_form_title', - __('Form Title', WPA0_LANG), - array(__CLASS__, 'render_form_title'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_form_title') - ); - add_settings_field( - 'wpa0_form_desc', - __('Form Description', WPA0_LANG), - array(__CLASS__, 'render_form_desc'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_form_desc') - ); - add_settings_field( - 'wpa0_show_icon', - __('Show Icon', WPA0_LANG), - array(__CLASS__, 'render_show_icon'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_show_icon') - ); - add_settings_field( - 'wpa0_icon_url', - __('Icon URL', WPA0_LANG), - array(__CLASS__, 'render_icon_url'), - WP_Auth0_Options::OPTIONS_NAME, - 'wp_auth0_settings_section', - array('label_for' => 'wpa0_icon_url') - ); - - - register_setting(WP_Auth0_Options::OPTIONS_NAME, WP_Auth0_Options::OPTIONS_NAME, array(__CLASS__, 'input_validator')); - } - - public static function render_client_id(){ - $v = WP_Auth0_Options::get( 'client_id' ); - echo ''; - } - public static function render_client_secret(){ - $v = WP_Auth0_Options::get( 'client_secret' ); - echo ''; - } - public static function render_endpoint(){ - $v = WP_Auth0_Options::get( 'endpoint' ); - echo ''; - echo '
' . __('This should only contain the HTTP protocol and domain! Example: https://1337.auth0.com/', WPA0_LANG) . ''; - } - public static function render_form_title(){ - $v = WP_Auth0_Options::get( 'form_title' ); - echo ''; - } - public static function render_form_desc(){ - $v = WP_Auth0_Options::get( 'form_desc' ); - echo ''; - } - public static function render_wp_login_btn_text(){ - $v = WP_Auth0_Options::get( 'wp_login_btn_text' ); - echo ''; - } - - public static function render_activate(){ - $v = absint(WP_Auth0_Options::get( 'active' )); - echo ''; - } - public static function render_auto_login(){ - $v = absint(WP_Auth0_Options::get( 'auto_login' )); - echo ''; - } - public static function render_auto_login_method(){ - $v = WP_Auth0_Options::get( 'auto_login_method' ); - echo ''; - echo '
' . __('To find the method name, log into Auth0 Dashboard, and navigate to: Connection -> [Connection Type] (eg. Social or Enterprise). Click the "down arrow" to expand the wanted method, and use the value in the "Name"-field. Example: google-oauth2', WPA0_LANG) . ''; - } - public static function render_redirect_referer(){ - $v = absint(WP_Auth0_Options::get( 'redirect_referer' )); - echo ''; - } - public static function render_ip_range_check(){ - $v = absint(WP_Auth0_Options::get( 'ip_range_check' )); - echo ''; - } - public static function render_ip_ranges(){ - $v = WP_Auth0_Options::get( 'ip_ranges' ); - echo ''; - echo '
' . __('Only one range per line! Range format should be as: xx.xx.xx.xx - yy.yy.yy.yy (spaces will be trimmed)', WPA0_LANG) . ''; - } - public static function render_wp_login_form(){ - $v = absint(WP_Auth0_Options::get( 'wp_login_form' )); - echo ''; - } - public static function render_show_icon(){ - $v = absint(WP_Auth0_Options::get( 'show_icon' )); - echo ''; - } - - public static function render_icon_url(){ - $v = WP_Auth0_Options::get( 'icon_url' ); - echo ''; - echo ' ' . __( 'Choose Icon', WPA0_LANG ) . ''; - echo '
' . __('The icon should be 32x32 pixels!', WPA0_LANG) . ''; - } - - public static function render_description(){ - - } - - public static function init_menu(){ - add_options_page( __('Auth0 Settings', WPA0_LANG), __('Auth0 Settings', WPA0_LANG), 'manage_options', 'wpa0', array(__CLASS__, 'render_settings_page') ); - } - - public static function render_settings_page(){ - include WPA0_PLUGIN_DIR . 'templates/settings.php'; - } - - public static function input_validator( $input ){ - $input['client_id'] = sanitize_text_field( $input['client_id'] ); - $input['form_title'] = sanitize_text_field( $input['form_title'] ); - $input['icon_url'] = esc_url( $input['icon_url'], array( - 'http', - 'https' - )); - if(empty($input['icon_url'])) - $input['show_icon'] = 0; - else - $input['show_icon'] = (isset($input['show_icon']) ? 1 : 0); - $input['active'] = (isset($input['active']) ? 1 : 0); - - - $input['endpoint'] = esc_url( $input['endpoint'], array('https', 'http') ); - if(!empty($input['endpoint'])) - $input['endpoint'] = trailingslashit($input['endpoint']); - - return $input; - } + 'wpa0_auto_login_method', + __('Auto Login Method', WPA0_LANG), + array(__CLASS__, 'render_auto_login_method'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_auto_login_method') + ); + + add_settings_field( + 'wpa0_ip_range_check', + __('Enable on IP Ranges', WPA0_LANG), + array(__CLASS__, 'render_ip_range_check'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_ip_range_check') + ); + + $use_ip_ranges = absint(WP_Auth0_Options::get( 'ip_range_check' )) == 1; + if($use_ip_ranges) + add_settings_field( + 'wpa0_ip_ranges', + __('IP Ranges', WPA0_LANG), + array(__CLASS__, 'render_ip_ranges'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_ip_ranges') + ); + + add_settings_field( + 'wpa0_show_icon', + __('Show Icon', WPA0_LANG), + array(__CLASS__, 'render_show_icon'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_show_icon') + ); + add_settings_field( + 'wpa0_icon_url', + __('Icon URL', WPA0_LANG), + array(__CLASS__, 'render_icon_url'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_icon_url') + ); + + add_settings_field( + 'wpa0_cdn_url', + __('Widget URL', WPA0_LANG), + array(__CLASS__, 'render_cdn_url'), + WP_Auth0_Options::OPTIONS_NAME, + 'wp_auth0_advanced_settings_section', + array('label_for' => 'wpa0_cdn_url') + ); + + register_setting(WP_Auth0_Options::OPTIONS_NAME, WP_Auth0_Options::OPTIONS_NAME, array(__CLASS__, 'input_validator')); + } + + public static function render_client_id(){ + $v = WP_Auth0_Options::get( 'client_id' ); + echo ''; + echo '
' . __('Application id, copy from the auth0 dashboard', WPA0_LANG) . ''; + } + public static function render_client_secret(){ + $v = WP_Auth0_Options::get( 'client_secret' ); + echo ''; + echo '
' . __('Application secret, copy from the auth0 dashboard', WPA0_LANG) . ''; + } + public static function render_domain(){ + $v = WP_Auth0_Options::get( 'domain' ); + echo ''; + echo '
' . __('Your Auth0 domain, you can see it in the auth0 dashboard', WPA0_LANG) . ''; + } + + public static function render_form_title(){ + $v = WP_Auth0_Options::get( 'form_title' ); + echo ''; + echo '
' . __('This is the title for the login widget', WPA0_LANG) . ''; + + } + + public static function render_activate(){ + $v = absint(WP_Auth0_Options::get( 'active' )); + echo ''; + } + public static function render_auto_login(){ + $v = absint(WP_Auth0_Options::get( 'auto_login' )); + echo ''; + echo '
' . __('Mark this to avoid the login page (you will have to select a single login provider)', WPA0_LANG) . ''; + } + public static function render_auto_login_method(){ + $v = WP_Auth0_Options::get( 'auto_login_method' ); + echo ''; + echo '
' . __('To find the method name, log into Auth0 Dashboard, and navigate to: Connection -> [Connection Type] (eg. Social or Enterprise). Click the "down arrow" to expand the wanted method, and use the value in the "Name"-field. Example: google-oauth2', WPA0_LANG) . ''; + } + public static function render_ip_range_check(){ + $v = absint(WP_Auth0_Options::get( 'ip_range_check' )); + echo ''; + } + public static function render_ip_ranges(){ + $v = WP_Auth0_Options::get( 'ip_ranges' ); + echo ''; + echo '
' . __('Only one range per line! Range format should be as: xx.xx.xx.xx - yy.yy.yy.yy (spaces will be trimmed)', WPA0_LANG) . ''; + } + public static function render_show_icon(){ + $v = absint(WP_Auth0_Options::get( 'show_icon' )); + echo ''; + } + + public static function render_icon_url(){ + $v = WP_Auth0_Options::get( 'icon_url' ); + echo ''; + echo ' ' . __( 'Choose Icon', WPA0_LANG ) . ''; + echo '
' . __('The icon should be 32x32 pixels!', WPA0_LANG) . ''; + } + + public static function render_cdn_url () { + $v = WP_Auth0_Options::get( 'cdn_url' ); + echo ''; + echo '
' . __('Point this to the latest widget available in the CDN', WPA0_LANG) . ''; + } + + public static function render_verified_email () { + $v = absint(WP_Auth0_Options::get( 'requires_verified_email' )); + echo ''; + echo '
' . __('Mark this if you require the user to have a verified email to login', WPA0_LANG) . ''; + } + + public static function render_allow_signup () { + $v = absint(WP_Auth0_Options::get( 'allow_signup' )); + echo ''; + echo '
' . __('If you have database connection you can allow users to signup in the widget', WPA0_LANG) . ''; + } + + + public static function render_basic_description(){ + + } + + public static function render_advanced_description(){ + + } + + + public static function init_menu(){ + add_options_page( __('Auth0 Settings', WPA0_LANG), __('Auth0 Settings', WPA0_LANG), 'manage_options', 'wpa0', array(__CLASS__, 'render_settings_page') ); + } + + public static function render_settings_page(){ + include WPA0_PLUGIN_DIR . 'templates/settings.php'; + } + + public static function input_validator( $input ){ + $input['client_id'] = sanitize_text_field( $input['client_id'] ); + $input['form_title'] = sanitize_text_field( $input['form_title'] ); + $input['icon_url'] = esc_url( $input['icon_url'], array( + 'http', + 'https' + )); + if(empty($input['icon_url'])) + $input['show_icon'] = 0; + else + $input['show_icon'] = (isset($input['show_icon']) ? 1 : 0); + $input['active'] = (isset($input['active']) ? 1 : 0); + $input['requires_verified_email'] = (isset($input['requires_verified_email']) ? 1 : 0); + $input['allow_signup'] = (isset($input['allow_signup']) ? 1 : 0); + + $error = ""; + if (empty($input["domain"]) ) { + $error = __("You need to specify domain", WPA0_LANG); + } + if (empty($input["client_id"])) { + $error = __("You need to specify a client id", WPA0_LANG); + } + if (empty($input["client_secret"])) { + $error = __("You need to specify a client secret", WPA0_LANG); + } + + if ($error != "") { + add_settings_error( + WP_Auth0_Options::OPTIONS_NAME, + WP_Auth0_Options::OPTIONS_NAME, + $error, + 'error' + ); + + } + + // $input['endpoint'] = esc_url( $input['endpoint'], array('https', 'http') ); + // if(!empty($input['endpoint'])) + // $input['endpoint'] = trailingslashit($input['endpoint']); + + return $input; + } } \ No newline at end of file diff --git a/lib/WP_Auth0_Ip_Check.php b/lib/WP_Auth0_Ip_Check.php old mode 100755 new mode 100644 diff --git a/lib/WP_Auth0_Options.php b/lib/WP_Auth0_Options.php old mode 100755 new mode 100644 index c5ac27e19..d8aa462da --- a/lib/WP_Auth0_Options.php +++ b/lib/WP_Auth0_Options.php @@ -1,55 +1,54 @@ 0, - 'auto_login' => 0, - 'auto_login_method' => '', - 'client_id' => '', - 'client_secret' => '', - 'endpoint' => '', - 'form_title' => '', - 'form_desc' => '', - 'show_icon' => 0, - 'icon_url' => '', - 'redirect_referer' => 0, - 'ip_range_check' => 0, - 'ip_ranges' => '', - 'wp_login_form' => 0, - 'wp_login_btn_text' => __('Regular Login', WPA0_LANG) - ); - } + const OPTIONS_NAME = 'wp_auth0_settings'; + private static $_opt = null; + + private static function get_options(){ + if(empty(self::$_opt)){ + $options = get_option( self::OPTIONS_NAME, array()); + if(!is_array($options)) + $options = self::defaults(); + + $options = array_merge( self::defaults(), $options ); + + self::$_opt = $options; + } + return self::$_opt; + } + + public static function get( $key, $default = null ){ + $options = self::get_options(); + + if(!isset($options[$key])) + return apply_filters( 'wp_auth0_get_option', $default, $key ); + return apply_filters( 'wp_auth0_get_option', $options[$key], $key ); + } + + public static function set( $key, $value ){ + $options = self::get_options(); + + $options[$key] = $value; + + update_option( self::OPTIONS_NAME, $options ); + } + + private static function defaults(){ + return array( + 'active' => 0, + 'auto_login' => 0, + 'auto_login_method' => '', + 'client_id' => '', + 'client_secret' => '', + 'domain' => '', + 'form_title' => '', + 'show_icon' => 0, + 'icon_url' => '', + 'ip_range_check' => 0, + 'ip_ranges' => '', + 'cdn_url' => 'http://cdn.auth0.com/w2/auth0-widget-4.0.0.min.js', + 'requires_verified_email' => true, + 'allow_signup' => true + ); + } } \ No newline at end of file diff --git a/lib/WP_Auth0_Referer_Check.php b/lib/WP_Auth0_Referer_Check.php old mode 100755 new mode 100644 diff --git a/lib/WP_Auth0_Users.php b/lib/WP_Auth0_Users.php old mode 100755 new mode 100644 index b06f517b0..3dceef099 --- a/lib/WP_Auth0_Users.php +++ b/lib/WP_Auth0_Users.php @@ -2,17 +2,20 @@ class WP_Auth0_Users { public static function create_user( $userinfo ){ $email = $userinfo->email; - + if (empty($email)) { + $email = "change_this_email@" . uniqid() .".com"; + } + $valid_user = apply_filters( 'wpa0_should_create_user', true, $userinfo ); if(!$valid_user) return -2; - + // Generate a random password $password = wp_generate_password(); - + // Split the name into first- and lastname $names = explode(" ", $userinfo->name); - + $firstname = ""; $lastname = ""; if(count($names) == 1) @@ -24,25 +27,29 @@ public static function create_user( $userinfo ){ $lastname = array_pop($names); $firstname = implode(" ", $names); } - + + $username = $userinfo->nickname; + if (empty($username)) { + $username = $email; + } // Create the user data array for updating first- and lastname $user_data = array( 'user_email' => $email, - 'user_login' => $email, + 'user_login' => $username, 'user_pass' => $password, 'first_name' => $firstname, 'last_name' => $lastname, - 'display_name' => $email + 'display_name' => $username ); - + // Update the user $user_id = wp_insert_user( $user_data ); - + if(!is_numeric($user_id)) return -1; - + do_action( 'wpa0_user_created', $user_id, $email, $password, $firstname, $lastname ); - + // Return the user ID return $user_id; } diff --git a/lib/WP_Auth0_Utils.php b/lib/WP_Auth0_Utils.php old mode 100755 new mode 100644 diff --git a/readme.txt b/readme.txt new file mode 100644 index 000000000..ee308f51f --- /dev/null +++ b/readme.txt @@ -0,0 +1,54 @@ +=== Wordpress Auth0 Integration === +Tags: Login, oauth, authentication, facebook, google +Tested up to: 3.9 +Requires at least: 3.8 +License: MIT +License URI: https://github.com/auth0/wp-auth0/blob/master/LICENSE.md +Stable tag: trunk +Contributors: 1337 ApS, hrajchert + +Provides Single Sing On to your wordpress site. You can use different auth providers as facebook, google, twitter, active directory, etc + +== Description == +This plugins allows you to extend the default user implementation and use the service provided by www.auth0.com + +You can make your users to login with facebook, google, linkedin, etc by a click of a button + + +== Installation == + +Before you start, make sure the admin user has a valid email that you own, read the Technical Notes for more information. + +1. Install from the wordpress store or upload the entire `wp-auth0` folder to the `/wp-content/plugins/` directory. +1. Activate the plugin through the 'Plugins' menu in WordPress. +1. In `settings` - `Auth0 Settings` edit the *Domain*, *Client ID* and *Client Secret* from your auth0 dashboard +1. Go to your auth0 dashboard, edit your application and add this to the available callbacks http:///index.php?auth0=1 + + +== Technical Notes == + +By using this plugin you are delegating the site authentication to Auth0, if a user is valid for Auth0 it will be valid for your site. + +When you install this plugin you have at least one existing user in the database, the admin user, and if the site ain't new, you probably have more. We want you to conserve those users! you want to be able to login as admin again, right ;)? + +Auth0 allows you to have different ways to authenticate, you can have social providers like facebook, twitter, google+, etc or you can have database users (just like wordpress!). All those providers MAY have an email and that email can be verified or not. We use that email (only if its verified) to join a previous existing user with the one from Auth0. + +There are two main scenarios that you need to keep in mind: + * The user logs in via database + * The user logs in via a social provider + +For now, if you add a database connection, you will start with no users (we plan to add an import feature later). But you still can claim your old user. To do so, you will need to signup using the login widget and then validate your account by clicking on the verification link in the email you'll receive. For database connections, if there was a previous user with that email you will require to verificate the address. + +If the user logs in via a social provider, it may have a verified email. If it does, and its the first time the user logs in using that social provider, the plugin will asociate that social account with the previous existing user (that has the same email) + +For both scenarios you may configure in the admin to require that the user has a verified email or not. + +In any case, you may end up with a situation where a user has two accounts. Remember that wordpress allows you to do something similar to a user merge. To do so, you need to delete an account and attribute its contents to the user you want to merge with. You can go to Users, select the account you want to delete, and in the confirmation dialog you can select another user to attribute content. + +Wordpress defines a function called `get_currentuserinfo` to populate the global variable `current_user` with the logged in WP_User. Similary we define `get_currentauth0userinfo` that populates `current_user` and `currentauth0_user` with the information of the [Normalized profile](https://docs.auth0.com/user-profile) + +You can style the login form by adding a filter like this + + add_filter( 'auth0_login_css', function() { + return "form a.a0-btn-small { background-color: red }"; + } ); diff --git a/templates/error-msg.php b/templates/error-msg.php old mode 100755 new mode 100644 diff --git a/templates/login-auto.php b/templates/login-auto.php deleted file mode 100755 index 4f0bef920..000000000 --- a/templates/login-auto.php +++ /dev/null @@ -1,21 +0,0 @@ - -
- - \ No newline at end of file diff --git a/templates/login-form.php b/templates/login-form.php old mode 100755 new mode 100644 index ba11b13ae..2f7533c9d --- a/templates/login-form.php +++ b/templates/login-form.php @@ -1,59 +1,82 @@ $interim_login, "uuid" =>uniqid()); +$state = $_SESSION['auth0_state'] = json_encode($stateObj); if(empty($client_id) || empty($domain)): ?> -

+

- + + + + + + + + + + > + + + You are connected + + diff --git a/templates/settings.php b/templates/settings.php old mode 100755 new mode 100644 diff --git a/templates/verify-email.php b/templates/verify-email.php new file mode 100644 index 000000000..8f9ae0d27 --- /dev/null +++ b/templates/verify-email.php @@ -0,0 +1,28 @@ + + +

+ + diff --git a/templates/wp-login-form.php b/templates/wp-login-form.php old mode 100755 new mode 100644