diff options
| author | winter Sparkles | 2026-08-09 02:26:33 +0100 |
|---|---|---|
| committer | winter Sparkles | 2026-08-09 02:26:33 +0100 |
| commit | 3354d45762bbe0db33e3d26d8997e6f6624f24d7 (patch) | |
| tree | 4bef4bf59488f443ed54ff6e30002268836ac259 /routes/test-challenges.php | |
| parent | 4bb659e1f7bb5850db5695a536428a9b71e3ffe5 (diff) | |
implement sessions and also log in/out
session data is stored in sqlite, not using php sessions
Diffstat (limited to 'routes/test-challenges.php')
| -rw-r--r-- | routes/test-challenges.php | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/routes/test-challenges.php b/routes/test-challenges.php deleted file mode 100644 index 32aad7e..0000000 --- a/routes/test-challenges.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -function presentChallenges( - Psso\Context $context, ?string $message = null -) { - $challengeTypes = Psso\AuthFlow::nextStep($context); - if ($challengeTypes === true) { - // auth finished! all good - header('Location: /login-success'); //temporary crap for testing - return; - } - if (count($challengeTypes) == 0) { - throw new RuntimeException('no more challenges available!! auth fail'); - } - - $challenges = []; - foreach ($challengeTypes as $type) { - $c = $type::create($context); - $challenges[$c->serial] = $c; - } - - $resp = new Psso\XMLResponse; - $resp->doc->addAttribute('title', L('login.title')); - if (isset($message)) { - $resp->doc->addChild('challenge-message', L($message)); - } - foreach ($challenges as $challenge) { - $challenge->addAsHtml($resp->doc); - } - $resp->send(); - // instead of just saving this to a file, it needs to be associated with the - // user's session somehow - file_put_contents('challenges-data', serialize($challenges)); -} - -function GET() { - $context = new Psso\Context; - presentChallenges($context); -} - -function POST(array $config) { - // we are receiving results of a previous challenge... load it in - $challenges = unserialize(file_get_contents('challenges-data')); - $answeredChallenge = $challenges[$_POST['challenge']]; - // match up the given input responses to their original Inputs - $inputData = []; - foreach ($_POST as $name => $value) { - if ($name == 'challenge') continue; - $serial = explode('__', $name, 2)[1]; - $input = $answeredChallenge->findInput($serial); - $inputData[$input->id] = $value; - } - - $providerClass = 'Psso\\AuthProvider\\' . $config['auth']['provider']; - $provider = new $providerClass($config); - $result = $answeredChallenge->validate($provider, $inputData); - - $context = $answeredChallenge->context; - $context->addResult($result); - - if ($result->successful) { - if (isset($result->user) && !isset($context->user)) { - $context->user = $result->user; - } - } - presentChallenges($context, $result->message); -} |
