99use SimpleSAML \Error ;
1010use SimpleSAML \Module ;
1111use SimpleSAML \Utils ;
12+ use Symfony \Component \HttpFoundation \Session \Session as SymfonySession ;
1213
1314/**
1415 * Example external authentication source.
@@ -64,13 +65,12 @@ private function getUser(): ?array
6465 * stored in the users PHP session, but this could be replaced
6566 * with anything.
6667 */
67-
68- if (!session_id ()) {
69- // session_start not called before. Do it here
70- session_start ();
68+ $ session = new SymfonySession ();
69+ if (!$ session ->getId ()) {
70+ $ session ->start ();
7171 }
7272
73- if (!isset ( $ _SESSION [ 'uid ' ] )) {
73+ if (!$ session -> has ( 'uid ' )) {
7474 // The user isn't authenticated
7575 return null ;
7676 }
@@ -80,16 +80,15 @@ private function getUser(): ?array
8080 * Note that all attributes in SimpleSAMLphp are multivalued, so we need
8181 * to store them as arrays.
8282 */
83-
8483 $ attributes = [
85- 'uid ' => [$ _SESSION [ 'uid ' ] ],
86- 'displayName ' => [$ _SESSION [ 'name ' ] ],
87- 'mail ' => [$ _SESSION [ 'mail ' ] ],
84+ 'uid ' => [$ session -> get ( 'uid ' ) ],
85+ 'displayName ' => [$ session -> get ( 'name ' ) ],
86+ 'mail ' => [$ session -> get ( 'mail ' ) ],
8887 ];
8988
9089 // Here we generate a multivalued attribute based on the account type
9190 $ attributes ['eduPersonAffiliation ' ] = [
92- $ _SESSION [ 'type ' ] , /* In this example, either 'student' or 'employee'. */
91+ $ session -> get ( 'type ' ) , /* In this example, either 'student' or 'employee'. */
9392 'member ' ,
9493 ];
9594
@@ -265,15 +264,12 @@ public static function resume(): void
265264 */
266265 public function logout (array &$ state ): void
267266 {
268- if (! session_id ()) {
269- // session_start not called before. Do it here
270- session_start ();
267+ $ session = new SymfonySession ();
268+ if (! $ session -> getId ()) {
269+ $ session -> start ();
271270 }
272271
273- /*
274- * In this example we simply remove the 'uid' from the session.
275- */
276- unset($ _SESSION ['uid ' ]);
272+ $ session ->clear ();
277273
278274 /*
279275 * If we need to do a redirect to a different page, we could do this
0 commit comments