diff --git a/classes/login/TestLogin.php b/classes/login/TestLogin.php new file mode 100644 index 0000000000000000000000000000000000000000..f0a4fb12513d0797116b162b901c3f2989ecd07e --- /dev/null +++ b/classes/login/TestLogin.php @@ -0,0 +1,34 @@ +<?php + +namespace RAP; + +class TestLogin extends LoginHandler { + + private $fakeIdentities = []; + + public function __construct(Locator $locator) { + parent::__construct($locator); + + // Create fake identities + $this->fakeIdentities[1] = $this->getFakeIdentity(Identity::EDU_GAIN, 1); + $this->fakeIdentities[2] = $this->getFakeIdentity(Identity::GOOGLE, 2); + $this->fakeIdentities[3] = $this->getFakeIdentity(Identity::LINKEDIN, 3); + } + + public function login(): string { + return $this->locator->getBasePath() . '/auth/test/select'; + } + + public function retrieveToken(int $id): string { + return $this->onIdentityDataReceived($this->fakeIdentities[$id]); + } + + private function getFakeIdentity(string $type, int $i): Identity { + $identity = new Identity($type); + $identity->email = 'fake-user' . $i . "@example.com"; + $identity->eppn = $identity->email; + $identity->typedId = 'fake-user' . $i; + return $identity; + } + +} diff --git a/classes/model/AuthPageModel.php b/classes/model/AuthPageModel.php index 05ed340ea61e03be4d26b9c8315a2cb7ea085d88..4c73c837b5d75c699a215c65671b3c864e3f5b1d 100644 --- a/classes/model/AuthPageModel.php +++ b/classes/model/AuthPageModel.php @@ -15,6 +15,7 @@ class AuthPageModel { public $facebook; public $linkedIn; public $localIdP; + public $test; // public $clientIcon; public $clientTitle; @@ -58,6 +59,9 @@ class AuthPageModel { $this->localIdP = isset($config->authenticationMethods->LocalIdP) && in_array(AuthenticationMethods::LOCAL_IDP, $client->authMethods); + + $this->test = isset($config->authenticationMethods->test) && + $config->authenticationMethods->test; } } diff --git a/include/front-controller.php b/include/front-controller.php index 7d7180fcb53a70c3897bf295c791fe1196614602..956e6bddab6f3bd746e0572969be4b4274b52d4c 100644 --- a/include/front-controller.php +++ b/include/front-controller.php @@ -224,6 +224,28 @@ Flight::route('/auth/x509', function() { $x509Login->login(); }); +Flight::route('GET /auth/test', function() { + session_start(); + global $locator; + $testLogin = new \RAP\TestLogin($locator); + Flight::redirect($testLogin->login()); +}); + +Flight::route('GET /auth/test/select', function() { + global $locator; + Flight::render('test-login.php', array('title' => 'Test login (demo)', + 'version' => $locator->getVersion(), + 'contextRoot' => $locator->config->contextRoot)); +}); + +Flight::route('POST /auth/test/token', function() { + session_start(); + global $locator; + $testLogin = new \RAP\TestLogin($locator); + $id = filter_input(INPUT_POST, 'user_id', FILTER_SANITIZE_NUMBER_INT); + Flight::redirect($testLogin->retrieveToken($id)); +}); + Flight::route('/local', function() { global $locator; Flight::redirect($locator->config->authenticationMethods->LocalIdP->url); diff --git a/views/main-page.php b/views/main-page.php index d069a7a22e94329f55313ea8b84dd0c018ead63a..5d2207c7f3c61544eb04270070b582706d649c9b 100644 --- a/views/main-page.php +++ b/views/main-page.php @@ -78,6 +78,16 @@ include 'include/header.php'; <?php echo $model->localIdPConfig->description; ?> </div> <?php } ?> + <?php if ($model->test) { ?> + <div class="home-box"> + <div class="img-wrapper"> + <a href="auth/test"> + <strong>Test Login</strong> + </a> + </div> + Use fake accounts + </div> + <?php } ?> </div> </div> diff --git a/views/test-login.php b/views/test-login.php new file mode 100644 index 0000000000000000000000000000000000000000..a16a90c5f223215a6814a3e3d1606d0afaf94662 --- /dev/null +++ b/views/test-login.php @@ -0,0 +1,22 @@ +<?php +include 'include/header.php'; +?> +<script src="js/index.js?v=<?php echo $version; ?>"></script> + +<h2 class="text-center">Test login</h2> + +<form class="col-xs-6 col-xs-offset-3" method="POST" action="<?php echo $contextRoot . '/auth/test/token'; ?>"> + <p>Select fake user:</p> + + <select class="form-control" name="user_id"> + <option value="1">Fake User 1 (eduGAIN)</option> + <option value="2">Fake User 2 (Google)</option> + <option value="3">Fake User 3 (LinkedIn)</option> + </select> + <br/> + <input type="submit" value="Login" class="btn btn-success" /> + <br/><br/> +</form> + +<?php +include 'include/footer.php';