-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOAP binding / backend logout work in progress proposal #613
base: MOODLE_39_STABLE
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,19 @@ public static function logout_from_idp_front_channel(): void { | |
require_logout(); | ||
} | ||
|
||
public static function logout_from_idp_back_channel($username, $sessionId): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you flesh out the phpdoc here and clarify if the sessionid is the moodle session id or the SSP session id? Renaming the vars would be helpful too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I would assume that the username here is not necessarily the same as the username of the moodle user and it may need to go through the same attribute mapping logic as here: https://github.com/catalyst/moodle-auth_saml2/blob/MOODLE_39_STABLE/classes/auth.php#L72-L73 |
||
global $DB; | ||
if (isset($sessionId)) { | ||
$DB->delete_records('auth_saml2_kvstore', array('k' => $sessionId)); | ||
} | ||
|
||
$userid = $DB->get_record('user', array('username' => $username), 'id'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add MUST_EXIST or handle the case where the user doesn't exist? ie if they have been deleted while logged in in the interim (small edge case) |
||
$mdsessionids = $DB->get_records('sessions', array('userid' => $userid->id), 'sid DESC', 'sid'); | ||
foreach ($mdsessionids as $mdsessionid) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I have a feeling these ~10 lines might be best re-ordered. This appears to be logging out all sessions of this users which isn't 100% correct. I would expect that you actually need to look at the values in the auth_saml2_kvstore to get a reverse mapping from the SSP session to the Moodle Session id and then just remove the single session. Also I would not touch any of the moodle session tables directly, instead use the moodle api for this:
|
||
$DB->delete_records('sessions', array('sid' => $mdsessionid->sid)); | ||
} | ||
} | ||
|
||
/** | ||
* SP logout callback. Called in case of normal Moodle logout. | ||
* {@see auth::logoutpage_hook} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,25 @@ | |
// user out in Moodle. | ||
if (!is_null($session->getAuthState($saml2auth->spname))) { | ||
$session->registerLogoutHandler($saml2auth->spname, '\auth_saml2\api', 'logout_from_idp_front_channel'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how the logut handler is registered for the case where we have a session, with some wrangling I'm hoping we can also use tehe same method to register a logout handler for the soap side of the equation. |
||
} else { | ||
try { | ||
$binding = \SAML2\Binding::getCurrentBinding(); | ||
} catch (\Exception $e) { | ||
// TODO: look for a specific exception | ||
// This is dirty. Instead of checking the message of the exception, \SAML2\Binding::getCurrentBinding() should throw | ||
// an specific exception when the binding is unknown, and we should capture that here | ||
if ($e->getMessage() === 'Unable to find the current binding.') { | ||
throw new \SimpleSAML\Error\Error('SLOSERVICEPARAMS', $e, 400); | ||
} else { | ||
throw $e; // do not ignore other exceptions! | ||
} | ||
} | ||
$message = $binding->receive(); | ||
|
||
if ($message instanceof \SAML2\LogoutRequest) { | ||
//Todo : parse xmlbody, get sp sessionid/moodle userid, and register logoutHandler from here ? | ||
//For the time being the call to the specific logout function is done with 3 lines in extlib.. session.php | ||
} | ||
} | ||
|
||
require('../.extlib/simplesamlphp/modules/saml/www/sp/saml2-logout.php'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to try an eliminate this change to the internal library which I think is possible, see comments below