Wrapper für die Android-SMS-Benutzerzustimmungs-API, SMS-Retrieval-API zum Lesen von einmaligen SMS-Codes, Abrufen der Benutzer-Telefonnummer, OTP, OTC, SMS-Autofill, Android-Autofill
Aus öffentlichen Paketdaten erstellte Orientierung.
SmartAuth ist ein Flutter-Paket, das die OTP- und SMS-basierte Authentifizierung auf Android vereinfacht, indem es die Android-SMS-Benutzerzustimmungs-API und die SMS-Retrieval-API nutzt. Es ermöglicht die automatische Erkennung und Lektüre von Einmalpasswörtern (OTPs) aus eingehenden SMS-Nachrichten, unterstützt das automatische Ausfüllen von OTPs in Formularen und ruft Telefonnummern sicher ab. Für eine nahtlose Integration mit PIN-, OTP- und Passwortfeldern entwickelt, verbessert es die Benutzererfahrung durch Reduzierung manueller Eingaben. Das Paket ist plattformspezifisch und funktioniert ausschließlich unter Android.
Anwendungsfälle
Automatische Erkennung von OTP aus SMS
Automatisches Ausfüllen von OTP in Anmeldeformularen
Lesen der Telefonnummer des Benutzers aus SMS
Verbesserung des Anmeldevorgangs mit SMS-Autofill
Zwei-Faktor-Authentifizierung vereinfachen
Reduzierung von Benutzereingabefehlern bei der OTP-Eingabe
Hauptmerkmale
Automatische OTP-Auswertung aus SMS
Sichere Telefonnummerabfrage
Nur für Android verfügbares SMS-Vervollständigungs-Unterstützung
Einfache Integration mit Textfeldern
Echtzeit-SMS-Monitoring
Kompatibel mit der Android SMS Retriever-API
Geeignet für
Android-Apps, die OTP-Autovervollständigung erfordern
Apps, die SMS-basierte 2FA verwenden
Entwickler, die native SMS-Integration suchen
Benutzerflüsse mit SMS-Verifizierung
Apps, die darauf abzielen, die Reibung beim Anmelden zu verringern
Hinweise
Funktioniert nur unter Android
Erforderliches korrektes SMS-Format zur Erkennung
Benötigt Laufzeitberechtigungen für den SMS-Zugriff
Beschränkt auf Geräte mit Google Play-Diensten
Abhängig von der Verfügbarkeit der SMS-Retrieval-API
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
Flutter Smart Auth
Need anything Flutter related? Reach out
on LinkedIn
Flutter package for listening SMS code on Android, suggesting phone number, email, saving a
credential.
If you need pin code input like shown below, take a look at
the Pinput package.
The Phone Number Hint API, a library powered by Google Play services, provides a frictionless way to
show a user’s (SIM-based) phone numbers as a hint.
The benefits to using Phone Number Hint include the following:
No additional permission requests are needed
Eliminates the need for the user to manually type in the phone number
No Google account is needed
Not directly tied to sign in/up workflows
Wider support for Android versions compared to Autofill
voidrequestPhoneNumberHint() async {
final res = await smartAuth.requestPhoneNumberHint();
if (res.hasData) {
// Use the phone number
} else {
// Handle error
}
}
The SMS User Consent API complements the SMS Retriever API by allowing an app to prompt the user to
grant access to the content of a single SMS message. When a user gives consent, the app will then
have access to the entire message body to automatically complete SMS verification. The verification
flow looks like this:
A user initiates SMS verification in your app. Your app might prompt the user to provide a phone
number manually or request the phone number hint by calling requestPhoneNumberHint method.
Your app makes a request to your server to verify the user's phone number. Depending on what
information is available in your user database, this request might include the user's ID, the
user's phone number, or both.
At the same time, your app calls the getSmsWithUserConsentApi to show the user a dialog to
grant access to the SMS message.
Your server sends an SMS message to the user that includes a one-time code to be sent back to
your server.
When the user's device receives the SMS message, the getSmsWithUserConsentApi will extract the
one-time code from the message text and you have to send it back to your server.
Your server receives the one-time code from your app, verifies the code, and finally records that
the user has successfully verified their account.
voidgetSmsWithUserConsentApi() async {
final res = await smartAuth.getSmsWithUserConsentApi();
if (res.hasData) {
final code = res.requireData.code;
/// The code can be null if the SMS was received but the code was not extracted from itif (code == null) return;
// Use the code
} elseif (res.isCanceled) {
// User canceled the dialog
} else {
// handle the error
}
}
With the SMS Retriever API, you can perform SMS-based user verification in your Android app
automatically, without requiring the user to manually type verification codes, and without requiring
any extra app permissions. When you implement automatic SMS verification in your app, the
verification flow looks like this:
A user initiates SMS verification in your app. Your app might prompt the user to provide a phone
number manually or request the phone number hint by calling requestPhoneNumberHint method.
Your app makes a request to your server to verify the user's phone number. Depending on what
information is available in your user database, this request might include the user's ID, the
user's phone number, or both.
At the same time, your app calls the getSmsWithRetrieverApi to begin listening for an SMS
response from your server.
Your server sends an SMS message to the user that includes a one-time code to be sent back to
your server, and a hash that identifies your app.
When the user's device receives the SMS message, Google Play services uses the app hash to
determine that the message is intended for your app, and makes the message text available to your
app through the SMS Retriever API.
The getSmsWithRetrieverApi will extract the one-time code from the message text and you have to
send it back to your server.
Your server receives the one-time code from your app, verifies the code, and finally records that
the user has successfully verified their account.
voidgetSmsWithRetrieverApi() async {
final res = await smartAuth.getSmsWithRetrieverApi();
if (res.hasData) {
final code = res.requireData.code;
/// The code can be null if the SMS was received but the code was not extracted from itif (code == null) return;
// Use the code
} else {
// handle the error
}
}
Dispose
The plugin automatically removes listeners after receiving the code, if not you can remove them by
calling the removeUserConsentApiListener or removeSmsRetrieverApiListener method.
voidremoveSmsListener() {
smartAuth.removeUserConsentApiListener();
// or
smartAuth.removeSmsRetrieverApiListener();
}