-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve WP_Auth0_Options #418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,24 @@ | |
|
||
class WP_Auth0_Options extends WP_Auth0_Options_Generic { | ||
|
||
protected static $instance = null; | ||
protected static $_instance = null; | ||
protected $_options_name = 'wp_auth0_settings'; | ||
|
||
public static function Instance() { | ||
if ( self::$instance === null ) { | ||
self::$instance = new WP_Auth0_Options; | ||
if ( null=== self::$_instance ) { | ||
self::$_instance = new WP_Auth0_Options; | ||
} | ||
return self::$instance; | ||
return self::$_instance; | ||
} | ||
|
||
protected $options_name = 'wp_auth0_settings'; | ||
|
||
public function is_wp_registration_enabled() { | ||
if ( is_multisite() ) { | ||
return users_can_register_signup_filter(); | ||
} | ||
return get_site_option( 'users_can_register', 0 ) == 1; | ||
} | ||
|
||
// TODO: Deprecate, not used | ||
public function get_enabled_connections() { | ||
return array( 'facebook', 'twitter', 'google-oauth2' ); | ||
} | ||
|
@@ -43,9 +44,13 @@ public function get_default($key) { | |
return $defaults[$key]; | ||
} | ||
|
||
/** | ||
* Get the stored token signing algorithm | ||
* | ||
* @return string | ||
*/ | ||
public function get_client_signing_algorithm() { | ||
$client_signing_algorithm = $this->get('client_signing_algorithm', WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG); | ||
return $client_signing_algorithm; | ||
return $this->get( 'client_signing_algorithm', WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG ); | ||
} | ||
|
||
/** | ||
|
@@ -129,92 +134,124 @@ public function get_logout_url() { | |
return add_query_arg( 'action', 'logout', site_url( 'wp-login.php', 'login' ) ); | ||
} | ||
|
||
/** | ||
* Get lock_connections as an array of strings | ||
* | ||
* @return array | ||
*/ | ||
public function get_lock_connections() { | ||
$connections = $this->get( 'lock_connections' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field in on the settings page is just a text field so comma-separated (or line break or pipe or whatever) is about the best we can do without a UI to force multiple, separate values. This is basically to handle user input |
||
$connections = empty( $connections ) ? array() : explode( ',', $connections ); | ||
return array_map( 'trim', $connections ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the trim needed because it's a user input or because you don't trust the source? (i don't know where it comes from) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User input |
||
} | ||
|
||
/** | ||
* Add a new connection to the lock_connections setting | ||
* | ||
* @param string $connection - connection name to add | ||
*/ | ||
public function add_lock_connection( $connection ) { | ||
$connections = $this->get_lock_connections(); | ||
|
||
// Add if it doesn't exist already | ||
if ( ! array_key_exists( $connection, $connections ) ) { | ||
$connections[] = $connection; | ||
$connections = implode( ',', $connections ); | ||
$this->set( 'lock_connections', $connections ); | ||
} | ||
} | ||
|
||
/** | ||
* Default settings when plugin is installed or reset | ||
* | ||
* @return array | ||
*/ | ||
protected function defaults() { | ||
return array( | ||
|
||
// System | ||
'version' => 1, | ||
'metrics' => 1, | ||
'last_step' => 1, | ||
'auto_login' => 0, | ||
'auto_login_method' => '', | ||
'migration_token_id' => null, | ||
'use_lock_10' => true, | ||
'jwt_auth_integration' => false, | ||
'amplificator_title' => '', | ||
'amplificator_subtitle' => '', | ||
'connections' => array(), | ||
'auth0js-cdn' => 'https://cdn.auth0.com/js/auth0/9.1/auth0.min.js', | ||
|
||
// Basic | ||
'domain' => '', | ||
'client_id' => '', | ||
'client_secret' => '', | ||
'client_secret_b64_encoded' => null, | ||
'client_signing_algorithm' => WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG, | ||
'cache_expiration' => 1440, | ||
'client_secret_b64_encoded' => null, | ||
'domain' => '', | ||
'form_title' => '', | ||
'icon_url' => '', | ||
'ip_range_check' => 0, | ||
'ip_ranges' => '', | ||
'lock_connections' => '', | ||
'passwordless_enabled' => false, | ||
'passwordless_method' => 'magiclink', | ||
'passwordless_cdn_url' => '//cdn.auth0.com/js/lock-passwordless-2.2.min.js', | ||
'use_lock_10' => true, | ||
'cdn_url' => '//cdn.auth0.com/js/lock/11.1/lock.min.js', | ||
'cdn_url_legacy' => '//cdn.auth0.com/js/lock-9.2.min.js', | ||
'requires_verified_email' => true, | ||
'auth0_app_token' => null, | ||
'wordpress_login_enabled' => true, | ||
'primary_color' => '', | ||
|
||
'language' => '', | ||
'language_dictionary' => '', | ||
|
||
'custom_signup_fields' => '', | ||
|
||
'social_big_buttons' => false, | ||
'username_style' => '', | ||
'extra_conf' => '', | ||
'custom_css' => '', | ||
'custom_js' => '', | ||
'auth0_implicit_workflow' => false, | ||
// Features | ||
'password_policy' => 'fair', | ||
'sso' => false, | ||
'singlelogout' => false, | ||
'gravatar' => true, | ||
'jwt_auth_integration' => false, | ||
'auth0_app_token' => null, | ||
'api_audience' => null, | ||
'mfa' => null, | ||
'fullcontact' => null, | ||
'fullcontact_rule' => null, | ||
'fullcontact_apikey' => null, | ||
'geo_rule' => null, | ||
'income_rule' => null, | ||
'link_auth0_users' => null, | ||
'remember_users_session' => false, | ||
|
||
'override_wp_avatars' => true, | ||
|
||
// Appearance | ||
'icon_url' => '', | ||
'form_title' => '', | ||
'social_big_buttons' => false, | ||
'gravatar' => true, | ||
'custom_css' => '', | ||
'custom_js' => '', | ||
'username_style' => '', | ||
'primary_color' => '', | ||
'language' => '', | ||
'language_dictionary' => '', | ||
|
||
// Advanced | ||
'requires_verified_email' => true, | ||
'remember_users_session' => false, | ||
'default_login_redirection' => home_url(), | ||
'passwordless_enabled' => false, | ||
'passwordless_method' => 'magiclink', | ||
'force_https_callback' => false, | ||
'cdn_url' => 'https://cdn.auth0.com/js/lock/11.1/lock.min.js', | ||
'cdn_url_legacy' => 'https://cdn.auth0.com/js/lock-9.2.min.js', | ||
'passwordless_cdn_url' => 'https://cdn.auth0.com/js/lock-passwordless-2.2.min.js', | ||
'lock_connections' => '', | ||
'link_auth0_users' => null, | ||
'auto_provisioning' => false, | ||
'migration_ws' => false, | ||
'migration_token' => null, | ||
'migration_token_id' => null, | ||
'migration_ips_filter' => false, | ||
'migration_ips' => null, | ||
'auto_login' => 0, | ||
'auto_login_method' => '', | ||
'auth0_implicit_workflow' => false, | ||
'ip_range_check' => 0, | ||
'ip_ranges' => '', | ||
'valid_proxy_ip' => null, | ||
|
||
'amplificator_title' => '', | ||
'amplificator_subtitle' => '', | ||
|
||
'connections' => array(), | ||
|
||
'password_policy' => 'fair', | ||
|
||
'force_https_callback' => false, | ||
|
||
'auto_provisioning' => false, | ||
'default_login_redirection' => home_url(), | ||
|
||
'custom_signup_fields' => '', | ||
'extra_conf' => '', | ||
'social_twitter_key' => '', | ||
'social_twitter_secret' => '', | ||
'social_facebook_key' => '', | ||
'social_facebook_secret' => '', | ||
'auth0_server_domain' => 'auth0.auth0.com', | ||
'auth0js-cdn' => '//cdn.auth0.com/js/auth0/9.1/auth0.min.js', | ||
'metrics' => 1, | ||
|
||
//DASHBOARD | ||
// Dashboard | ||
'chart_idp_type' => 'donut', | ||
'chart_gender_type' => 'donut', | ||
'chart_age_type' => 'donut', | ||
|
||
'chart_age_from' => '10', | ||
'chart_age_to' => '70', | ||
'chart_age_step' => '5', | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -556,8 +556,6 @@ public function connections_validation( $old_options, $input ) { | |
|
||
if ($input['passwordless_enabled'] && $input['passwordless_enabled'] != $old_options['passwordless_enabled']) { | ||
|
||
// $check_if_enabled = explode(',', $input['lock_connections']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happened to all these comments that are now removed? was it implemented somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They've been commented for a while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but is it something you want to do someday? are you tracking it somewhere else or are they just gone for good? 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what it's for, it's obviously not doing anything, and it's related to the settings I'm working with so 👋 :) |
||
|
||
foreach ($passwordless_connections as $alias => $name) { | ||
if (strpos($input['passwordless_method'], $alias) !== false) { | ||
$check_if_enabled[] = $name; | ||
|
@@ -566,19 +564,12 @@ public function connections_validation( $old_options, $input ) { | |
|
||
} elseif ($input['passwordless_method'] != $old_options['passwordless_method']) { | ||
|
||
// $check_if_enabled = explode(',', $input['lock_connections']); | ||
|
||
foreach ($passwordless_connections as $name) { | ||
if (strpos($input['passwordless_method'], $name) !== false) { | ||
$check_if_enabled[] = $name; | ||
} | ||
} | ||
|
||
} // elseif ($input['lock_connections'] != $old_options['lock_connections']) { | ||
|
||
// $check_if_enabled = explode(',', $input['lock_connections']); | ||
|
||
// } | ||
} | ||
|
||
if (!empty($check_if_enabled)) { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this like this
get(key, valueIfMissing)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes