Skip to content
Snippets Groups Projects
Unverified Commit 8e311454 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Added calls to session cleanup to avoid common bugs (#1016)

parent 8fa40843
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,19 @@ SimpleSAMLphp SP API reference ...@@ -6,6 +6,19 @@ SimpleSAMLphp SP API reference
This document describes the \SimpleSAML\Auth\Simple API. This document describes the \SimpleSAML\Auth\Simple API.
This is the preferred API for integrating SimpleSAMLphp with other applications. This is the preferred API for integrating SimpleSAMLphp with other applications.
### Note on PHP sessions and SimpleSAMLphp API calls
Some SimpleSAMLphp calls replace the current active PHP session. If you previously started a session and wish to write to it, then you must cleanup the SimpleSAMLphp session before you can write to your session. If you do not need to modify your own session, then you can leave the cleanup call out; however, forgetting to call cleanup is a common source of hard to find bugs.
session_start();
// ...
$auth = new \SimpleSAML\Auth\Simple('default-sp');
$auth->isAuthenticated(); // Replaces our session with the SimpleSAMLphp one
// $_SESSION['key'] = 'value'; // This would save to the SimpleSAMLphp session which isn't what we want
SimpleSAML_Session::getSessionFromRequest()->cleanup(); // Reverts to our PHP session
// Save to our session
$_SESSION['key'] = 'value';
Constructor Constructor
----------- -----------
...@@ -34,11 +47,11 @@ Check whether the user is authenticated with this authentication source. ...@@ -34,11 +47,11 @@ Check whether the user is authenticated with this authentication source.
### Example ### Example
if (!$auth->isAuthenticated()) { if (!$auth->isAuthenticated()) {
SimpleSAML_Session::getSessionFromRequest()->cleanup();
/* Show login link. */ /* Show login link. */
print('<a href="/login">Login</a>'); print('<a href="/login">Login</a>');
} }
`requireAuth` `requireAuth`
------------- -------------
...@@ -57,6 +70,7 @@ See the documentation for the `login`-function for a description of the paramete ...@@ -57,6 +70,7 @@ See the documentation for the `login`-function for a description of the paramete
### Example 1 ### Example 1
$auth->requireAuth(); $auth->requireAuth();
SimpleSAML_Session::getSessionFromRequest()->cleanup();
print("Hello, authenticated user!"); print("Hello, authenticated user!");
### Example 2 ### Example 2
...@@ -69,6 +83,7 @@ See the documentation for the `login`-function for a description of the paramete ...@@ -69,6 +83,7 @@ See the documentation for the `login`-function for a description of the paramete
'ReturnTo' => 'https://sp.example.org/', 'ReturnTo' => 'https://sp.example.org/',
'KeepPost' => FALSE, 'KeepPost' => FALSE,
]); ]);
SimpleSAML_Session::getSessionFromRequest()->cleanup();
print("Hello, authenticated user!"); print("Hello, authenticated user!");
...@@ -112,7 +127,7 @@ The [`saml:SP`](./saml:sp) authentication source also defines some parameters. ...@@ -112,7 +127,7 @@ The [`saml:SP`](./saml:sp) authentication source also defines some parameters.
'isPassive' => TRUE, 'isPassive' => TRUE,
'ErrorURL' => 'https://.../error_handler.php', 'ErrorURL' => 'https://.../error_handler.php',
]); ]);
SimpleSAML_Session::getSessionFromRequest()->cleanup();
`logout` `logout`
-------- --------
...@@ -144,6 +159,7 @@ This function never returns. ...@@ -144,6 +159,7 @@ This function never returns.
Logout, and redirect to the specified URL. Logout, and redirect to the specified URL.
$auth->logout('https://sp.example.org/logged_out.php'); $auth->logout('https://sp.example.org/logged_out.php');
SimpleSAML_Session::getSessionFromRequest()->cleanup();
### Example 2 ### Example 2
...@@ -154,6 +170,7 @@ Same as the previous, but check the result of the logout operation afterwards. ...@@ -154,6 +170,7 @@ Same as the previous, but check the result of the logout operation afterwards.
'ReturnStateParam' => 'LogoutState', 'ReturnStateParam' => 'LogoutState',
'ReturnStateStage' => 'MyLogoutState', 'ReturnStateStage' => 'MyLogoutState',
]); ]);
SimpleSAML_Session::getSessionFromRequest()->cleanup();
And in logged_out.php: And in logged_out.php:
......
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