Truecaller JavaScript API
Integrate Truecaller login using the WebToNative JavaScript API. Enable fast, secure phone number authentication in Android applications.
Function to integrate Truecaller authentication into your app. The WebToNative Truecaller plugin integrates the Truecaller Android and iOS SDKs natively, giving you a single JavaScript API that works across both platforms while preserving the platform-specific verification model required by Truecaller.
How It Works
Truecaller uses two different verification flows depending on the operating system. The WebToNative plugin abstracts the SDK call into a single JavaScript function, but the data returned to your callback — and therefore the work your backend must do — depends on the platform the user is on.
Android
OAuth 2.0 with PKCE
authorizationCode, codeVerifier, requestNonce
Exchange the authorization code using the PKCE verifier, then fetch the user profile.
iOS
Legacy JWT delegate
Signed JWT (in authorizationCode), empty codeVerifier, requestNonce
Verify the JWT signature, decode the claims, and extract the user profile.
Always inspect data.platform in the callback response to decide which verification path to run on your backend.
Setting Up Your Truecaller Account
WebToNative leverages Truecaller's developer platform to power phone-number based login within your app. To get started, register at the Truecaller Developer Portal.
Log in to the Truecaller Developer Portal
Log in to the Truecaller Developer Portal.
Add platform details
Add the following details for each platform:
For Android:
Package Name
WebToNative dashboard → App Info → Package Name.
SHA-1
The release SHA-1 of the signing keystore used for your app.
For iOS:
Bundle ID
The Bundle ID you created in App Store Connect (iOS only).
App Name
The display name of your app as listed on the App Store.
Add credentials in WebToNative
Go to your WebToNative dashboard → Add-ons → Truecaller and enter:
Android Client ID
Paste the Client ID copied from the Truecaller dashboard.
iOS App Key
Paste the App Key copied from the Truecaller dashboard.
iOS App Link
Paste the App Link copied from the Truecaller Dashboard.
Truecaller Login
Opens the Truecaller consent screen. On success, returns the credentials your backend needs to fetch the verified user profile.
window.WTN.Truecaller.truecallerLogin({
callback: function (response) {
if (response.success) {
console.log(response.data.platform);
console.log(response.data.authorizationCode);
console.log(response.data.codeVerifier);
console.log(response.data.requestNonce);
} else {
console.error(response.error.code);
console.error(response.error.message);
}
},
});import { truecallerLogin } from "webtonative/Truecaller";
truecallerLogin({
callback: (response) => {
if (response.success) {
console.log(response.data.platform);
console.log(response.data.authorizationCode);
console.log(response.data.codeVerifier);
console.log(response.data.requestNonce);
} else {
console.error(response.error.code);
console.error(response.error.message);
}
},
});Parameters:
callback
Function
No
Callback function invoked with the response.
Callback Response:
type
String
Always "truecallerLogin". Use this to filter the callback.
success
Boolean
true if the login flow completed, false if it failed.
data
Object
Present when success is true. See Data Object below.
error
Object
Present when success is false. See Error Object below.
Data Object (returned on success):
authorizationCode
String
On Android, the OAuth authorization code. On iOS, the signed JWT token issued by Truecaller.
codeVerifier
String
On Android, the PKCE verifier required to exchange the authorization code. On iOS, this is an empty string.
requestNonce
String
A unique nonce generated for this request. Send to your backend to prevent replay attacks.
platform
String
Either "android" or "ios". Use this to choose the correct backend verification path.
Error Object (returned on failure):
code
String
Machine-readable error code. See the table below.
message
String
Human-readable error description.
Error Codes:
USER_CANCELLED
User cancelled or closed the flow.
TRUECALLER_NOT_INSTALLED
Truecaller app is unavailable.
SDK_INTERNAL_ERROR
Internal SDK failure.
Example Responses
Android Success Response
iOS Success Response
Error Response
iOS Callback Limitation
Unlike Android, iOS does not always emit a cancellation callback. This is a limitation of the current legacy TrueSDK and is not something the WebToNative plugin can work around.
No callback is received when:
The user closes Truecaller manually.
The user dismisses the login flow.
The user switches away before the redirect completes.
The universal-link callback never fires.
Recommended Handling
Wrap the call in a frontend timeout so your UI never gets stuck waiting on a response that will never come.
Backend Verification
The credentials returned by the SDK are not user identities — they are proof that the user completed the Truecaller flow. The verified profile is only available after your backend exchanges or decodes these credentials with Truecaller.
Always branch your backend logic on the platform field:
Android Verification Flow
POST the
authorizationCodeandcodeVerifierto Truecaller's token endpoint.Receive an access token in exchange.
Call Truecaller's profile API with the access token to fetch the verified user.
iOS Verification Flow
Receive the signed JWT from
data.authorizationCode.Verify the JWT signature against Truecaller's public keys.
Decode the claims to extract the verified phone number and profile fields.
Complete Example
A full implementation that handles both platforms, errors, and iOS cancellations:
Best Practices
Always verify on the backend. Treat anything returned to the frontend as untrusted until your server has exchanged or verified it with Truecaller.
Never trust frontend profile data. The phone number and identity are only authoritative after backend verification.
Store the Android PKCE verifier securely. It must accompany the authorization code on the server-side exchange request.
Verify the JWT signature on iOS. Decoding without verification leaves you open to forged tokens.
Use the request nonce. Pass it through to your backend and reject any verification response whose nonce does not match the one you issued — this prevents replay attacks.
Branch on
platform. Do not assume one flow on the server; the credentials look superficially similar but require different verification.Apply an iOS timeout. Treat the missing-callback case as a cancellation so your UI never hangs.
Integration Checklist
Use this checklist before shipping to make sure the integration is wired up end-to-end.
Truecaller portal
WebToNative dashboard
Frontend
Backend
FAQs
Official References
Last updated