Skip to content

Commit

Permalink
Add option to do full logout
Browse files Browse the repository at this point in the history
Adds a new option to perform a full logout of Azure AD when
logging out of WordPress. Fixes #163 and fixes #184.
  • Loading branch information
psignoret committed Apr 6, 2018
1 parent 137ff4a commit 4da5465
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class AADSSO_Settings {
*/
public $default_wp_role = null;

/**
* Indicates whether a logout of WordPress should also trigger a logout of Azure AD.
*
* @var boolean Whether or not logging out of WordPress triggers logging out of Azure AD.
*/
public $enable_full_logout = false;

/**
* @var string The OpenID Connect configuration discovery endpoint.
*/
Expand Down
20 changes: 20 additions & 0 deletions SettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ public function register_settings() {
'aadsso_settings_page', // page
'aadsso_settings_general' // section
);

add_settings_field(
'enable_full_logout', // id
__( 'Enable full logout', 'aad-sso-wordpress' ), // title
array( $this, 'enable_full_logout_callback' ), // callback
'aadsso_settings_page', // page
'aadsso_settings_general' // section
);

add_settings_field(
'field_to_match_to_upn', // id
Expand Down Expand Up @@ -374,6 +382,7 @@ public function sanitize_settings( $input ) {
'enable_auto_forward_to_aad',
'enable_aad_group_to_wp_role',
'match_on_upn_alias',
'enable_full_logout',
);
foreach ( $boolean_settings as $boolean_setting )
{
Expand Down Expand Up @@ -646,6 +655,17 @@ public function openid_configuration_endpoint_callback() {
);
}

/**
* Renders the `enable_full_logout` checkbox control.
*/
public function enable_full_logout_callback() {
$this->render_checkbox_field(
'enable_full_logout',
__( 'Do a full logout of Azure AD when logging out of WordPress.',
'aad-sso-wordpress' )
);
}

/**
* Renders a simple text field and populates it with the setting value.
*
Expand Down
21 changes: 20 additions & 1 deletion aad-sso-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct( $settings ) {
add_action( 'login_form', array( $this, 'print_login_link' ) ) ;

// Clear session variables when logging out
add_action( 'wp_logout', array( $this, 'clear_session' ) );
add_action( 'wp_logout', array( $this, 'logout' ) );

// If configured, bypass the login form and redirect straight to AAD
add_action( 'login_init', array( $this, 'save_redirect_and_maybe_bypass_login' ), 20 );
Expand Down Expand Up @@ -348,6 +348,10 @@ function authenticate( $user, $username, $password ) {
);
}

if ( is_a( $user, 'WP_User' ) ) {
$_SESSION['aadsso_signed_in_with_azuread'] = true;
}

return $user;
}

Expand Down Expand Up @@ -563,6 +567,21 @@ function clear_session() {
session_destroy();
}

/**
* Clears the current the session, and triggers a full Azure AD logout if needed.
*/
function logout() {

$signed_in_with_azuread = isset( $_SESSION['aadsso_signed_in_with_azuread'] )
&& true === $_SESSION['aadsso_signed_in_with_azuread'];
$this->clear_session();

if ( $signed_in_with_azuread && $this->settings->enable_full_logout ) {
wp_redirect( $this->get_logout_url() );
die();
}
}

/*** Settings ***/

/**
Expand Down

3 comments on commit 4da5465

@bradkovach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psignoret You forgot to increment the version number!

@psignoret
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradkovach I haven't been following a strict versioning strategy so far, perhaps now is a good time to do so. Per semver.org, this would have fit under "add functionality in a backwards-compatible manner", so should have incremented minor version to 0.7.0. Thoughts? Suggestions?

@chris18890
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d go with .0.7.0 :)

Please sign in to comment.