Android-Implementierung der OTP-Autofill mit Hilfe der User Consent API und der Retriever API. Fügen Sie die Möglichkeit hinzu, OTP-Codes von einer anderen Eingabe zu erhalten.
Aus öffentlichen Paketdaten erstellte Orientierung.
Das otp_autofill-Paket ermöglicht die automatische Ausfüllung von OTPs unter Android mithilfe der User Consent API und der Retriever API, wodurch Apps eindeutige Passwörter aus SMS automatisch erkennen und ausfüllen können. Es unterstützt die Eingabe von OTP-Codes über alternative Quellen und verbessert so die Benutzererfahrung bei der Authentifizierung. Das Paket funktioniert auch auf iOS und bietet eine plattformübergreifende Kompatibilität für PIN- und OTP-Felder. Speziell für eine nahtlose Integration mit Formularfeldern entwickelt, verringert es Eingabefehler und beschleunigt den Anmeldevorgang.
Anwendungsfälle
Automatisierte OTP-Erkennung in Anmeldeformularen
Verbesserung der Benutzererfahrung während der Zwei-Faktor-Authentifizierung
Unterstützung von SMS-basierten Überprüfungsabläufen
Integration mit bestehenden PIN- oder Passwort-Eingabefeldern
Fallback-OTP-Retrieval aus alternativen Quellen aktivieren
Hauptmerkmale
Verwendet die Android-APIs für Benutzerzustimmung und Retriever
Plattformübergreifende Unterstützung (Android und iOS)
Automatische OTP-Code-Auswertung aus SMS
Fallback-Eingabemethode für die OTP-Abfrage
Einfache Integration mit Textfeldern
Geeignet für
Apps, die sichere OTP-Eingabe erfordern
Authentifizierungsabläufe mit SMS-Verifizierung
Entwickler, die geringere Benutzerfriction suchen
Projekte für Android- und iOS-Plattformen
Formularitätsreiche Anwendungen mit PIN-/OTP-Feldern
Hinweise
Erforderlich für vollständige Funktionalität: Android SDK 28+
Beschränkt auf Android-SMS-Autovervollständigung ohne zusätzliche Einrichtung
Die iOS-Implementierung basiert auf der systemnahen OTP-Verwaltung
Benötigte Berechtigungen für den SMS-Zugriff unter Android
Kann Tests über verschiedene Gerätehersteller erfordern
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
You could use autofill from another input by using the OTPStrategy (e.g. from push-notification).
For testing you could create a TestStrategy.
iOS
On iOS, the OTP autofill feature is integrated into the TextField component.
The code received from an SMS is stored for a duration of 3 minutes.
Rules for sms
Sms must contain the word code or its translation in iOS supported localizations.
The sms should contain only one sequence of digits.
iOS Testing
The iOS platform is capable of receiving OTP from any phone number, not just a specific sender.
Android
OTPInteractor.hint - displays a system dialog that allows the user to select from their saved phone numbers (recommendation from Google).
OTPInteractor.getAppSignature - creates the hash code of your application, which is used in the SMS Retriever API.
OTPInteractor.startListenUserConsent - the broadcast receiver that starts listening for OTP codes using the SMS User Consent API. It listens for a duration of 5 minutes, after which a timeout exception occurs.
OTPInteractor.startListenRetriever - the broadcast receiver that starts listening for OTP codes using the SMS Retriever API. It listens for a duration of 5 minutes, after which a timeout exception occurs.
OTPInteractor.stopListenForCode - used in dispose.
The plugin is designed to receive the full text of an SMS message and requires a parser to extract the relevant information from the message.
If you use the SMS User Consent API, the system will prompt the user for permission to access and read incoming messages.
It should contain a one-time code that the client sends back to your server to complete the verification process.
It should include an 11-character hash string that identifies your app (refer to the documentation for server for more details). For testing, you can obtain it from OTPInteractor.getAppSignature.
Android Testing
The OTPInteractor.startListenForCode method allows the application to start receiving verification codes from a specific phone number, specified by the senderPhone argument.
You also can use Android Emulator to test the plugin. To do this, you need to send an SMS to the emulator with the following command:
adb emu sms send <senderPhone> <message>
E.g.:
adb emu sms send 900 "Your code is 12345. Do not share it with anyone."
Make sure senderPhone is the same as the one you specified in the startListenForCode method.
Usage
You should use OTPInteractor to interact with OTP.
To simplify implementation, consider using the OTPTextEditController as a controller for your TextField.
OTPTextEditController.startListenUserConsent - uses the SMS User Consent API and listens to user strategies.
OTPTextEditController.startListenRetriever - uses the SMS Retriever API and listens to user strategies.
OTPTextEditController.startListenOnlyStrategies - only listens to user strategies.
OTPTextEditController.stopListen - used in dispose.
Installation
Add otp_autofill to your pubspec.yaml file:
dependencies:otp_autofill:$currentVersion$
At this moment, the current version of otp_autofill is .
Android Installation
Set minSdkVersion at least to 19 in <project root>/android/app/build.gradle.
To receive a new code when a timeout exception occurs, you can pass a callback function to the onTimeOutException parameter and start listen for a new code.
All significant changes to this project will be documented in this file.
Issues
To report any issues, submit them directly in the Issues section.
Contribute
If you wish to contribute to the package (for instance, by enhancing the documentation, fixing a bug, or introducing a new feature), please review our contribution guide first and then submit your pull request.
Your PRs are always welcome.
How to reach us
Please don't hesitate to ask any questions about this package. Join our community chat on Telegram. We communicate in both English and Russian.