Add WhatsApp OTP Login
Allow users to log into your app via OTP with WhatsApp, as a secure alternative to SMS
Enable WhatsApp OTP in your project
Authgear let your users login passwordlessly with WhatsApp OTP.
To enable this feature from the Portal:
Go to Authentication > Login Methods, we are going make few changes on this page.
In the top section of Select Login Methods, select Mobile.
In Authentication of Select Login Methods, select Passwordless.
In the tabs section below, switch to the tab Verification and OTP.
In the dropdown Verify phone number by, select either WhatsApp or SMS or WhatsApp only.
Press Save on the top left corner.
When the user login with their phone number, a WhatsApp message with an OTP will be received. They can copy the code by tapping on the "Copy code" button and log in by the code.
If "Verify phone number by WhatsApp or SMS" is enabled, the user can switch to receive the OTP via SMS instead in the login page.
Set up your own WhatsApp Business account
By default, WhatsApp OTP are sent via a shared Authgear sender. If you want them to be sent with your own WhatsApp numbers, you need a WhatsApp Business account and a Meta App. This guide shows you how to set up a WhatsApp Business number for Authgear OTP authentication.
You will need an unused phone number, and a Facebook account.
Step 1: Create a business portfolio
Skip this if you already have an existing business portfolio
Go to business.facebook.com in a desktop browser. You will also use this address to log into Meta Business Suite. If you already have access to Meta Business Suite, you can also click the dropdown menu located at the top of the left menu. Then skip to Step 4.
Click Create account.
Log into your personal Facebook account. If you don’t have an account, click Create account to sign up for one.
Click Create a business portfolio.
Enter your business details.
Business portfolio name. It should match the public name of your business or organization, since it will be visible across Meta. It can't contain special characters.
Your name.
Business email. Meta will use this email to contact you about your business. It won't be visible to your customers.
Click Submit or Create to create your portfolio. You’ll get an email asking to confirm your business email address.
Step 2: Register Phone number as a new WhatsApp Business Account
Go to “Settings” in Meta Businss Suite
Under “Accounts”, go to “WhatsApp accounts” and then “Create a new WhatsApp Business account”

Enter the display name and set up the profile image, which will be shown to your users
Use a unregistered phone number for the account, Follow the on-screen instructions to verify the phone number
Set up payment method in this business portfolio and link the WhatsApp account with the payment method.
Step 3: Set up Message template
Go to “WhatsApp Manager” in Meta Business Suite, if the item is not available in the nav bar, search WhatsApp in “All tools”
Go to “Manage templates” and “Create Template”, make sure the correct WhatsApp business account is selected on the top right dropdown.

Select “Authentication” type

For each language you wish to support, create a template named
one_time_passwordSelect “Copy Code” under Code delivery setup
Select “Add security recommendation” under Content
Set Validity period to 10 minutes

The template page should look like this after adding the required languages

Step 4: Set up Application
In this step, we will create a “Meta App”
Go to https://developers.facebook.com/apps/ and create a new app
Enter an identifier for the meta app and your contact email
In User cases, select “Other”
App type, select “Business”
Link to the business portolio created in step 1.
After creating the app, select “WhatsApp” in “Add product to your app”

In “API Setup”, tap “Generate access token” and select the WhatsApp account we created in Step 2. Then click continue.

Under “From” dropdown, select the phone number we registered in Step 2. Note the “Phone number ID” and “WhatsApp Business Account ID”. Here if your enter a valid “To” number, you should be able to receive a testing “Hello World” message.

Go to “App Settings”, add “Privacy Policy” link
Switch App mode to “Live” (You may be asked to enter business details for review.)
Step 5: Set up “System User”
Go back to Meta Business Suite business.facebook.com
Go to “Settings” > “Users” > “System users”
Add a new system user
Assign the App we created in Step 4 with “Develop app” access
Assign the WhatsApp account created in Step 2 with "Message templates (view only)” and “Phone Numbers (view and manage)” access
Click “Generate token” and note the token created.
Now, give Authgear team the following items:
Phone number ID
WhatsApp Business Account ID
Access Token of the System user
And we will help you set up the connection in the backend
Step 6: Set up Automatic SMS Fallback
To support automatic fallback to SMS when the WhatsApp delivery failed, we will need to set up a webhook between Meta and the Authgear server to check the delivery status of messages.
Go back to https://developers.facebook.com/apps/ and manage the app we created
Under WhatsApp, go to “Configuration”
Fill in the
Callback URL:
https://{authgear_endpoint}/whatsapp/webhookVerify token: A random string
e.g. Use
openssl rand -hex 16command to generate a 32-character sequence
Share the “Verify token” to the Authgear Team for backend configuration
Press “Verify and save”

In The “Webhooks” page, select “WhatsApp Business Account” under Product, and then enable the
messageswebhook subscription.
Last updated
Was this helpful?