mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +00:00
feat: Add Twilio Verification Service (#8678)
# Which Problems Are Solved Twilio supports a robust, multi-channel verification service that notably supports multi-region SMS sender numbers required for our use case. Currently, Zitadel does much of the work of the Twilio Verify (eg. localization, code generation, messaging) but doesn't support the pool of sender numbers that Twilio Verify does. # How the Problems Are Solved To support this API, we need to be able to store the Twilio Service ID and send that in a verification request where appropriate: phone number verification and SMS 2FA code paths. This PR does the following: - Adds the ability to use Twilio Verify of standard messaging through Twilio - Adds support for international numbers and more reliable verification messages sent from multiple numbers - Adds a new Twilio configuration option to support Twilio Verify in the admin console - Sends verification SMS messages through Twilio Verify - Implements Twilio Verification Checks for codes generated through the same # Additional Changes # Additional Context - base was implemented by @zhirschtritt in https://github.com/zitadel/zitadel/pull/8268 ❤️ - closes https://github.com/zitadel/zitadel/issues/8581 --------- Co-authored-by: Zachary Hirschtritt <zachary.hirschtritt@klaviyo.com> Co-authored-by: Joey Biscoglia <joey.biscoglia@klaviyo.com>
This commit is contained in:
@@ -222,7 +222,8 @@ func (wm *UserV3WriteModel) NewCreated(
|
||||
data json.RawMessage,
|
||||
email *Email,
|
||||
phone *Phone,
|
||||
code func(context.Context) (*EncryptedCode, error),
|
||||
emailCode func(context.Context) (*EncryptedCode, error),
|
||||
phoneCode func(context.Context) (*EncryptedCode, string, error),
|
||||
) (_ []eventstore.Command, codeEmail string, codePhone string, err error) {
|
||||
if err := wm.checkPermissionWrite(ctx, wm.ResourceOwner, wm.AggregateID); err != nil {
|
||||
return nil, "", "", err
|
||||
@@ -239,7 +240,7 @@ func (wm *UserV3WriteModel) NewCreated(
|
||||
if email != nil {
|
||||
emailEvents, plainCodeEmail, err := wm.NewEmailCreate(ctx,
|
||||
email,
|
||||
code,
|
||||
emailCode,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
@@ -253,7 +254,7 @@ func (wm *UserV3WriteModel) NewCreated(
|
||||
if phone != nil {
|
||||
phoneEvents, plainCodePhone, err := wm.NewPhoneCreate(ctx,
|
||||
phone,
|
||||
code,
|
||||
phoneCode,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
@@ -310,7 +311,8 @@ func (wm *UserV3WriteModel) NewUpdate(
|
||||
user *SchemaUser,
|
||||
email *Email,
|
||||
phone *Phone,
|
||||
code func(context.Context) (*EncryptedCode, error),
|
||||
emailCode func(context.Context) (*EncryptedCode, error),
|
||||
phoneCode func(context.Context) (*EncryptedCode, string, error),
|
||||
) (_ []eventstore.Command, codeEmail string, codePhone string, err error) {
|
||||
if err := wm.checkPermissionWrite(ctx, wm.ResourceOwner, wm.AggregateID); err != nil {
|
||||
return nil, "", "", err
|
||||
@@ -334,7 +336,7 @@ func (wm *UserV3WriteModel) NewUpdate(
|
||||
if email != nil {
|
||||
emailEvents, plainCodeEmail, err := wm.NewEmailUpdate(ctx,
|
||||
email,
|
||||
code,
|
||||
emailCode,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
@@ -348,7 +350,7 @@ func (wm *UserV3WriteModel) NewUpdate(
|
||||
if phone != nil {
|
||||
phoneEvents, plainCodePhone, err := wm.NewPhoneCreate(ctx,
|
||||
phone,
|
||||
code,
|
||||
phoneCode,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
@@ -564,7 +566,7 @@ func (wm *UserV3WriteModel) newEmailCodeAddedEvent(
|
||||
func (wm *UserV3WriteModel) NewPhoneCreate(
|
||||
ctx context.Context,
|
||||
phone *Phone,
|
||||
code func(context.Context) (*EncryptedCode, error),
|
||||
code func(context.Context) (*EncryptedCode, string, error),
|
||||
) (_ []eventstore.Command, plainCode string, err error) {
|
||||
if err := wm.checkPermissionWrite(ctx, wm.ResourceOwner, wm.AggregateID); err != nil {
|
||||
return nil, "", err
|
||||
@@ -596,7 +598,7 @@ func (wm *UserV3WriteModel) NewPhoneCreate(
|
||||
func (wm *UserV3WriteModel) NewPhoneUpdate(
|
||||
ctx context.Context,
|
||||
phone *Phone,
|
||||
code func(context.Context) (*EncryptedCode, error),
|
||||
code func(context.Context) (*EncryptedCode, string, error),
|
||||
) (_ []eventstore.Command, plainCode string, err error) {
|
||||
if !wm.PhoneWM {
|
||||
return nil, "", nil
|
||||
@@ -637,7 +639,7 @@ func (wm *UserV3WriteModel) newPhoneVerifiedEvent(
|
||||
|
||||
func (wm *UserV3WriteModel) NewResendPhoneCode(
|
||||
ctx context.Context,
|
||||
code func(context.Context) (*EncryptedCode, error),
|
||||
code func(context.Context) (*EncryptedCode, string, error),
|
||||
isReturnCode bool,
|
||||
) (_ []eventstore.Command, plainCode string, err error) {
|
||||
if !wm.PhoneWM {
|
||||
@@ -661,10 +663,10 @@ func (wm *UserV3WriteModel) NewResendPhoneCode(
|
||||
|
||||
func (wm *UserV3WriteModel) newPhoneCodeAddedEvent(
|
||||
ctx context.Context,
|
||||
code func(context.Context) (*EncryptedCode, error),
|
||||
code func(context.Context) (*EncryptedCode, string, error),
|
||||
isReturnCode bool,
|
||||
) (_ *schemauser.PhoneCodeAddedEvent, plainCode string, err error) {
|
||||
cryptoCode, err := code(ctx)
|
||||
cryptoCode, generatorID, err := code(ctx)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -673,8 +675,9 @@ func (wm *UserV3WriteModel) newPhoneCodeAddedEvent(
|
||||
}
|
||||
return schemauser.NewPhoneCodeAddedEvent(ctx,
|
||||
UserV3AggregateFromWriteModel(&wm.WriteModel),
|
||||
cryptoCode.Crypted,
|
||||
cryptoCode.Expiry,
|
||||
cryptoCode.CryptedCode(),
|
||||
cryptoCode.CodeExpiry(),
|
||||
isReturnCode,
|
||||
generatorID,
|
||||
), plainCode, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user