# Setting Up Text-Message (SMS) Codes for Two-Factor Authentication

Source: https://help.yurbi.com/admin-guides/setting-up-text-message-sms-codes-for-two-factor-authentication

To send two-factor codes by text message, Yurbi needs an SMS provider. You can connect **Twilio** directly or use any other SMS gateway that offers an HTTP API. Messages are sent from your account with that provider; Yurbi does not include messaging credit.

If you do not want to set up a provider, leave the **Text message (SMS)** switch off under **Allowed methods** and offer the authenticator app and email methods instead.

## Before you begin

- An account with your SMS provider, able to send to your users' countries.
- For Twilio: the **Account SID**, **Auth token**, and a **From number** or messaging service.
- For other providers: the API documentation showing the endpoint, authentication header, and request body for sending a message.
- Your server must be able to reach the provider's API over HTTPS.

## Connecting Twilio

1. Go to **Settings → Server Settings → Security Settings** and scroll to **Two-Factor Authentication**.
2. Switch on **Text message (SMS)** under **Allowed methods**. The **Text message provider** box appears.
3. Choose **Twilio** and enter the **Account SID**, **Auth token**, and **From number** (in international format, for example `+15551234567`).
4. Click the page's **Save** button.
5. Enter your own mobile number next to **Send test SMS** and click it. The test uses the saved settings, so save first. You should receive a message within a few seconds.

## Connecting another provider (Generic HTTP API)

1. In the **Text message provider** box, choose **Generic HTTP API**.
2. Fill in the request from your provider's documentation:

| Field | What to enter | Example |
|---|---|---|
| Endpoint URL | The send-message address | `https://api.provider.com/send` |
| HTTP method | Usually POST | `POST` |
| Auth header | The full header, as `Name: value` | `Authorization: Bearer xxxxx` |
| Body template | The request body, with `{to}` for the recipient, `{from}` for your sender id and `{message}` for the text containing the code | `{"to":"{to}","from":"{from}","text":"{message}"}` |
| From / sender id | The number or name your provider sends from | `+15551234567` or `ACME` |
| Success match | Text that appears in a successful response; leave blank to accept any 2xx response | `"status":"sent"` |

3. Click the page's **Save** button, then use **Send test SMS**.

A body template that is valid JSON is sent as `application/json`; anything else is sent form-encoded. The template is sent as-is apart from the placeholders.

## Security of your credentials

Credentials are stored encrypted on your server. After saving, the Auth token and Auth header show as `********`. Leaving the masked value in place and saving keeps the existing secret; type a new value to replace it.

## Phone numbers

Users enter their own mobile number when they enroll in the text-message method, from **My Profile → Two-factor authentication**. Numbers should be in international format with the country code. Administrators can see and edit the number in the user editor.

## Troubleshooting

**Send test fails.** The error shown is the provider's response. Common causes: wrong credentials, the From number is not enabled for SMS, the destination country is not enabled on your account, or the server cannot reach the provider (firewall or proxy).

**Test works but users do not get codes.** Check the user's number in the user editor, including the country code. Check the provider's logs for delivery status; carrier filtering of short automated messages is common in some countries.

**Codes arrive late.** Codes expire after 10 minutes. If delivery regularly takes longer, ask users to use the authenticator app method instead.

**I changed providers.** Save the new provider settings; existing user enrollments keep working because only the delivery method changes.

## Frequently asked questions

**Can different groups use different providers or numbers?** No. One provider is used for the whole server.

**Does Yurbi send any other text messages?** No. Only two-factor codes are sent, and only to users who chose the text-message method.

**Which providers have been tested?** Twilio directly. The Generic HTTP option has been used with regional gateways that accept a JSON POST with a bearer or basic authorization header.

## Related

- [Two-Factor Authentication (2FA)](https://help.yurbi.com/admin-guides/two-factor-authentication-2fa)
- [Signing In with Two-Factor Authentication](https://help.yurbi.com/user-guides/signing-in-with-two-factor-authentication)
- [Login and Account Security Options](https://help.yurbi.com/admin-guides/login-and-account-security-options)
