mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
14e2aba1bc
# 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>
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/sms"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/twilio"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/webhook"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
// GetActiveSMSConfig reads the active iam sms provider config
|
|
func (n *NotificationQueries) GetActiveSMSConfig(ctx context.Context) (*sms.Config, error) {
|
|
config, err := n.SMSProviderConfigActive(ctx, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
provider := &sms.Provider{
|
|
ID: config.ID,
|
|
Description: config.Description,
|
|
}
|
|
if config.TwilioConfig != nil {
|
|
token, err := crypto.DecryptString(config.TwilioConfig.Token, n.SMSTokenCrypto)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &sms.Config{
|
|
ProviderConfig: provider,
|
|
TwilioConfig: &twilio.Config{
|
|
SID: config.TwilioConfig.SID,
|
|
Token: token,
|
|
SenderNumber: config.TwilioConfig.SenderNumber,
|
|
VerifyServiceSID: config.TwilioConfig.VerifyServiceSID,
|
|
},
|
|
}, nil
|
|
}
|
|
if config.HTTPConfig != nil {
|
|
return &sms.Config{
|
|
ProviderConfig: provider,
|
|
WebhookConfig: &webhook.Config{
|
|
CallURL: config.HTTPConfig.Endpoint,
|
|
Method: http.MethodPost,
|
|
Headers: nil,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
return nil, zerrors.ThrowNotFound(nil, "HANDLER-8nfow", "Errors.SMS.Twilio.NotFound")
|
|
}
|