logout(SimpleSAML_Utilities::selfURLNoQuery()); /* The previous function will never return. */ } if (array_key_exists('login', $_REQUEST)) { /* * If the login parameter is requested, it means that we should log * the user in. We do that by requiring the user to be authenticated. * * Note that the requireAuth-function will preserve all GET-parameters * and POST-parameters by default. */ $as->requireAuth(); /* The previous function will only return if the user is authenticated. */ } if (array_key_exists('message', $_POST)) { /* * We require authentication while posting a message. If the user is * authenticated, the message will be shown. * * Since POST parameters are preserved during requireAuth-processing, * the message will be presented to the user after the authentication. */ $as->requireAuth(); $message = $_POST['message']; } else { $message = NULL; } /* * We set a variable depending on whether the user is authenticated or not. * This allows us to show the user a login link or a logout link depending * on the authentication state. */ $isAuth = $as->isAuthenticated(); /* * Retrieve the users attributes. We will list them if the user * is authenticated. */ $attributes = $as->getAttributes(); ?> Simple test

Simple auth test

You are currently authenticated. Log out.

'; } else { echo '

You are not authenticated. Log in.

'; } ?>

The following form makes it possible to test requiering authentication in a POST handler. Try to submit the message while unauthenticated.

Message'; echo '

' . htmlspecialchars($message) . '

'; } /* Print out the attributes if the user is authenticated. */ if ($isAuth) { echo '

Attributes

'; echo '
'; foreach ($attributes as $name => $values) { echo '
' . htmlspecialchars($name) . '
'; echo '
'; } echo '
'; } ?>