twilio

Can Twilio Be Set Up to Send Verification Codes on Demand?


We are currently working to integrate Twilio with Okta, since Okta is removing their SMS/Voice verification functionality. I'm wondering if we can also use Twilio to manually send verification codes.

For example, user calls the help desk to change their password. We want some verification that it really is the user, not someone else pretending to be them.

Right now we have the help desk tech manually text a code to the user from their personal phone. We'd like to stop doing this and have the ability for the help desk to press a button to send a verification code to the user's phone # on file. Then the user can read it back to confirm it really is them.

Is this feasible with Twilio?


Solution

  • Yes, you can do this easily with the Twilio Verify API. You can either send the OTP code via voice, sms, email or WhatsApp.

    // Download the helper library from https://www.twilio.com/docs/node/install
    const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
    
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    const accountSid = process.env.TWILIO_ACCOUNT_SID;
    const authToken = process.env.TWILIO_AUTH_TOKEN;
    const client = twilio(accountSid, authToken);
    
    async function createVerification() {
      const verification = await client.verify.v2
        .services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
        .verifications.create({
          channel: "sms",
          to: "+15017122661",
        });
    
      console.log(verification.sid);
    }
    
    createVerification();