From b422b6ded608807c7d3bb8b965b3797ca513610b Mon Sep 17 00:00:00 2001 From: winter Sparkles Date: Sat, 8 Aug 2026 23:01:51 +0100 Subject: implement a large chunk of the auth system itself :D --- routes/index.php | 2 +- routes/test-challenges.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 routes/test-challenges.php (limited to 'routes') diff --git a/routes/index.php b/routes/index.php index a5e66a8..685ab92 100644 --- a/routes/index.php +++ b/routes/index.php @@ -1,7 +1,7 @@ doc->addChild('content'); $content->addChild('p', 'Welcome to Pleasant SSO!'); $resp->send(); diff --git a/routes/test-challenges.php b/routes/test-challenges.php new file mode 100644 index 0000000..32aad7e --- /dev/null +++ b/routes/test-challenges.php @@ -0,0 +1,67 @@ +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); +} -- cgit v1.3