-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '9.next-cake4' into 10.next-cake5
- Loading branch information
Showing
24 changed files
with
538 additions
and
90 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.bat] | ||
end_of_line = crlf | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Two Factor (2FA) | ||
================ | ||
|
||
Two-factor authentication (2FA) is an identity and access management security method that requires two forms of identification to access resources and data. 2FA gives businesses the ability to monitor and help safeguard their most vulnerable information and networks. | ||
|
||
Configuration | ||
------------- | ||
|
||
Processors defined as Configure storage with key `TwoFactorProcessors` | ||
|
||
|
||
Processors | ||
------------- | ||
|
||
* `OneTimePassword` - Authenticator is an authenticator app used as part of a two-factor/multi-factor authentication (2FA/MFA) scheme. It acts as an example of a “something you have” factor by generating one-time passwords (OTPs) on a smartphone or other mobile device. | ||
* `Webauthn2fa` - WebAuthn is a browser-based API that allows for web applications to simplify and secure user authentication by using registered devices (phones, laptops, etc) as factors. It uses public key cryptography to protect users from advanced phishing attacks. |
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
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
115 changes: 115 additions & 0 deletions
115
src/Authentication/TwoFactorProcessor/OneTimePasswordProcessor.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,115 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright 2010 - 2024, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2024, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace CakeDC\Auth\Authentication\TwoFactorProcessor; | ||
|
||
use Authentication\Authenticator\Result; | ||
use Authentication\Authenticator\ResultInterface; | ||
use Cake\Core\Configure; | ||
use CakeDC\Auth\Authentication\OneTimePasswordAuthenticationCheckerFactory; | ||
use CakeDC\Auth\Authentication\OneTimePasswordAuthenticationCheckerInterface; | ||
use CakeDC\Auth\Authentication\TwoFactorProcessorInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
/** | ||
* OneTimePasswordProcessor class | ||
*/ | ||
class OneTimePasswordProcessor implements TwoFactorProcessorInterface | ||
{ | ||
public const NEED_TWO_FACTOR_VERIFY = 'NEED_TWO_FACTOR_VERIFY'; | ||
|
||
public const TWO_FACTOR_VERIFY_SESSION_KEY = 'temporarySession'; | ||
|
||
/** | ||
* Returns processor type. | ||
* | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return self::NEED_TWO_FACTOR_VERIFY; | ||
} | ||
|
||
/** | ||
* Returns processor session key. | ||
* | ||
* @return string | ||
*/ | ||
public function getSessionKey(): string | ||
{ | ||
return self::TWO_FACTOR_VERIFY_SESSION_KEY; | ||
} | ||
|
||
/** | ||
* Processor status detector. | ||
* | ||
* @return bool | ||
*/ | ||
public function enabled(): bool | ||
{ | ||
return Configure::read('OneTimePasswordAuthenticator.login') !== false; | ||
} | ||
|
||
/** | ||
* Processor status detector. | ||
* | ||
* @return bool | ||
*/ | ||
public function isRequired(array $userData): bool | ||
{ | ||
return $this->getOneTimePasswordAuthenticationChecker()->isRequired($userData); | ||
} | ||
|
||
/** | ||
* Proceed to 2fa processor after a valid result result. | ||
* | ||
* @param \Psr\Http\Message\ServerRequestInterface $request Request instance. | ||
* @param \Authentication\Authenticator\ResultInterface $result Input result object. | ||
* @return \Authentication\Authenticator\ResultInterface | ||
*/ | ||
public function proceed(ServerRequestInterface $request, ResultInterface $result): ResultInterface | ||
{ | ||
/** | ||
* @var \Cake\Http\Session $session | ||
*/ | ||
$session = $request->getAttribute('session'); | ||
$session->write($this->getSessionKey(), $result->getData()); | ||
$result = new Result(null, $this->getType()); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Generates 2fa url, if enable. | ||
* | ||
* @param string $type Processor type. | ||
* @return array|null | ||
*/ | ||
public function getUrlByType(string $type): ?array | ||
{ | ||
if ($type == $this->getType()) { | ||
return Configure::read('OneTimePasswordAuthenticator.verifyAction'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get the configured one-time password authentication checker | ||
* | ||
* @return \CakeDC\Auth\Authentication\OneTimePasswordAuthenticationCheckerInterface | ||
*/ | ||
protected function getOneTimePasswordAuthenticationChecker(): OneTimePasswordAuthenticationCheckerInterface | ||
{ | ||
return (new OneTimePasswordAuthenticationCheckerFactory())->build(); | ||
} | ||
} |
Oops, something went wrong.