mirror of
https://github.com/ChristophWurst/twofactor_test
synced 2025-10-03 09:19:15 +02:00
initial commit
This commit is contained in:
commit
ad8a9d51b9
4 changed files with 123 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# twofactor_test
|
||||||
|
|
||||||
|
Dummy 2FA provider to test ownCloud's 2FA
|
23
appinfo/info.xml
Normal file
23
appinfo/info.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<info>
|
||||||
|
<id>twofactor_test</id>
|
||||||
|
<name>Two Factor Test Provider</name>
|
||||||
|
<description>An Two-Factor-Auth Test Provider for ownCloud 9.1</description>
|
||||||
|
<licence>AGPL</licence>
|
||||||
|
<author>Christoph Wurst</author>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<namespace>TwoFactor_Test</namespace>
|
||||||
|
<category>other</category>
|
||||||
|
<types>
|
||||||
|
<prelogin/>
|
||||||
|
<authentication/>
|
||||||
|
</types>
|
||||||
|
|
||||||
|
<two-factor-providers>
|
||||||
|
<provider>OCA\TwoFactor_Test\Provider\TwoFactorTestProvider</provider>
|
||||||
|
</two-factor-providers>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<owncloud min-version="9.1" max-version="9.1" />
|
||||||
|
</dependencies>
|
||||||
|
</info>
|
92
lib/Provider/TwoFactorTestProvider.php
Normal file
92
lib/Provider/TwoFactorTestProvider.php
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Wurst <christoph@owncloud.com>
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
|
* @license AGPL-3.0
|
||||||
|
*
|
||||||
|
* This code is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\TwoFactor_Test\Provider;
|
||||||
|
|
||||||
|
use OCP\Authentication\TwoFactorAuth\IProvider;
|
||||||
|
use OCP\IUser;
|
||||||
|
use OCP\Template;
|
||||||
|
|
||||||
|
class TwoFactorTestProvider implements IProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unique identifier of this 2FA provider
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return 'test';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the display name for selecting the 2FA provider
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDisplayName() {
|
||||||
|
return 'Test';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the description for selecting the 2FA provider
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDescription() {
|
||||||
|
return 'Use a test provider';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the template for rending the 2FA provider view
|
||||||
|
*
|
||||||
|
* @param IUser $user
|
||||||
|
* @return Template
|
||||||
|
*/
|
||||||
|
public function getTemplate(IUser $user) {
|
||||||
|
return new Template('twofactor_test', 'challenge');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the given challenge
|
||||||
|
*
|
||||||
|
* @param IUser $user
|
||||||
|
* @param string $challenge
|
||||||
|
*/
|
||||||
|
public function verifyChallenge(IUser $user, $challenge) {
|
||||||
|
if ($challenge === 'passme') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decides whether 2FA is enabled for the given user
|
||||||
|
*
|
||||||
|
* @param IUser $user
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isTwoFactorAuthEnabledForUser(IUser $user) {
|
||||||
|
// 2FA is enforced for all users
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
5
templates/challenge.php
Normal file
5
templates/challenge.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="redirect_url" value="<?php p($_['redirect_url']); ?>">
|
||||||
|
<input type="text" name="challenge" value="passme" required="required">
|
||||||
|
<input type="submit" class="button" value="Verify">
|
||||||
|
</form>
|
Loading…
Add table
Add a link
Reference in a new issue