@@ -83,7 +83,7 @@ public function __construct( $settings ) {
8383 add_action ( 'login_form ' , array ( $ this , 'print_login_link ' ) ) ;
8484
8585 // Clear session variables when logging out
86- add_action ( 'wp_logout ' , array ( $ this , 'clear_session ' ) );
86+ add_action ( 'wp_logout ' , array ( $ this , 'logout ' ) );
8787
8888 // If configured, bypass the login form and redirect straight to AAD
8989 add_action ( 'login_init ' , array ( $ this , 'save_redirect_and_maybe_bypass_login ' ), 20 );
@@ -348,6 +348,10 @@ function authenticate( $user, $username, $password ) {
348348 );
349349 }
350350
351+ if ( is_a ( $ user , 'WP_User ' ) ) {
352+ $ _SESSION ['aadsso_signed_in_with_azuread ' ] = true ;
353+ }
354+
351355 return $ user ;
352356 }
353357
@@ -563,6 +567,21 @@ function clear_session() {
563567 session_destroy ();
564568 }
565569
570+ /**
571+ * Clears the current the session, and triggers a full Azure AD logout if needed.
572+ */
573+ function logout () {
574+
575+ $ signed_in_with_azuread = isset ( $ _SESSION ['aadsso_signed_in_with_azuread ' ] )
576+ && true === $ _SESSION ['aadsso_signed_in_with_azuread ' ];
577+ $ this ->clear_session ();
578+
579+ if ( $ signed_in_with_azuread && $ this ->settings ->enable_full_logout ) {
580+ wp_redirect ( $ this ->get_logout_url () );
581+ die ();
582+ }
583+ }
584+
566585 /*** Settings ***/
567586
568587 /**
0 commit comments