-
Notifications
You must be signed in to change notification settings - Fork 349
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
base: master
Are you sure you want to change the base?
Conversation
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) |
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 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:
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 = ... |
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.
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
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