Skip to content
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

Initial OTP implementation #981

Draft
wants to merge 9 commits into
base: 11.next-cake4
Choose a base branch
from
Draft

Conversation

ajibarra
Copy link
Member

No description provided.

@ajibarra ajibarra changed the base branch from master to 11.next-cake4 February 18, 2022 10:10
Copy link
Collaborator

@rochamarcelo rochamarcelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have an READ ME file.

config/users.php Outdated
'checker' => \CakeDC\Auth\Authentication\DefaultCode2fAuthenticationChecker::class,
'type' => \CakeDC\Auth\Authentication\Code2fAuthenticationCheckerInterface::CODE2F_TYPE_EMAIL,
'config' => 'default',
'message' => __d('cake_d_c/users', '{0} is your {1} verification code'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the {0} and {1} will work here as expected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed _d( since we will replace {0} with code and {1} with App Name. Added a comment in users.php.

if ($this->getRequest()->is(['post', 'put'])) {

$value = $this->getRequest()->getData($field);
if ($data['field'] === Code2fAuthenticationCheckerInterface::CODE2F_TYPE_PHONE && !preg_match('/^\+[1-9]\d{1,14}$/i', $value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work with any country? if not we may need to move this so the app can extend

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am moving this to a config since it works with any country but may not work with any sms service. Defaulting on Twilio to the current one.

$this->request->getSession()->write(TwoFactorAuthenticator::USER_SESSION_KEY, $data['user']);
return $this->redirectWithQuery(Configure::read('Auth.AuthenticationComponent.loginAction'));
} catch (\Exception $e) {
$this->Flash->error($e->getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we will not show bad error messages like database error or expose file path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only specific exceptions are catched now

try {
$OtpCodes->sendCode2f($data['user']['id'], $resend);
} catch (\Exception $e) {
$this->Flash->error($e->getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we will not show bad error messages like database error or expose file path?

Copy link
Member Author

@ajibarra ajibarra Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have encapsulated potential exceptions logging them and throwing new ones with generic messages. Additionally only specific exceptions are catched now

use Cake\Mailer\Message;
use Twilio\Rest\Client;

class TwilioTransport extends AbstractTransport
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this tranport class? I see twilio is required in composer but I don't see when we are using this in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, this is the default transport class provided to users who wants otp with SMS out of the box. They can always implement a new transport or use email of course.

@ajibarra ajibarra force-pushed the feature/otp-7cake4 branch 2 times, most recently from 9f48763 to 65c8c45 Compare February 25, 2022 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants