diff --git a/lib/WP_Auth0_Api_Operations.php b/lib/WP_Auth0_Api_Operations.php index 02751050..3538b583 100644 --- a/lib/WP_Auth0_Api_Operations.php +++ b/lib/WP_Auth0_Api_Operations.php @@ -153,6 +153,8 @@ public function create_wordpress_connection( $app_token, $migration_enabled, $pa } /** + * TODO: Deprecate when self::update_connection() is deprecated + * * This function will sync and update the connection setting with auth0 * First it checks if there is any connection with this strategy enabled for the app. * - If exists, it checks if it has the facebook keys, in this case will ignore WP setting and will update the WP settings diff --git a/lib/WP_Auth0_Options.php b/lib/WP_Auth0_Options.php index 839ef89b..d32e35fc 100755 --- a/lib/WP_Auth0_Options.php +++ b/lib/WP_Auth0_Options.php @@ -16,6 +16,9 @@ public function is_wp_registration_enabled() { return is_multisite() ? users_can_register_signup_filter() : get_site_option( 'users_can_register' ); } + /** + * TODO: Deprecate + */ public function set_connection( $key, $value ) { $options = $this->get_options(); $options['connections'][ $key ] = $value; diff --git a/lib/initial-setup/WP_Auth0_InitialSetup_Connections.php b/lib/initial-setup/WP_Auth0_InitialSetup_Connections.php index 14a18f00..ac9e0091 100644 --- a/lib/initial-setup/WP_Auth0_InitialSetup_Connections.php +++ b/lib/initial-setup/WP_Auth0_InitialSetup_Connections.php @@ -27,16 +27,85 @@ public function update_connection() { } /** - * TODO: Remove when self::update_connection() is removed + * TODO: Deprecate when self::update_connection() is deprecated */ protected function toggle_db() { + + $domain = $this->a0_options->get( 'domain' ); + $app_token = $this->a0_options->get( 'auth0_app_token' ); + $connection_id = $this->a0_options->get( 'db_connection_id' ); + $client_id = $this->a0_options->get( 'client_id' ); + + $connection = WP_Auth0_Api_Client::get_connection( $domain, $app_token, $connection_id ); + + $enabled_clients = array(); + + if ( $_POST['enabled'] === 'true' ) { + $enabled_clients = $connection->enabled_clients; + $enabled_clients[] = $client_id; + } else { + $enabled_clients = array_diff( $connection->enabled_clients, array( $client_id ) ); + } + + $connection->enabled_clients = array_values( $enabled_clients ); + + unset( $connection->name ); + unset( $connection->strategy ); + unset( $connection->id ); + + WP_Auth0_Api_Client::update_connection( $domain, $app_token, $connection_id, $connection ); + + $this->a0_options->set( 'db_connection_enabled', $_POST['enabled'] === 'true' ? 1 : 0 ); + exit; } /** - * TODO: Remove when self::update_connection() is removed + * TODO: Deprecate when self::update_connection() is deprecated */ protected function toggle_social( $provider_name ) { + + $provider_options = array( + 'facebook' => array( + 'public_profile' => true, + 'email' => true, + 'user_birthday' => true, + 'publish_actions' => true, + ), + 'twitter' => array( + 'profile' => true, + ), + 'google-oauth2' => array( + 'google_plus' => true, + 'email' => true, + 'profile' => true, + ), + ); + + $input = array(); + $old_input = array(); + + $operations = new WP_Auth0_Api_Operations( $this->a0_options ); + + $old_input[ "social_{$provider_name}" ] = $this->a0_options->get_connection( "social_{$provider_name}" ); + $old_input[ "social_{$provider_name}_key" ] = $this->a0_options->get_connection( "social_{$provider_name}_key" ); + $old_input[ "social_{$provider_name}_secret" ] = $this->a0_options->get_connection( "social_{$provider_name}_secret" ); + + $input[ "social_{$provider_name}" ] = ( $_POST['enabled'] === 'true' ); + $input[ "social_{$provider_name}_key" ] = $this->a0_options->get_connection( "social_{$provider_name}_key" ); + $input[ "social_{$provider_name}_secret" ] = $this->a0_options->get_connection( "social_{$provider_name}_secret" ); + + try { + $options = isset( $provider_options[ $provider_name ] ) ? $provider_options[ $provider_name ] : null; + $input = $operations->social_validation( $this->a0_options->get( 'auth0_app_token' ), $old_input, $input, $provider_name, $options ); + } catch ( Exception $e ) { + exit( $e->getMessage() ); + } + + foreach ( $input as $key => $value ) { + $this->a0_options->set_connection( $key, $value ); + } + exit; } diff --git a/lib/initial-setup/WP_Auth0_InitialSetup_Consent.php b/lib/initial-setup/WP_Auth0_InitialSetup_Consent.php index 34bcbaf4..9b8cc4ad 100644 --- a/lib/initial-setup/WP_Auth0_InitialSetup_Consent.php +++ b/lib/initial-setup/WP_Auth0_InitialSetup_Consent.php @@ -138,10 +138,6 @@ public function consent_callback( $name ) { $enabled_clients = array_diff( $connection->enabled_clients, array( $client_id ) ); WP_Auth0_Api_Client::update_connection( $domain, $app_token, $connection->id, array( 'enabled_clients' => array_values( $enabled_clients ) ) ); } - } elseif ( $connection->strategy !== 'auth0' ) { - $this->a0_options->set_connection( "social_{$connection->name}", 1 ); - $this->a0_options->set_connection( "social_{$connection->name}_key", isset( $connection->options->client_id ) ? $connection->options->client_id : null ); - $this->a0_options->set_connection( "social_{$connection->name}_secret", isset( $connection->options->client_secret ) ? $connection->options->client_secret : null ); } } }