Skip to content

Commit d475ac1

Browse files
authored
feat: add phone to sms webhook payload (#2160)
## What kind of change does this PR introduce? This PR adds the phone number to the SendSMS webhook, when a phone factor is challenged or a phone confirmation is required. ## What is the current behavior? Currently, the SMS webhook only sends the `user_id` and the `otp_code`. However, we have no way of knowing which factor (device) was used in case the send SMS webhook is used for MFA (as opposed to phone confirmation, which uses the user's phone number), and there is more than one device enrolled for a single user. ## What is the new behavior? The webhook payload contains `phone`, which is either the user's phone number for phone confirmation or the factor phone number for MFA with a phone factor. ## Additional context Add any other context or screenshots.
1 parent 1f804a2 commit d475ac1

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

internal/api/mfa.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,15 @@ func (a *API) challengePhoneFactor(w http.ResponseWriter, r *http.Request) error
409409
return apierrors.NewInternalServerError("error generating sms template").WithInternalError(err)
410410
}
411411

412+
phone := factor.Phone.String()
413+
412414
if config.Hook.SendSMS.Enabled {
413415
input := v0hooks.SendSMSInput{
414416
User: user,
415417
SMS: v0hooks.SMS{
416418
OTP: otp,
417419
SMSType: "mfa",
420+
Phone: phone,
418421
},
419422
}
420423
output := v0hooks.SendSMSOutput{}
@@ -428,7 +431,7 @@ func (a *API) challengePhoneFactor(w http.ResponseWriter, r *http.Request) error
428431
return apierrors.NewInternalServerError("Failed to get SMS provider").WithInternalError(err)
429432
}
430433
// We omit messageID for now, can consider reinstating if there are requests.
431-
if _, err = smsProvider.SendMessage(factor.Phone.String(), message, channel, otp); err != nil {
434+
if _, err = smsProvider.SendMessage(phone, message, channel, otp); err != nil {
432435
return apierrors.NewInternalServerError("error sending message").WithInternalError(err)
433436
}
434437
}

internal/api/phone.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func (a *API) sendPhoneConfirmation(r *http.Request, tx *storage.Connection, use
9898
input := v0hooks.SendSMSInput{
9999
User: user,
100100
SMS: v0hooks.SMS{
101-
OTP: otp,
101+
OTP: otp,
102+
Phone: phone,
102103
},
103104
}
104105
output := v0hooks.SendSMSOutput{}

internal/hooks/v0hooks/v0hooks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type AfterUserCreatedOutput struct{}
9595
type SMS struct {
9696
OTP string `json:"otp,omitempty"`
9797
SMSType string `json:"sms_type,omitempty"`
98+
Phone string `json:"phone,omitempty"`
9899
}
99100

100101
// AccessTokenClaims is a struct thats used for JWT claims

0 commit comments

Comments
 (0)