-
Notifications
You must be signed in to change notification settings - Fork 296
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
base: 11.next-cake4
Are you sure you want to change the base?
Conversation
4d1e295
to
adceb67
Compare
adceb67
to
35862b1
Compare
35862b1
to
8bb108a
Compare
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.
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'), |
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.
I don't think the {0} and {1} will work here as expected.
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.
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)) { |
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.
Will this work with any country? if not we may need to move this so the app can extend
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.
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()); |
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.
Are we sure that we will not show bad error messages like database error or expose file path?
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.
only specific exceptions are catched now
try { | ||
$OtpCodes->sendCode2f($data['user']['id'], $resend); | ||
} catch (\Exception $e) { | ||
$this->Flash->error($e->getMessage()); |
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.
Are we sure that we will not show bad error messages like database error or expose file path?
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.
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 |
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.
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.
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.
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.
9f48763
to
65c8c45
Compare
65c8c45
to
ef3a33e
Compare
42d6d14
to
4a02570
Compare
No description provided.