Repository navigation
v1.0.0 - Zero-Permission SMS OTP Verification for Android
π Initial Release - SMS OTP Verification for React Native Android
Automatic SMS OTP verification using Google's SMS Retriever API and SMS User Consent API with zero permissions required.
β¨ Key Features
- π Two verification methods: Automatic (SMS Retriever) and User-Consent based
- π« Zero permissions: No
READ_SMSorRECEIVE_SMSneeded - β Google Play approved: Uses official Google Play Services APIs
- π― Easy integration: Simple JavaScript API with full TypeScript support
- π± Android only: iOS throws descriptive error
- π Event-driven: Real-time SMS listening with callbacks
- π οΈ Modern architecture: Built with React Native TurboModules
π¦ Installation
npm install @pushpendersingh/react-native-otp-verifyor
yarn add @pushpendersingh/react-native-otp-verifyπ Quick Start
import {
startSmsRetriever,
addSmsListener,
getAppSignature,
extractOtp
} from '@pushpendersingh/react-native-otp-verify';
// Get app signature for your backend
const signature = await getAppSignature();
// Start listening for SMS
await startSmsRetriever();
// Listen for incoming OTP
const removeListener = addSmsListener((message) => {
if (message.status === 'success') {
const otp = extractOtp(message.message);
console.log('OTP:', otp);
}
});π― What's Included
Native Implementation (Kotlin)
- β SMS Retriever API integration
- β SMS User Consent API integration
- β App signature hash generator (11-character Base64)
- β BroadcastReceiver for SMS events
- β Activity result handling for consent dialogs
- β Android API 19+ support
JavaScript API
- β
startSmsRetriever()- Start automatic SMS listening - β
getAppSignature()- Get app hash for SMS formatting - β
requestPhoneNumber()- Start consent-based verification - β
addSmsListener()- Listen for SMS events - β
removeSmsListener()- Stop listening - β
extractOtp()- Extract OTP with custom regex support
Documentation
- β Comprehensive README with all APIs documented
- β Complete usage examples (Automatic & Consent-based)
- β Backend integration guide (Node.js example)
- β SMS format specifications
- β Troubleshooting guide
- β Full TypeScript definitions
Example App
- β Simple demo app with both verification methods
- β Live testing examples
- β Clear implementation patterns
π API Overview
SMS Retriever (Automatic)
Perfect when you control the SMS format. Captures OTP automatically without user interaction.
// Your backend sends SMS like this:
// <#> Your OTP is: 123456
//
// FA+9qCX9VSu
await startSmsRetriever();
const removeListener = addSmsListener((message) => {
const otp = extractOtp(message.message); // "123456"
});SMS User Consent (Dialog-based)
Works with any SMS format. Shows Google consent dialog - user taps "Allow" to share SMS.
// Works with any SMS format:
// "Your verification code is 123456"
await requestPhoneNumber();
const removeListener = addSmsListener((message) => {
if (message.status === 'success') {
const otp = extractOtp(message.message); // "123456"
}
});π§ Requirements
- React Native >= 0.76+
- Android API Level >= 24
- Google Play Services
π Comparison: SMS Retriever vs SMS User Consent
| Feature | SMS Retriever | SMS User Consent |
|---|---|---|
| User Action | None (Automatic) | Tap "Allow" |
| SMS Format | Requires app hash | Any format |
| User Experience | Seamless | One-tap consent |
| Best For | Your own backend | 3rd party SMS |
| Permission | Zero | Zero |
π‘οΈ Zero Permissions
Both APIs use Google Play Services and require zero permissions in AndroidManifest.xml.
<!-- AndroidManifest.xml -->
<manifest>
<!-- No READ_SMS -->
<!-- No RECEIVE_SMS -->
<!-- No special permissions needed! -->
</manifest>π§ Backend Integration
SMS Format for SMS Retriever
<#> Your OTP is: 123456
YOUR_APP_SIGNATURE
Node.js Example
const signature = 'FA+9qCX9VSu'; // Get from getAppSignature()
const otp = '123456';
const sms = `<#> Your OTP is: ${otp}
${signature}`;
// Send via your SMS provider (Twilio, AWS SNS, etc.)
await sendSMS(phoneNumber, sms);π Bug Reports & Feature Requests
If you find any issues or have feature requests, please open an issue.
π€ Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
π License
MIT - See LICENSE for details.
π Credits
- Built with create-react-native-library
- Uses Google SMS Retriever API
- Uses Google SMS User Consent API