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

fix: add twilio verify support on mfa #1714

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

J0
Copy link
Contributor

@J0 J0 commented Aug 6, 2024

What kind of change does this PR introduce?

We don't store the OTP with Twilio Verify and will need to do the check with Twilio if we want to support it

Comment on lines +596 to +603
if config.Sms.IsTwilioVerifyProvider() {
smsProvider, _ := sms_provider.GetSmsProvider(*config)
if err := smsProvider.(*sms_provider.TwilioVerifyProvider).VerifyOTP(factor.Phone.String(), nonce); err != nil {
return forbiddenError(ErrorCodeOTPExpired, "Token has expired or is invalid").WithInternalError(err)
}
valid = true
} else {
otpCode, shouldReEncrypt, err = challenge.GetOtpCode(config.Security.DBEncryption.DecryptionKeys, config.Security.DBEncryption.Encrypt, config.Security.DBEncryption.EncryptionKeyID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are still working on this, but I did notice this code below could panic since the err is dropped in smsProvider, _ := sms_provider.GetSmsProvider(*config). Maybe we could hoist that to the block above. Since it appears this is checking for an optional interface, we could add one:

type SmsProvider interface {
	SendMessage(phone, message, channel, otp string) (string, error)
}

type SmsProviderVerifier interface {
	 VerifyOTP(phone, code string) error
}

Then check the optional interface in below:

Suggested change
if config.Sms.IsTwilioVerifyProvider() {
smsProvider, _ := sms_provider.GetSmsProvider(*config)
if err := smsProvider.(*sms_provider.TwilioVerifyProvider).VerifyOTP(factor.Phone.String(), nonce); err != nil {
return forbiddenError(ErrorCodeOTPExpired, "Token has expired or is invalid").WithInternalError(err)
}
valid = true
} else {
otpCode, shouldReEncrypt, err = challenge.GetOtpCode(config.Security.DBEncryption.DecryptionKeys, config.Security.DBEncryption.Encrypt, config.Security.DBEncryption.EncryptionKeyID)
smsProvider, err := sms_provider.GetSmsProvider(*config)
if err == nil { ... }
if vr, ok := smsProvider.(sms_provider.SmsProviderVerifier); ok {
if err := vr.VerifyOTP(factor.Phone.String(), code); err != nil {
return forbiddenError(ErrorCodeOTPExpired,
"Token has expired or is invalid").WithInternalError(err)
}
valid = true
} else {
otpCode, shouldReEncrypt, err = ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion, thanks!

Yeah unfortunately haven't had time to close this one out, will do so after finishing MFA for WebAuthn hopefully

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