-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #757 from rochamarcelo/feature/u2f
Feature/u2f
- Loading branch information
Showing
25 changed files
with
2,424 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
:major: 8 | ||
:minor: 0 | ||
:patch: 3 | ||
:minor: 1 | ||
:patch: 0 | ||
:special: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
YubicoKey U2F | ||
============= | ||
|
||
Installation | ||
------------ | ||
To enable this feature you need to | ||
|
||
``` | ||
composer require yubico/u2flib-server:^1.0 | ||
``` | ||
|
||
Setup | ||
----- | ||
|
||
Enable it in your bootstrap.php file: | ||
|
||
Config/bootstrap.php | ||
``` | ||
Configure::write('U2f.enabled', true); | ||
``` | ||
|
||
How does it work | ||
---------------- | ||
When the user log-in, he is requested to insert and tap his registered yubico key, | ||
if this is the first time he access he need to register the yubico key. | ||
|
||
Please check the yubico site for more information about U2F | ||
https://developers.yubico.com/U2F/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
config/Migrations/20190208174112_AddAdditionalDataToUsers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
|
||
use Migrations\AbstractMigration; | ||
|
||
class AddAdditionalDataToUsers extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* More information on this method is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-change-method | ||
* @return void | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->table('users'); | ||
$table->addColumn('additional_data', 'text', [ | ||
'default' => null, | ||
'null' => true, | ||
]); | ||
$table->update(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace CakeDC\Users\Auth; | ||
|
||
use Cake\Core\Configure; | ||
|
||
/** | ||
* Default class to check if two factor authentication is enabled and required | ||
* | ||
* @package CakeDC\Users\Auth | ||
*/ | ||
class DefaultU2fAuthenticationChecker implements U2fAuthenticationCheckerInterface | ||
{ | ||
/** | ||
* Check if two factor authentication is enabled | ||
* | ||
* @return bool | ||
*/ | ||
public function isEnabled() | ||
{ | ||
return Configure::read('U2f.enabled') !== false; | ||
} | ||
|
||
/** | ||
* Check if two factor authentication is required for a user | ||
* | ||
* @param array $user user data | ||
* | ||
* @return bool | ||
*/ | ||
public function isRequired(array $user = null) | ||
{ | ||
return !empty($user) && $this->isEnabled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace CakeDC\Users\Auth; | ||
|
||
use Cake\Core\Configure; | ||
use Cake\Network\Exception\BadRequestException; | ||
|
||
/** | ||
* Factory for two authentication checker | ||
* | ||
* @package CakeDC\Users\Auth | ||
*/ | ||
class U2fAuthenticationCheckerFactory | ||
{ | ||
/** | ||
* Get the two factor authentication checker | ||
* | ||
* @return U2fAuthenticationCheckerInterface | ||
*/ | ||
public function build() | ||
{ | ||
$className = Configure::read('U2f.checker'); | ||
$interfaces = class_implements($className); | ||
$required = U2fAuthenticationCheckerInterface::class; | ||
|
||
if (in_array($required, $interfaces)) { | ||
return new $className(); | ||
} | ||
throw new \InvalidArgumentException("Invalid config for 'U2f.checker', '$className' does not implement '$required'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace CakeDC\Users\Auth; | ||
|
||
interface U2fAuthenticationCheckerInterface | ||
{ | ||
/** | ||
* Check if two factor authentication is enabled | ||
* | ||
* @return bool | ||
*/ | ||
public function isEnabled(); | ||
|
||
/** | ||
* Check if two factor authentication is required for a user | ||
* | ||
* @param array $user user data | ||
* | ||
* @return bool | ||
*/ | ||
public function isRequired(array $user = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.