mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:47:33 +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:
@@ -25,12 +25,13 @@ const (
|
||||
SMSColumnInstanceID = "instance_id"
|
||||
SMSColumnDescription = "description"
|
||||
|
||||
smsTwilioTableSuffix = "twilio"
|
||||
SMSTwilioColumnSMSID = "sms_id"
|
||||
SMSTwilioColumnInstanceID = "instance_id"
|
||||
SMSTwilioColumnSID = "sid"
|
||||
SMSTwilioColumnSenderNumber = "sender_number"
|
||||
SMSTwilioColumnToken = "token"
|
||||
smsTwilioTableSuffix = "twilio"
|
||||
SMSTwilioColumnSMSID = "sms_id"
|
||||
SMSTwilioColumnInstanceID = "instance_id"
|
||||
SMSTwilioColumnSID = "sid"
|
||||
SMSTwilioColumnSenderNumber = "sender_number"
|
||||
SMSTwilioColumnToken = "token"
|
||||
SMSTwilioColumnVerifyServiceSID = "verify_service_sid"
|
||||
|
||||
smsHTTPTableSuffix = "http"
|
||||
SMSHTTPColumnSMSID = "sms_id"
|
||||
@@ -69,6 +70,7 @@ func (*smsConfigProjection) Init() *old_handler.Check {
|
||||
handler.NewColumn(SMSTwilioColumnSID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSTwilioColumnSenderNumber, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSTwilioColumnToken, handler.ColumnTypeJSONB),
|
||||
handler.NewColumn(SMSTwilioColumnVerifyServiceSID, handler.ColumnTypeText),
|
||||
},
|
||||
handler.NewPrimaryKey(SMSTwilioColumnInstanceID, SMSTwilioColumnSMSID),
|
||||
smsTwilioTableSuffix,
|
||||
@@ -172,6 +174,7 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioAdded(event eventstore.Event)
|
||||
handler.NewCol(SMSTwilioColumnSID, e.SID),
|
||||
handler.NewCol(SMSTwilioColumnToken, e.Token),
|
||||
handler.NewCol(SMSTwilioColumnSenderNumber, e.SenderNumber),
|
||||
handler.NewCol(SMSTwilioColumnVerifyServiceSID, e.VerifyServiceSID),
|
||||
},
|
||||
handler.WithTableSuffix(smsTwilioTableSuffix),
|
||||
),
|
||||
@@ -202,13 +205,16 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioChanged(event eventstore.Even
|
||||
))
|
||||
}
|
||||
|
||||
twilioColumns := make([]handler.Column, 0)
|
||||
twilioColumns := make([]handler.Column, 0, 3)
|
||||
if e.SID != nil {
|
||||
twilioColumns = append(twilioColumns, handler.NewCol(SMSTwilioColumnSID, *e.SID))
|
||||
}
|
||||
if e.SenderNumber != nil {
|
||||
twilioColumns = append(twilioColumns, handler.NewCol(SMSTwilioColumnSenderNumber, *e.SenderNumber))
|
||||
}
|
||||
if e.VerifyServiceSID != nil {
|
||||
twilioColumns = append(twilioColumns, handler.NewCol(SMSTwilioColumnVerifyServiceSID, *e.VerifyServiceSID))
|
||||
}
|
||||
if len(twilioColumns) > 0 {
|
||||
stmts = append(stmts, handler.AddUpdateStatement(
|
||||
twilioColumns,
|
||||
|
@@ -38,7 +38,8 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
"crypted": "Y3J5cHRlZA=="
|
||||
},
|
||||
"senderNumber": "sender-number",
|
||||
"description": "description"
|
||||
"description": "description",
|
||||
"verifyServiceSid": "verify-service-sid"
|
||||
}`),
|
||||
), eventstore.GenericEventMapper[instance.SMSConfigTwilioAddedEvent]),
|
||||
},
|
||||
@@ -63,7 +64,7 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.sms_configs3_twilio (sms_id, instance_id, sid, token, sender_number) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.sms_configs3_twilio (sms_id, instance_id, sid, token, sender_number, verify_service_sid) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
expectedArgs: []interface{}{
|
||||
"id",
|
||||
"instance-id",
|
||||
@@ -75,6 +76,7 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
Crypted: []byte("crypted"),
|
||||
},
|
||||
"sender-number",
|
||||
"verify-service-sid",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -92,7 +94,8 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
"id": "id",
|
||||
"sid": "sid",
|
||||
"senderNumber": "sender-number",
|
||||
"description": "description"
|
||||
"description": "description",
|
||||
"verifyServiceSid": "verify-service-sid"
|
||||
}`),
|
||||
), eventstore.GenericEventMapper[instance.SMSConfigTwilioChangedEvent]),
|
||||
},
|
||||
@@ -113,10 +116,11 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.sms_configs3_twilio SET (sid, sender_number) = ($1, $2) WHERE (sms_id = $3) AND (instance_id = $4)",
|
||||
expectedStmt: "UPDATE projections.sms_configs3_twilio SET (sid, sender_number, verify_service_sid) = ($1, $2, $3) WHERE (sms_id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"sid",
|
||||
"sender-number",
|
||||
"verify-service-sid",
|
||||
"id",
|
||||
"instance-id",
|
||||
},
|
||||
@@ -248,6 +252,46 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceSMSConfigTwilioChanged, only sid",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigTwilioChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id",
|
||||
"verifyServiceSid": "verify-service-sid"
|
||||
}`),
|
||||
), eventstore.GenericEventMapper[instance.SMSConfigTwilioChangedEvent]),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigTwilioChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.sms_configs3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.sms_configs3_twilio SET verify_service_sid = $1 WHERE (sms_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"verify-service-sid",
|
||||
"id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceSMSHTTPAdded",
|
||||
args: args{
|
||||
|
@@ -37,9 +37,10 @@ type SMSConfig struct {
|
||||
}
|
||||
|
||||
type Twilio struct {
|
||||
SID string
|
||||
Token *crypto.CryptoValue
|
||||
SenderNumber string
|
||||
SID string
|
||||
Token *crypto.CryptoValue
|
||||
SenderNumber string
|
||||
VerifyServiceSID string
|
||||
}
|
||||
|
||||
type HTTP struct {
|
||||
@@ -123,6 +124,10 @@ var (
|
||||
name: projection.SMSTwilioColumnSenderNumber,
|
||||
table: smsTwilioTable,
|
||||
}
|
||||
SMSTwilioColumnVerifyServiceSID = Column{
|
||||
name: projection.SMSTwilioColumnVerifyServiceSID,
|
||||
table: smsTwilioTable,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -227,6 +232,7 @@ func prepareSMSConfigQuery(ctx context.Context, db prepareDatabase) (sq.SelectBu
|
||||
SMSTwilioColumnSID.identifier(),
|
||||
SMSTwilioColumnToken.identifier(),
|
||||
SMSTwilioColumnSenderNumber.identifier(),
|
||||
SMSTwilioColumnVerifyServiceSID.identifier(),
|
||||
|
||||
SMSHTTPColumnSMSID.identifier(),
|
||||
SMSHTTPColumnEndpoint.identifier(),
|
||||
@@ -255,6 +261,7 @@ func prepareSMSConfigQuery(ctx context.Context, db prepareDatabase) (sq.SelectBu
|
||||
&twilioConfig.sid,
|
||||
&twilioConfig.token,
|
||||
&twilioConfig.senderNumber,
|
||||
&twilioConfig.verifyServiceSid,
|
||||
|
||||
&httpConfig.id,
|
||||
&httpConfig.endpoint,
|
||||
@@ -289,6 +296,7 @@ func prepareSMSConfigsQuery(ctx context.Context, db prepareDatabase) (sq.SelectB
|
||||
SMSTwilioColumnSID.identifier(),
|
||||
SMSTwilioColumnToken.identifier(),
|
||||
SMSTwilioColumnSenderNumber.identifier(),
|
||||
SMSTwilioColumnVerifyServiceSID.identifier(),
|
||||
|
||||
SMSHTTPColumnSMSID.identifier(),
|
||||
SMSHTTPColumnEndpoint.identifier(),
|
||||
@@ -321,6 +329,7 @@ func prepareSMSConfigsQuery(ctx context.Context, db prepareDatabase) (sq.SelectB
|
||||
&twilioConfig.sid,
|
||||
&twilioConfig.token,
|
||||
&twilioConfig.senderNumber,
|
||||
&twilioConfig.verifyServiceSid,
|
||||
|
||||
&httpConfig.id,
|
||||
&httpConfig.endpoint,
|
||||
@@ -343,10 +352,11 @@ func prepareSMSConfigsQuery(ctx context.Context, db prepareDatabase) (sq.SelectB
|
||||
}
|
||||
|
||||
type sqlTwilioConfig struct {
|
||||
smsID sql.NullString
|
||||
sid sql.NullString
|
||||
token *crypto.CryptoValue
|
||||
senderNumber sql.NullString
|
||||
smsID sql.NullString
|
||||
sid sql.NullString
|
||||
token *crypto.CryptoValue
|
||||
senderNumber sql.NullString
|
||||
verifyServiceSid sql.NullString
|
||||
}
|
||||
|
||||
func (c sqlTwilioConfig) set(smsConfig *SMSConfig) {
|
||||
@@ -354,9 +364,10 @@ func (c sqlTwilioConfig) set(smsConfig *SMSConfig) {
|
||||
return
|
||||
}
|
||||
smsConfig.TwilioConfig = &Twilio{
|
||||
SID: c.sid.String,
|
||||
Token: c.token,
|
||||
SenderNumber: c.senderNumber.String,
|
||||
SID: c.sid.String,
|
||||
Token: c.token,
|
||||
SenderNumber: c.senderNumber.String,
|
||||
VerifyServiceSID: c.verifyServiceSid.String,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,7 @@ var (
|
||||
` projections.sms_configs3_twilio.sid,` +
|
||||
` projections.sms_configs3_twilio.token,` +
|
||||
` projections.sms_configs3_twilio.sender_number,` +
|
||||
` projections.sms_configs3_twilio.verify_service_sid,` +
|
||||
|
||||
// http config
|
||||
` projections.sms_configs3_http.sms_id,` +
|
||||
@@ -50,6 +51,7 @@ var (
|
||||
` projections.sms_configs3_twilio.sid,` +
|
||||
` projections.sms_configs3_twilio.token,` +
|
||||
` projections.sms_configs3_twilio.sender_number,` +
|
||||
` projections.sms_configs3_twilio.verify_service_sid,` +
|
||||
|
||||
// http config
|
||||
` projections.sms_configs3_http.sms_id,` +
|
||||
@@ -74,6 +76,7 @@ var (
|
||||
"sid",
|
||||
"token",
|
||||
"sender-number",
|
||||
"verify_sid",
|
||||
// http config
|
||||
"sms_id",
|
||||
"endpoint",
|
||||
@@ -126,6 +129,7 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
"sid",
|
||||
&crypto.CryptoValue{},
|
||||
"sender-number",
|
||||
"",
|
||||
// http config
|
||||
nil,
|
||||
nil,
|
||||
@@ -148,9 +152,10 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
Sequence: 20211109,
|
||||
Description: "description",
|
||||
TwilioConfig: &Twilio{
|
||||
SID: "sid",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SenderNumber: "sender-number",
|
||||
SID: "sid",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SenderNumber: "sender-number",
|
||||
VerifyServiceSID: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -178,6 +183,7 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// http config
|
||||
"sms-id",
|
||||
"endpoint",
|
||||
@@ -228,6 +234,7 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
"sid",
|
||||
&crypto.CryptoValue{},
|
||||
"sender-number",
|
||||
"verify-service-sid",
|
||||
// http config
|
||||
nil,
|
||||
nil,
|
||||
@@ -246,6 +253,7 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
"sid2",
|
||||
&crypto.CryptoValue{},
|
||||
"sender-number2",
|
||||
"verify-service-sid2",
|
||||
// http config
|
||||
nil,
|
||||
nil,
|
||||
@@ -264,6 +272,7 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// http config
|
||||
"sms-id3",
|
||||
"endpoint3",
|
||||
@@ -286,9 +295,10 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
Sequence: 20211109,
|
||||
Description: "description",
|
||||
TwilioConfig: &Twilio{
|
||||
SID: "sid",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SenderNumber: "sender-number",
|
||||
SID: "sid",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SenderNumber: "sender-number",
|
||||
VerifyServiceSID: "verify-service-sid",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -301,9 +311,10 @@ func Test_SMSConfigsPrepare(t *testing.T) {
|
||||
Sequence: 20211109,
|
||||
Description: "description",
|
||||
TwilioConfig: &Twilio{
|
||||
SID: "sid2",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SenderNumber: "sender-number2",
|
||||
SID: "sid2",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SenderNumber: "sender-number2",
|
||||
VerifyServiceSID: "verify-service-sid2",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -397,6 +408,7 @@ func Test_SMSConfigPrepare(t *testing.T) {
|
||||
"sid",
|
||||
&crypto.CryptoValue{},
|
||||
"sender-number",
|
||||
"verify-service-sid",
|
||||
// http config
|
||||
nil,
|
||||
nil,
|
||||
@@ -413,9 +425,10 @@ func Test_SMSConfigPrepare(t *testing.T) {
|
||||
Sequence: 20211109,
|
||||
Description: "description",
|
||||
TwilioConfig: &Twilio{
|
||||
SID: "sid",
|
||||
SenderNumber: "sender-number",
|
||||
Token: &crypto.CryptoValue{},
|
||||
SID: "sid",
|
||||
SenderNumber: "sender-number",
|
||||
Token: &crypto.CryptoValue{},
|
||||
VerifyServiceSID: "verify-service-sid",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -440,6 +453,7 @@ func Test_SMSConfigPrepare(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// http config
|
||||
"sms-id",
|
||||
"endpoint",
|
||||
|
Reference in New Issue
Block a user