メインコンテンツにスキップ

Send SMS with Twilio Verify

With the Twilio Verify type, Twilio generates the SMS verification code, sends it, and checks the code that the user enters. Casdoor only starts the verification and asks Twilio whether the code is approved. Use it instead of Twilio SMS when you want Twilio to handle the codes, for example to send them without registering a sender number.


学習目標​

  • Create a Verify service in Twilio.
  • Add Twilio Verify as an SMS provider in Casdoor and test it.

必要なもの​

  • A Twilio account
  • Casdoor 管理コンソールへの管理者アクセス権限

Create a Verify service​

  1. In the Twilio Console, copy the Account SID and the Auth Token.
  2. Go to Verify > Services and create a service with the SMS channel. Copy its Service SID, which starts with VA.

The code length and the code lifetime are set on the Verify service. Keep the lifetime no shorter than the verification code timeout of Casdoor (verificationCodeTimeout in conf/app.conf, 10 minutes by default).

Casdoor でプロバイダーを追加する​

  1. Casdoor 管理コンソールで Identity > Providers に移動し、プロバイダーを追加します。

  2. Set Category to SMS and Type to Twilio Verify.

  3. フィールドに入力します:

    Casdoor fieldTwilioRequired
    Client IDAccount SIDYes
    Client secretAuth TokenYes
    Service SIDService SIDYes
  4. プロバイダーを保存し、アプリケーションに追加します。詳細については Add providers to an application を参照してください。

The provider works in all the places where Casdoor sends SMS codes: sign-up, sign-in with a code, binding or changing a phone number, password recovery, and SMS multi-factor authentication.

結果の確認​

Enter a phone number in SMS Test and send a test message. You get a code from Twilio Verify.

How the codes are checked​

  • The code that the user enters is checked by the Verification Check API of Twilio. Only an approved result passes. A wrong code, or a verification that has expired, has already been approved, or has run out of attempts, counts as a wrong code.
  • Casdoor still applies its own limits: the resend interval, the code timeout, the failed attempt limits, and a code that has been used can't be used again.
  • Twilio Verify は独自のメッセージテキストを送信するため、Template code フィールドは使用されません。Casdoor の SMS 送信 API も、渡された内容の代わりに認証コード(Verify code)を送信します。

関連項目​