From 67a7f177fd5bb30f15a86d365db77314aedc75c0 Mon Sep 17 00:00:00 2001 From: snufkin Date: Thu, 21 Jul 2016 12:16:19 +0200 Subject: [PATCH] Issue #2619262 by epicflux, snufkin: Allow Modules to Alter $gotourl on User Logout --- simplesamlphp_auth.api.php | 36 ++++++++++++++++++++++++++++++++++++ simplesamlphp_auth.module | 3 +++ 2 files changed, 39 insertions(+) diff --git a/simplesamlphp_auth.api.php b/simplesamlphp_auth.api.php index 260dd80..1e50158 100644 --- a/simplesamlphp_auth.api.php +++ b/simplesamlphp_auth.api.php @@ -70,3 +70,39 @@ function hook_simplesamlphp_auth_pre_login($attributes, $ext_user) { exit(); } } + +/** + * Allow modules to change the url passed to simplesamlphp during logout. + * + * Called when a user logs out of Drupal. + * + * @param string $gotourl + * The url to be passed to simplesamlphp. + * @param object $account + * The user being logged out. + */ +function hook_simplesamlphp_auth_logout_gotourl_alter(&$gotourl, $account) { + // Example of reacting to a value on the account. + if ($account->field_example == 'example_value') { + $gotourl = url( + 'thanks-for-stopping-by', + array( + 'absolute' => TRUE, + ) + ); + } + + // Example of adding the destination value to the redirect URL. + if (isset($_GET['destination'])) { + // Ensure our redirect URL is absolute. + $redirect_url = url( + $_GET['destination'], + array( + 'absolute' => TRUE, + ) + ); + + // Add our redirect URL as a querystring to the full URL. + $gotourl = $gotourl . '?redirect=' . drupal_encode_path($redirect_url); + } +} diff --git a/simplesamlphp_auth.module b/simplesamlphp_auth.module index 847c8f5..2e8c8a5 100644 --- a/simplesamlphp_auth.module +++ b/simplesamlphp_auth.module @@ -250,6 +250,9 @@ function simplesamlphp_auth_user_logout($account) { $gotourl = variable_get('simplesamlphp_auth_logoutgotourl', ''); } + // Allow modules to alter $gotourl. + drupal_alter('simplesamlphp_auth_logout_gotourl', $gotourl, $account); + $_simplesamlphp_auth_as->logout($gotourl); }