Skip to content

Commit

Permalink
Merge pull request #224 from auth0/dev
Browse files Browse the repository at this point in the history
Lock10 + guardian support
  • Loading branch information
glena authored Aug 16, 2016
2 parents 4300154 + a7d4a25 commit 3025392
Show file tree
Hide file tree
Showing 20 changed files with 693 additions and 54 deletions.
17 changes: 14 additions & 3 deletions WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: PLUGIN_NAME
* Description: PLUGIN_DESCRIPTION
* Version: 3.1.6
* Version: 3.2.0
* Author: Auth0
* Author URI: https://auth0.com
*/
Expand All @@ -11,8 +11,8 @@
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', 9 );
define( 'WPA0_VERSION', '3.1.6' );
define( 'AUTH0_DB_VERSION', 10 );
define( 'WPA0_VERSION', '3.2.0' );

/**
* Main plugin class
Expand Down Expand Up @@ -415,5 +415,16 @@ function get_currentauth0user() {
}
}

if ( ! function_exists( 'get_auth0_curatedBlogName' ) ) {
function get_auth0_curatedBlogName() {
$name = get_bloginfo( 'name' );

$name = preg_replace("/[^A-Za-z0-9 ]/", '', $name);
$name = str_replace(" ", "-", $name);

return $name;
}
}

$a0_plugin = new WP_Auth0();
$a0_plugin->init();
37 changes: 37 additions & 0 deletions lib/WP_Auth0_Api_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ public static function ConsentRequiredScopes() {
'read:users',
'update:users',
'create:users',

'update:guardian_factors',
);
}

Expand Down Expand Up @@ -701,4 +703,39 @@ public static function GetConsentScopestoShow() {
}
return $processed;
}

public static function update_guardian($domain, $app_token, $factor, $enabled) {
$endpoint = "https://$domain/api/v2/guardian/factors/$factor";

$headers = self::get_info_headers();

$headers['Authorization'] = "Bearer $app_token";
$headers['content-type'] = "application/json";

$payload = array(
"enabled" => $enabled
);

$response = wp_remote_post( $endpoint , array(
'method' => 'PUT',
'headers' => $headers,
'body' => json_encode($payload)
) );

if ( $response instanceof WP_Error ) {
WP_Auth0_ErrorManager::insert_auth0_error( 'WP_Auth0_Api_Client::update_guardian', $response );
error_log( $response->get_error_message() );
return false;
}

if ( $response['response']['code'] != 200 ) {
WP_Auth0_ErrorManager::insert_auth0_error( 'WP_Auth0_Api_Client::update_guardian', $response['body'] );
error_log( $response['body'] );
return false;
}

if ( $response['response']['code'] >= 300 ) return false;

return json_decode($response['body']);
}
}
10 changes: 5 additions & 5 deletions lib/WP_Auth0_Api_Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function update_wordpress_connection( $app_token, $connection_id, $passwo
}

$login_script = str_replace( '{THE_WS_TOKEN}', $migration_token, WP_Auth0_CustomDBLib::$login_script );
$login_script = str_replace( '{THE_WS_URL}', get_home_url() . '/migration-ws-login', $login_script );
$login_script = str_replace( '{THE_WS_URL}', get_home_url() . '/index.php?a0_action=migration-ws-login', $login_script );

$get_user_script = str_replace( '{THE_WS_TOKEN}', $migration_token, WP_Auth0_CustomDBLib::$get_user_script );
$get_user_script = str_replace( '{THE_WS_URL}', get_home_url() . '/migration-ws-get-user', $get_user_script );
$get_user_script = str_replace( '{THE_WS_URL}', get_home_url() . '/index.php?a0_action=migration-ws-get-user', $get_user_script );

$connection->options->customScripts->login = $login_script;
$connection->options->customScripts->get_user = $get_user_script;
Expand All @@ -68,7 +68,7 @@ public function create_wordpress_connection( $app_token, $migration_enabled, $pa

$domain = $this->a0_options->get( 'domain' );
$client_id = $this->a0_options->get( 'client_id' );
$db_connection_name = 'DB-' . str_replace( ' ', '-', get_bloginfo( 'name' ) );
$db_connection_name = 'DB-' . get_auth0_curatedBlogName();

$body = array(
'name' => $db_connection_name,
Expand All @@ -94,10 +94,10 @@ public function create_wordpress_connection( $app_token, $migration_enabled, $pa
}

$login_script = str_replace( '{THE_WS_TOKEN}', $migration_token, WP_Auth0_CustomDBLib::$login_script );
$login_script = str_replace( '{THE_WS_URL}', get_home_url() . '/migration-ws-login', $login_script );
$login_script = str_replace( '{THE_WS_URL}', get_home_url() . '/index.php?a0_action=migration-ws-login', $login_script );

$get_user_script = str_replace( '{THE_WS_TOKEN}', $migration_token, WP_Auth0_CustomDBLib::$get_user_script );
$get_user_script = str_replace( '{THE_WS_URL}', get_home_url() . '/migration-ws-get-user', $get_user_script );
$get_user_script = str_replace( '{THE_WS_URL}', get_home_url() . '/index.php?a0_action=migration-ws-get-user', $get_user_script );

$body['options'] = array(
'enabledDatabaseCustomization' => true,
Expand Down
49 changes: 42 additions & 7 deletions lib/WP_Auth0_DBManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ public function check_update() {

public function install_db() {

$options = WP_Auth0_Options::Instance();

if ($this->current_db_version === 0) {
$this->a0_options->set('auth0_table', false);
} elseif($this->a0_options->get('auth0_table') === null) {
$this->a0_options->set('auth0_table', true);
$options->set('auth0_table', false);
} elseif($options->get('auth0_table') === null) {
$options->set('auth0_table', true);
}

$options = WP_Auth0_Options::Instance();
$cdn_url = $options->get( 'cdn_url' );

if ( strpos( $cdn_url, 'auth0-widget-5' ) !== false || strpos( $cdn_url, 'lock-6' ) !== false ) {
$options->set( 'cdn_url', '//cdn.auth0.com/js/lock-9.1.min.js' );
}
Expand All @@ -42,9 +44,8 @@ public function install_db() {
if ( strpos( $cdn_url, 'auth0-widget-5' ) !== false || strpos( $cdn_url, 'lock-9.0' ) !== false ) {
$options->set( 'cdn_url', '//cdn.auth0.com/js/lock-9.1.min.js' );
}

if ( $this->current_db_version < 9 ) {
$this->migrate_users_data();
if ( strpos( $cdn_url, 'auth0-widget-5' ) !== false || strpos( $cdn_url, 'lock-9.1' ) !== false ) {
$options->set( 'cdn_url', '//cdn.auth0.com/js/lock-9.2.min.js' );
}

if ( $this->current_db_version <= 7 ) {
Expand All @@ -68,6 +69,40 @@ public function install_db() {
}
}

if ( $this->current_db_version < 9 ) {
$this->migrate_users_data();
}

if ( $this->current_db_version < 10 ) {

if ($options->get('use_lock_10') === null) {

if ( strpos( $cdn_url, 'lock-10.0' ) !== false ) {
$options->set('use_lock_10', false);
} else {
$options->set('use_lock_10', true);
}

}

$dict = $options->get('dict');

if (!empty($dict))
{

if (json_decode($dict) === null)
{
$options->set('language', $dict);
}
else
{
$options->set('language_dictionary', $dict);
}

}

}

$this->current_db_version = AUTH0_DB_VERSION;
update_option( 'auth0_db_version', AUTH0_DB_VERSION );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/WP_Auth0_Import_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function import_settings() {

public function export_settings() {
header( 'Content-Type: application/json' );
$name = urlencode( get_bloginfo( 'name' ) );
$name = urlencode( get_auth0_curatedBlogName() );
header( "Content-Disposition: attachment; filename=auth0_for_wordpress_settings-$name.json" );
header( 'Pragma: no-cache' );

Expand Down
Loading

0 comments on commit 3025392

Please sign in to comment.