Skip to content

Commit

Permalink
fix: update mfa provider
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 30, 2024
1 parent 0ca3f7d commit c112b4b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/api/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,9 @@ func (a *API) verifyPhoneFactor(w http.ResponseWriter, r *http.Request, params *
var valid bool
var otpCode string
var shouldReEncrypt bool
var err error
if config.Sms.IsTwilioVerifyProvider() {
smsProvider, _ := sms_provider.GetSmsProvider(*config)
if err := smsProvider.(*sms_provider.TwilioVerifyProvider).VerifyOTP(factor.Phone.String(), nonce); err != nil {
if err := smsProvider.VerifyOTP(factor.Phone.String(), params.Code); err != nil {
return forbiddenError(ErrorCodeOTPExpired, "Token has expired or is invalid").WithInternalError(err)
}
valid = true
Expand Down
4 changes: 4 additions & 0 deletions internal/api/sms_provider/messagebird.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ func (t *MessagebirdProvider) SendSms(phone string, message string) (string, err

return resp.ID, nil
}

func (t *MessagebirdProvider) VerifyOTP(phone, code string) error {
return fmt.Errorf("VerifyOTP is not supported for Messagebird")
}
1 change: 1 addition & 0 deletions internal/api/sms_provider/sms_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {

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

func GetSmsProvider(config conf.GlobalConfiguration) (SmsProvider, error) {
Expand Down
3 changes: 3 additions & 0 deletions internal/api/sms_provider/textlocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ func (t *TextlocalProvider) SendSms(phone string, message string) (string, error

return messageID, nil
}
func (t *TextlocalProvider) VerifyOTP(phone, code string) error {
return fmt.Errorf("VerifyOTP is not supported for Textlocal")
}
3 changes: 3 additions & 0 deletions internal/api/sms_provider/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ func (t *TwilioProvider) SendSms(phone, message, channel, otp string) (string, e

return resp.MessageSID, nil
}
func (t *TwilioProvider) VerifyOTP(phone, code string) error {
return fmt.Errorf("VerifyOTP is not supported for Twilio")
}
4 changes: 4 additions & 0 deletions internal/api/sms_provider/vonage.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ func (t *VonageProvider) SendSms(phone string, message string) (string, error) {

return resp.Messages[0].MessageID, nil
}

func (t *VonageProvider) VerifyOTP(phone, code string) error {
return fmt.Errorf("VerifyOTP is not supported for Vonage")
}

0 comments on commit c112b4b

Please sign in to comment.