Skip to content

Commit

Permalink
add nice error message when exchange of token returns 401 #11
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Oct 10, 2014
1 parent 6879659 commit 63a09fd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
30 changes: 29 additions & 1 deletion WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,33 @@ public static function init(){
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", array(__CLASS__, 'wp_add_plugin_settings_link'));

if (isset($_GET['message']))
{
add_action( 'wp_footer', array( __CLASS__, 'a0_render_message' ) );
}

WP_Auth0_Admin::init();
WP_Auth0_ErrorLog::init();
}

public static function a0_render_message()
{
$message = null;

switch (strtolower($_GET['message']))
{
case 'unauthorized': $message = "Please check your Client Secret on the settings plugin is the same as the one on the Auth0 dashboard."; break;
}

if ($message)
{
echo "<div class=\"a0-message\">$message <small onclick=\"jQuery('.a0-message').hide();\">(Close)</small></div>";
echo '<script type="text/javascript">
setTimeout(function(){jQuery(".a0-message").hide();}, 10 * 1000);
</script>';
}
}

// Add settings link on plugin page
public static function wp_add_plugin_settings_link($links) {

Expand All @@ -81,6 +104,11 @@ public static function wp_enqueue(){

if (trim($client_id) == "") return;

if (isset($_GET['message']))
{
wp_enqueue_script('jquery');
}

wp_enqueue_style( 'auth0-widget', WPA0_PLUGIN_URL . 'assets/css/main.css' );
}

Expand Down Expand Up @@ -228,7 +256,7 @@ public static function init_auth0(){
$body = array(
'client_id' => $client_id,
'redirect_uri' => home_url(),
'client_secret' => $client_secret,
'client_secret' =>'0'. $client_secret,
'code' => $code,
'grant_type' => 'authorization_code'
);
Expand Down
16 changes: 16 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,20 @@
}
.auth0-login .form-signin-heading {
margin-bottom: 10px;
}
.a0-message{
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #FFF;
line-height: 2em;
text-align: center;
font-weight: bold;
z-index: 999;
}

.a0-message small {
font-weight: normal;
cursor: pointer;
}

0 comments on commit 63a09fd

Please sign in to comment.