Skip to content

Commit

Permalink
Remove set_connection usage
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jul 19, 2018
1 parent 3bdcf55 commit 58b884d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/WP_Auth0_Api_Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/WP_Auth0_Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function is_wp_registration_enabled() {
return is_multisite() ? users_can_register_#_filter() : get_site_option( 'users_can_register' );
}

/**
* TODO: Deprecate
*/
public function set_connection( $key, $value ) {
$options = $this->get_options();
$options['connections'][ $key ] = $value;
Expand Down
73 changes: 71 additions & 2 deletions lib/initial-setup/WP_Auth0_InitialSetup_Connections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 0 additions & 4 deletions lib/initial-setup/WP_Auth0_InitialSetup_Consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand Down

0 comments on commit 58b884d

Please # to comment.