Skip to content

Commit

Permalink
Merge pull request #78 from auth0/dev
Browse files Browse the repository at this point in the history
Fixed Mixed content warning #75 & added login action for issue #76 #77
  • Loading branch information
glena committed Jun 10, 2015
2 parents d0d8238 + 51da620 commit 7905a44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ There are cases where the server is behind a firewall and does not have access t

When it is enabled, the token is returned in the login callback and then sent back to the WordPress sever so it doesn't need to call the Auth0 webervices.

## Interating with the plugin

The plugin provides an action to get notified each time a user logs in or is created in WordPress. This action is called `auth0_user_login` and receives 4 params:
1. $user_id (int): the id of the user logged in
2. $user_profile (stdClass): the Auth0 profile of the user
3. $is_new (boolean): `true` if the user was created on WordPress, `false` if doesn't. Don't get confused with Auth0 registrations, this flag will tell you if a new user was created on the WordPress database.
4. $id_token (string): the user's JWT.

To hook to this action, you will need to do the following:
```
add_action( 'auth0_user_login', 'auth0UserLoginAction', 0,4 );
function auth0UserLoginAction($user_id, $user_profile, $is_new, $id_token) {
...
}
```

## API authentication

The last version of the plugin provides the ability integrate with **wp-jwt-auth** plugin to authenticate api calls via a HTTP Authorization Header.
Expand Down
11 changes: 8 additions & 3 deletions WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Wordpress Auth0 Integration
* Description: Implements the Auth0 Single Sign On solution into Wordpress
* Version: 1.3.0
* Version: 1.3.1
* Author: Auth0
* Author URI: https://auth0.com
*/
Expand All @@ -12,7 +12,7 @@
define('WPA0_PLUGIN_URL', trailingslashit(plugin_dir_url(__FILE__) ));
define('WPA0_LANG', 'wp-auth0');
define('AUTH0_DB_VERSION', 2);
define('WPA0_VERSION', '1.3.0');
define('WPA0_VERSION', '1.3.1');

class WP_Auth0 {
public static function init(){
Expand Down Expand Up @@ -180,7 +180,7 @@ public static function wp_enqueue(){
wp_enqueue_script('jquery');
}

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

public static function shortcode( $atts ){
Expand Down Expand Up @@ -558,6 +558,9 @@ public static function login_user( $userinfo, $id_token ){
// User exists! Log in
self::updateAuth0Object($userinfo);
wp_set_auth_cookie( $user->ID );

do_action( 'auth0_user_login' , $user->ID, $userinfo, false, $id_token );

return true;
} else {

Expand All @@ -566,6 +569,8 @@ public static function login_user( $userinfo, $id_token ){
$user_id = $creator->create($userinfo, $id_token);

wp_set_auth_cookie( $user_id );

do_action( 'auth0_user_login' , $user_id, $userinfo, true, $id_token );
}
catch (WP_Auth0_CouldNotCreateUserException $e) {
$msg = __('Error: Could not create user.', WPA0_LANG);
Expand Down

0 comments on commit 7905a44

Please sign in to comment.