-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two factor refactoring. #86
Open
skie
wants to merge
7
commits into
7.next-cake4
Choose a base branch
from
feature/two-factor-refactoring
base: 7.next-cake4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
41fd79f
extract two factor logic into separate classes processing each type o…
skie d966e8f
update workflow
skie e25f32d
remove obsolete php versions
skie cb40f03
update ubuntu version
skie 288976a
update code checker php version
skie e2e91f9
codestyle fix
skie 91fede5
add documentation. update changelog.
skie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@ | ||
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 | ||
------------- | ||
|
||
* `U2FProcessor` - *deprecated*. Universal 2nd Factor (U2F) is an open standard that strengthens and simplifies two-factor authentication (2FA) using specialized Universal Serial Bus (USB) or near-field communication (NFC) devices based on similar security technology found in smart cards. | ||
* `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
114 changes: 114 additions & 0 deletions
114
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,114 @@ | ||
<?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\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() | ||
{ | ||
return (new OneTimePasswordAuthenticationCheckerFactory())->build(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add 8.2 and 8.3