Skip to content
Snippets Groups Projects
Commit 8089261b authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

allow redirection of user after login, re #4482

parent 7533ca13
No related branches found
No related tags found
1 merge request!3266add oauth2 as auth plugin, fixes #4482
Pipeline #25860 passed
......@@ -62,18 +62,22 @@ final class StudipAuthOAuth2 extends StudipAuthSSO
if (!Request::get('code')) {
$authorizationUrl = $this->oauth2_provider->getAuthorizationUrl(['scope' => 'profile email']);
$_SESSION['oauth2state'] = $this->oauth2_provider->getState();
$_SESSION[self::class] = [
'state' => $this->oauth2_provider->getState(),
'redirect' => Request::url(),
];
page_close();
header('Location: ' . $authorizationUrl);
die;
} elseif (
!Request::get('state')
|| empty($_SESSION['oauth2state'])
|| Request::get('state') !== $_SESSION['oauth2state']
|| empty($_SESSION[self::class]['state'])
|| Request::get('state') !== $_SESSION[self::class]['state']
) {
if (isset($_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
if (isset($_SESSION[self::class])) {
unset($_SESSION[self::class]);
}
} else {
$accessToken = $this->oauth2_provider->getAccessToken('authorization_code', [
......@@ -104,6 +108,6 @@ final class StudipAuthOAuth2 extends StudipAuthSSO
*/
private function getUsernameKey(): string
{
return $this->user_data_mapping['auth_user_md5.username'] ?? 'nickname';
return $this->user_data_mapping['map_args']['auth_user_md5.username'] ?? 'nickname';
}
}
......@@ -125,7 +125,13 @@ class Seminar_Auth
# Check for user supplied automatic login procedure
if ($uid = $this->auth_preauth()) {
$this->auth["uid"] = $uid;
$sess->regenerate_session_id(['auth', '_language', 'phpCAS', 'contrast']);
$sess->regenerate_session_id([
'_language',
'auth',
'contrast',
'phpCAS',
StudipAuthOAuth2::class
]);
$sess->freeze();
$GLOBALS['user'] = new Seminar_User($this->auth['uid']);
return true;
......
......@@ -158,6 +158,15 @@ if (Navigation::hasItem('/profile/edit')) {
}
if ($user_did_login) {
if (isset($_SESSION[StudipAuthOAuth2::class]['redirect'])) {
$redirect = $_SESSION[StudipAuthOAuth2::class]['redirect'];
unset($_SESSION[StudipAuthOAuth2::class]);
page_close();
header('Location: ' . $redirect);
die;
}
NotificationCenter::postNotification('UserDidLogin', $user->id);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment