You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

<?php
declare(strict_types=1);
require '_common.php';
use authkit2\Authkit2;
echo html_header();
if (isset($_SESSION['access_token']) && isset($_SESSION['refresh_token']))
{
// Fetch the token for the user so we can make requests on their behalf
$token = Authkit2::get_token($_SESSION['access_token'], $_SESSION['refresh_token']);
// If the token needs to be refreshed, the library will do that for us, but
// we need to set a callback so it can let us know to store the updated token.
$token->setRefreshCallback(static function($token) {
echo 'Refreshing token...<br>';
$_SESSION['access_token'] = $token->getAccessToken();
$_SESSION['refresh_token'] = $token->getRefreshToken();
});
// Fetch the user's information from the openid provider
$user_info = $token->getUserInfo();
echo 'Hello, '.$user_info['name'].'!<br>';
echo 'Your id is: '.$token->getUserId().'<br>';
echo '<a href="logout.php">Logout</a><br>';
}
else
{
echo 'Not signed in.<br>';
echo '<a href="login.php">Login</a><br>';
}
echo html_footer();