双因素认证

两次调用, 即可添加第二重验证。

配置语言:
Cursor

双因素认证在密码之上增加了第二重验证:通过用户控制的渠道发送一次性验证码。使用 Bird Verify,只需在登录时发起一次发送调用,用户输入验证码后进行一次校验调用即可——支持 SMS、WhatsApp 或电子邮件,可按国家/地区配置渠道,两次调用之间无需存储任何状态。

verify.ts
200 · pending
import { BirdClient } from "@messagebird/sdk";

const bird = new BirdClient({
  apiKey: process.env.BIRD_API_KEY!,
});

// Send the code, then check it by recipient.
await bird.verify.verifications.create({
  to: { phone_number: "+15551234567" },
}).safe();

const { data, error } = await bird.verify.verifications.check({
  to:   { phone_number: "+15551234567" },
  code: userInput,
}).safe();
if (error) throw error;

2FA 就是指向登录场景的验证流程。

Under the hood, 2FA is the same flow the Bird Verify API runs everywhere: create a verification for the user's phone or email when they sign in, then check the code they enter. Because the check is by recipient, your login handler keeps no per-attempt state, and the workspace's routing decides which channel a given user gets. Drop the password in front of it and the same flow becomes passwordless login.

2FA 的接入内容。

两次调用加一份配置。

  1. 01

    登录时发送,提交时校验。

    当用户通过第一重因素认证后创建验证;用户输入验证码时进行校验。这就是全部的集成工作。

  2. 02

    SMS、WhatsApp 或电子邮件作为验证因素。

    使用您已有的用户渠道:通过 SMS 或 WhatsApp 发送到手机号,通过电子邮件发送到邮箱。语音渠道即将推出,提供更多选择。

  3. 03

    One configuration, workspace-wide.

    Routing, code rules, and channel plan live in a single configuration for the whole workspace, already covering login, signup, and high-value actions.

  4. 04

    暴力破解受到限制。

    内置尝试次数锁定和按接收方的发送频率限制,确保第二重因素不会成为新的攻击面。

登录时的验证流程。

密码验证通过后发送验证码;用户提交时进行校验。验证码错误是一个可供分支判断的结果,而非需要捕获的异常。

two-factor.ts
200
// Send the second factor once the password checks out.
await bird.verify.verifications.create({
  to: { phone_number: user.phone },
}).safe();

const { data, error } = await bird.verify.verifications.check({
  to:   { phone_number: user.phone },
  code: submitted,
}).safe();
if (error) throw error;

if (data.success) grantSession(user);

双重身份验证,与您的其他渠道共用同一 API。

Bird Verify 为您的登录和注册流程提供基于验证码的认证因素:目前支持 SMS、电子邮件和 WhatsApp,语音渠道即将上线。

从一个渠道开始。
准备好后,再添加其他渠道。

测试 API 密钥即刻可用。添加支付方式并验证发送者身份后,即可解锁生产环境。

正在使用 Claude Code、Cursor 或 Codex?复制一条设置提示,您的智能代理即可自动安装 Bird CLI 和相关技能。选择您的工具:

Cursor