Guides
Embedded Signup and login
Facebook Login, Embedded Signup and coexistence with the Mimicr sdk.js, exchanging the code for a token and debugging tokens.
Tech providers connect each customer's WhatsApp account with Facebook Login or Embedded Signup. Mimicr simulates both ends: the consent dialog and the exchange of the code for a token of the chosen business.
Front end: swap the SDK
Load Mimicr's SDK instead of Meta's. The FB API is the same:
// before: https://connect.facebook.net/en_US/sdk.js
const s = document.createElement("script");
s.src = "https://whatsapp.mimicr.dev/en_US/sdk.js";
document.head.appendChild(s);
window.fbAsyncInit = () => {
FB.init({ appId: "109310356550101", version: "v24.0" });
};
window.addEventListener("message", (event) => {
if (event.origin !== "https://whatsapp.mimicr.dev") return; // with Meta: https://www.facebook.com
const data = JSON.parse(event.data);
if (data.type === "WA_EMBEDDED_SIGNUP" && data.event === "FINISH") {
const { waba_id, phone_number_id, business_id } = data.data;
// store them together with the code
}
});
FB.login((response) => {
if (response.authResponse) sendCodeToBackend(response.authResponse.code);
}, {
config_id: "<config_id>",
response_type: "code",
override_default_response_type: true,
extras: { setup: {}, featureType: "", sessionInfoVersion: "3" },
});FB.login opens the Mimicr dialog in a popup. The user picks the business and number (with several WABAs in the sandbox, each one shows up), the callback gets authResponse.code and, about 2.5 seconds later, the page posts the WA_EMBEDDED_SIGNUP event with waba_id, phone_number_id and business_id. If the user cancels, event: "CANCEL" arrives with current_step.
With extras.featureType: "whatsapp_business_app_onboarding" (coexistence with the WhatsApp Business app), the event is FINISH_WHATSAPP_BUSINESS_APP_ONBOARDING.
With Meta, the event comes from the https://www.facebook.com origin. In Mimicr, it comes from https://whatsapp.mimicr.dev: make the origin configurable. FB.api is not simulated; call the Graph API from your backend.
Login with redirect
Without the SDK, send the user to the Login dialog:
https://whatsapp.mimicr.dev/v24.0/dialog/oauth?client_id=109310356550101&redirect_uri=https://app.example.com/callback&state=xyz&scope=whatsapp_business_management,whatsapp_business_messaging
On continue, the user comes back to redirect_uri?code=…&state=xyz; on cancel, to redirect_uri?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=xyz.
Back end: exchange the code for a token
curl --url 'https://whatsapp.mimicr.dev/v24.0/oauth/access_token?client_id=109310356550101&client_secret=<app_secret>&code=<code>'
{ "access_token": "EAAsim…", "token_type": "bearer", "expires_in": 5183944 }The code is valid for 10 minutes. Include redirect_uri when the flow used one. The returned token only sees the chosen WABA. Errors: unknown client_id (101), wrong client_secret (1), invalid or expired code (100, subcode 36007).
With grant_type=fb_exchange_token&fb_exchange_token=<token> the same route returns a long-lived token.
After the exchange
- Get the token's user and List the user's businesses: the token's business and WABA.
- Debug an access token with the app token:
is_valid,scopesandgranular_scopeswith the WABA. - Subscribe the app to the customer's WABA to receive its webhooks, optionally with
override_callback_uri. - List phone numbers and Register a phone number to put the number on the Cloud API.
Several businesses
Create your customers' businesses with POST /v1/whatsapp/{slug}/wabas (see Environment). Each one has its WABA and first number, and the dialog starts offering the choice.