aboutsummaryrefslogtreecommitdiff
path: root/routes/test-challenges.php
diff options
context:
space:
mode:
Diffstat (limited to 'routes/test-challenges.php')
-rw-r--r--routes/test-challenges.php67
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);
-}