Skip to content
Snippets Groups Projects
Commit f7954199 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Fix session

parent cfc9c8e8
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ use SimpleSAML\Auth; ...@@ -9,6 +9,7 @@ use SimpleSAML\Auth;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\Module; use SimpleSAML\Module;
use SimpleSAML\Utils; use SimpleSAML\Utils;
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
/** /**
* Example external authentication source. * Example external authentication source.
...@@ -64,13 +65,12 @@ class External extends Auth\Source ...@@ -64,13 +65,12 @@ class External extends Auth\Source
* stored in the users PHP session, but this could be replaced * stored in the users PHP session, but this could be replaced
* with anything. * with anything.
*/ */
$session = new SymfonySession();
if (!session_id()) { if (!$session->getId()) {
// session_start not called before. Do it here $session->start();
session_start();
} }
if (!isset($_SESSION['uid'])) { if (!$session->has('uid')) {
// The user isn't authenticated // The user isn't authenticated
return null; return null;
} }
...@@ -80,16 +80,15 @@ class External extends Auth\Source ...@@ -80,16 +80,15 @@ class External extends Auth\Source
* Note that all attributes in SimpleSAMLphp are multivalued, so we need * Note that all attributes in SimpleSAMLphp are multivalued, so we need
* to store them as arrays. * to store them as arrays.
*/ */
$attributes = [ $attributes = [
'uid' => [$_SESSION['uid']], 'uid' => [$session->get('uid')],
'displayName' => [$_SESSION['name']], 'displayName' => [$session->get('name')],
'mail' => [$_SESSION['mail']], 'mail' => [$session->get('mail')],
]; ];
// Here we generate a multivalued attribute based on the account type // Here we generate a multivalued attribute based on the account type
$attributes['eduPersonAffiliation'] = [ $attributes['eduPersonAffiliation'] = [
$_SESSION['type'], /* In this example, either 'student' or 'employee'. */ $session->get('type'), /* In this example, either 'student' or 'employee'. */
'member', 'member',
]; ];
...@@ -265,15 +264,12 @@ class External extends Auth\Source ...@@ -265,15 +264,12 @@ class External extends Auth\Source
*/ */
public function logout(array &$state): void public function logout(array &$state): void
{ {
if (!session_id()) { $session = new SymfonySession();
// session_start not called before. Do it here if (!$session->getId()) {
session_start(); $session->start();
} }
/* $session->clear();
* In this example we simply remove the 'uid' from the session.
*/
unset($_SESSION['uid']);
/* /*
* If we need to do a redirect to a different page, we could do this * If we need to do a redirect to a different page, we could do this
......
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