Handle Back-channel Logout
masterBack-channel logout allows an OpenID Provider (OP) to notify your Relying Party (RP) to end a session via a POST request.
To handle this:
- Use
verifyLogoutToken()to validate the incoming token. - Retrieve the session identifier using
getSidFromBackChannel()or the subject usinggetSubjectFromBackChannel(). - Use these identifiers to locate and destroy the corresponding local session in your application (e.g., by looking up a session ID in Redis).
// Hypothetical implementation of a logout handler
function handleLogout() {
if ($this->oidc->verifyLogoutToken()) {
$sid = $this->oidc->getSidFromBackChannel();
if (isset($sid)) {
// Example: finding and destroying a session via Redis
$this->redis->connect('127.0.0.1', 6379);
$session_id_to_destroy = $this->redis->get($sid);
if ($session_id_to_destroy) {
session_commit();
session_id($session_id_to_destroy);
session_start();
$_SESSION = [];
}
}
}
}