Beispiel #1
0
    return empty($_SESSION['tokens']) ? null : new \P7\SSO\TokenSet($_SESSION['tokens']);
}
function authenticatedRedirect()
{
    $tokens = getSessionTokens();
    if (!$tokens) {
        return false;
    }
    header('Location: /account');
    exit;
}
$loggedIn = getSessionTokens() ? true : false;
switch ($action) {
    case 'login':
        authenticatedRedirect();
        $uri = $sso->authorization()->authorizeUri(['redirect_uri' => $callbackUri]);
        require 'partial/login.php';
        break;
    case 'login-redirect':
        authenticatedRedirect();
        $uri = $sso->authorization()->authorizeUri(['redirect_uri' => $callbackUri]);
        header('Location: ' . $uri);
        break;
    case 'callback':
        authenticatedRedirect();
        if (!empty($_GET['error'])) {
            $error = $_GET['error'];
            $errorDescription = $_GET['error_description'];
            require 'partial/callback.php';
            break;
        }
Beispiel #2
0
}
function authenticatedRedirect()
{
    $tokens = getSessionTokens();
    if (!$tokens) {
        return false;
    }
    header('Location: /account');
    exit;
}
$loggedIn = getSessionTokens() ? true : false;
switch ($action) {
    case 'login':
        authenticatedRedirect();
        $_SESSION['state'] = md5(uniqid(rand(), true));
        $uri = $sso->authorization()->authorizeUri(['redirect_uri' => $callbackUri, 'state' => $_SESSION['state']]);
        require 'partial/login.php';
        break;
    case 'login-redirect':
        authenticatedRedirect();
        $uri = $sso->authorization()->authorizeUri(['redirect_uri' => $callbackUri, 'state' => $_SESSION['state']]);
        header('Location: ' . $uri);
        break;
    case 'callback':
        authenticatedRedirect();
        try {
            $tokens = $sso->authorization()->callback($callbackUri, $_GET, $_SESSION['state']);
            $_SESSION['tokens'] = $tokens->getArrayCopy();
        } catch (AuthorizeCallbackException $e) {
            $error = $e->getError();
            $errorDescription = $e->getMessage();