File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ http://moodle.local/auth/saml2/login.php?wants&idp=c4b9265e38e3107bee1ccdf9d6475
1818http://moodle.local/login/logout.php?sesskey=ihwmEywPxu
1919
2020
21- 4 ) Test Single logout starting from the IdP
21+ 4 ) Test Single logout starting from the IdP. Notice that ` ReturnTo ` URL domain should be in ` trusted.url.domains ` in IdP config.
22+ If that is not the case, try using ` ReturnTo=http://idp.local/simplesaml ` which should work as SimpleSAMLphp trusts self hostname by default.
2223
2324http://idp.local/simplesaml/saml2/idp/SingleLogoutService.php?ReturnTo=http://moodle.local/
2425
Original file line number Diff line number Diff line change 2929 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3030 */
3131class api {
32+
3233 /**
33- * Called from SimpleSamlphp after a LogoutResponse from the IdP
34+ * IdP logout callback. Called only when logout is initiated from IdP.
35+ * {@see saml2-logout.php}
3436 */
3537 public static function logout_from_idp_front_channel (): void {
36- // The SP session will be cleaned up but we need to remove the
37- // Moodle session here.
38- \core \session \manager::terminate_current ();
38+ // The SP session will be cleaned up. Log user out of Moodle.
39+ require_logout ();
3940 }
4041
4142 /**
42- * Called from SimpleSamlphp after a LogoutRequest from the SP
43+ * SP logout callback. Called in case of normal Moodle logout.
44+ * {@see auth::logoutpage_hook}
4345 *
4446 * @param array $state Information about the current logout operation.
4547 */
Original file line number Diff line number Diff line change 3333/*
3434 * There are 4 methods of logging out:
3535 *
36- * 1) Initiated from moodles logout, in which case we first logout of
36+ * 1) Initiated from moodle logout, in which case we first logout of
3737 * moodle and then log out of the middle SP and then optionally
3838 * redirect to the IdP to do full Single Logout. This is the way
39- * a majority of users logout and is fully supported.
39+ * a majority of users logout and is fully supported. Notice that in this
40+ * case SAML session is not authenticated by the time we reach this point.
4041 *
4142 * 2) If doing SLO via IdP via the HTTP-Redirect binding
4243 *
4849 */
4950try {
5051 $ session = \SimpleSAML \Session::getSessionFromRequest ();
51- $ session ->registerLogoutHandler ($ saml2auth ->spname , '\auth_saml2\api ' , 'logout_from_idp_front_channel ' );
52+ // When logout is initiated from IdP (we land here from SingleLogoutService call),
53+ // session is still authenticated, so we can register the handler that will log
54+ // user out in Moodle.
55+ if (!is_null ($ session ->getAuthState ($ saml2auth ->spname ))) {
56+ $ session ->registerLogoutHandler ($ saml2auth ->spname , '\auth_saml2\api ' , 'logout_from_idp_front_channel ' );
57+ }
5258
5359 require ('../.extlib/simplesamlphp/modules/saml/www/sp/saml2-logout.php ' );
5460} catch (Exception $ e ) {
You can’t perform that action at this time.
0 commit comments