Flutter package for listening SMS code on Android, suggesting phone number, email, saving a credential.

Overview

Flutter Smart Auth From Tornike & Great Contributors

Pub package Github starts style: effective dart pub package

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 Pinput package, SmartAuth is already integrated into it and you can build highly customizable input, that your designers can't even draw in Figma đŸ€­

Bonus tip: đŸ€« Tell your PM that you need a week to implement the feature and chill with your friends meanwhile.

Note that only Android is supported, I faked other operating systems because other package is depended on this one and that package works on every system

Features:

  • Android Autofill
    • SMS Retriever API
    • SMS User Consent API
  • Showing Hint Dialog
  • Getting Saved Credential
  • Saving Credential
  • Deleting Credential

Support

PRs Welcome

Discord Channel

Example

Don't forget to give it a star ⭐

Demo

Getting Started

Create instance of SmartAuth

  final smartAuth = SmartAuth();

Get the App signature

  void getAppSignature() async {
    final res = await smartAuth.getAppSignature();
    debugPrint('Signature: $res');
  }

Get SMS code

  void getSmsCode() async {
    final res = await smartAuth.getSmsCode();
    if (res.succeed) {
      debugPrint('SMS: ${res.code}');
    } else {
      debugPrint('SMS Failure:');
    }
  }

The plugin automatically removes listeners after receiving the code, if not you can remove them by calling the removeSmsListener method

  void removeSmsListener() {
    smartAuth.removeSmsListener();
  }

Request hints to the user

  void requestHint() async {
    final res = await smartAuth.requestHint(
      isPhoneNumberIdentifierSupported: true,
      isEmailAddressIdentifierSupported: true,
      showCancelButton: true,
    );
    debugPrint('requestHint: $res');
  }

Request Hint

Get saved credential

  // identifier Url
  final accountType = 'https://developers.google.com';
  // Value you want to save, phone number or email for example
  final credentialId = 'Credential Id';
  final credentialName = 'Credential Name';
  final profilePictureUri = 'https://profilePictureUri.com';
  void getCredential() async {
    final res = await smartAuth.getCredential(
      accountType: accountType,
      showResolveDialog: true,
    );
    debugPrint('getCredentials: $res');
  }

Get Credential

Save credential

  void saveCredential() async {
    final res = await smartAuth.saveCredential(
      id: credentialId,
      name: credentialName,
      accountType: accountType,
      profilePictureUri: profilePictureUri,
    );
    debugPrint('saveCredentials: $res');
  }

Save Credential

Delete credential

  void deleteCredential() async {
    final res = await smartAuth.deleteCredential(
      id: credentialId,
      accountType: accountType,
    );
    debugPrint('removeCredentials: $res');
  }

API

getAppSignature

  /// This method outputs hash that is required for SMS Retriever API [https://developers.google.com/identity/sms-retriever/overview?hl=en]
  /// SMS must contain this hash at the end of the text
  /// Note that hash for debug and release if different
  Future<String?> getAppSignature()

getSmsCode

  /// Starts listening to SMS that contains the App signature [getAppSignature] in the text
  /// returns code if it matches with matcher
  /// More about SMS Retriever API [https://developers.google.com/identity/sms-retriever/overview?hl=en]
  ///
  /// If useUserConsentApi is true SMS User Consent API will be used [https://developers.google.com/identity/sms-retriever/user-consent/overview]
  /// Which shows confirmations dialog to user to confirm reading the SMS content
  Future<SmsCodeResult> getSmsCode({
    // used to extract code from SMS
    String matcher = _defaultCodeMatcher,
    // Optional parameter for User Consent API
    String? senderPhoneNumber,
    // if true SMS User Consent API will be used otherwise plugin will use SMS Retriever API
    bool useUserConsentApi = false,
  })

removeSmsListener

  /// Removes listener for [getSmsCode]
  Future<void> removeSmsListener()

  /// Disposes [getSmsCode] if useUserConsentApi is false listener
  Future<bool> removeSmsRetrieverListener()

  /// Disposes [getSmsCode] if useUserConsentApi is true listener
  Future<bool> removeSmsUserConsentListener()

requestHint

  /// Opens dialog of user emails and/or phone numbers
  /// More about hint request [https://developers.google.com/identity/smartlock-passwords/android/retrieve-hints]
  /// More about parameters [https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/HintRequest.Builder]
  Future<Credential?> requestHint({
    // Enables returning credential hints where the identifier is an email address,
    // intended for use with a password chosen by the user.
    bool? isEmailAddressIdentifierSupported,
    // Enables returning credential hints where the identifier is a phone number,
    // intended for use with a password chosen by the user or SMS verification.
    bool? isPhoneNumberIdentifierSupported,
    // The list of account types (identity providers) supported by the app.
    // typically in the form of the associated login domain for each identity provider.
    String? accountTypes,
    // Enables button to add account
    bool? showAddAccountButton,
    // Enables button to cancel request
    bool? showCancelButton,
    // Specify whether an ID token should be acquired for hints, if available for the selected credential identifier.This is enabled by default;
    // disable this if your app does not use ID tokens as part of authentication to decrease latency in retrieving credentials and credential hints.
    bool? isIdTokenRequested,
    // Specify a nonce value that should be included in any generated ID token for this request.
    String? idTokenNonce,
    //Specify the server client ID for the backend associated with this app.
    // If a Google ID token can be generated for a retrieved credential or hint,
    // and the specified server client ID is correctly configured to be associated with the app,
    // then it will be used as the audience of the generated token. If a null value is specified,
    // the default audience will be used for the generated ID token.
    String? serverClientId,
  })

getCredential

  /// Tries to suggest a zero-click sign-in account. Only call this if your app does not currently know who is signed in.
  /// If zero-click suggestion fails app show dialog of credentials to choose from
  /// More about this https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/CredentialsApi?hl=en#save(com.google.android.gms.common.api.GoogleApiClient,%20com.google.android.gms.auth.api.credentials.Credential)
  Future<Credential?> getCredential({
    // Identifier url, should be you App's website url
    String? accountType,
    String? serverClientId,
    String? idTokenNonce,
    bool? isIdTokenRequested,
    bool? isPasswordLoginSupported,
    // If we can't get credential without user interaction,
    // we can show dialog to prompt user to choose credential
    bool showResolveDialog = false,
  })

saveCredential

  /// Saves a credential that was used to sign in to the app. If disableAutoSignIn was previously called and the save operation succeeds,
  /// auto sign-in will be re-enabled if the user's settings permit this.
  ///
  /// Note: On Android O and above devices save requests that require showing a save confirmation may be cancelled
  /// in favor of the active Autofill service's save dialog.
  /// This behavior may be overridden by using Auth.AuthCredentialsOptions.Builder.forceEnableSaveDialog().
  /// Please see the overview documentation for more details on providing the best user experience when targeting Android O and above.
  /// More about this https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/CredentialsApi?hl=en#save(com.google.android.gms.common.api.GoogleApiClient,%20com.google.android.gms.auth.api.credentials.Credential)
  Future<bool> saveCredential({
    // Value you want to save
    required String id,
    // Identifier url, should be you App's website url
    String? accountType,
    String? name,
    String? password,
    String? profilePictureUri,
  })

deleteCredential

  /// Deletes a credential that is no longer valid for signing into the app.
  /// More about this https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/CredentialsApi?hl=en#save(com.google.android.gms.common.api.GoogleApiClient,%20com.google.android.gms.auth.api.credentials.Credential)
  Future<bool> deleteCredential({
    // Value you want to save
    required String id,
    // Identifier url, should be you App's website url
    String? accountType,
    String? name,
    String? password,
    String? profilePictureUri,
  })
You might also like...

Presentation-Remote-PC - Manage your presentation from your smart phone - Phone Client

Presentation-Remote-PC - Manage your presentation from your smart phone - Phone Client

Presentation-Remote-PC Manage your presentation from your smart phone - Phone Cl

Jan 25, 2022

Flutter plugin that implements Android's SMS User Consent API

Flutter plugin that implements Android's SMS User Consent API

sms_user_consent Request user's phone number (supports dual sim) and/or consent to read SMS without adding any permissions, using Android's SMS User C

Sep 7, 2022

Flutter Plugin for sending SMS and MMS on Android and iOS.

Flutter Plugin for sending SMS and MMS on Android and iOS.

Flutter Plugin for sending SMS and MMS on Android and iOS. If you send to more than one person it will send as MMS. On the iOS if the number is an iPhone and iMessage is enabled it will send as an iMessage.

Jan 6, 2023

Dialogs for picking and saving files in Android and in iOS.

flutter_file_dialog Dialogs for picking and saving files in Android and in iOS. Features Supports Android (API level 19 or later) and iOS (10.0 or lat

Dec 31, 2022

Notefy - Task Saving App for both Android and iOS

Assignment for Flutter Developers Goal of the assignment is to: - Show the capa

Jan 25, 2022

SMS Receiver Channel For Android

SMS Receiver Channel For Android

SMS Receiver Channel SMS Receiver Channel For Android Getting Started Use channel on the client_side (flutter) and the platform_side (android) and inv

Nov 3, 2022

Flutter package for sending and verifying SMS/OTP

Flutter package for sending and verifying SMS/OTP

Flutter Termii A Flutter plugin that helps developers use messaging channels to verify and authenticate customer transactions Android iOS Linux macOS

May 26, 2022

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

Nov 11, 2022

Outlook Email App Redesign - Flutter Fully Responsive Design UI

Outlook Email App Redesign - Flutter Fully Responsive Design UI

Outlook Email App Redesign - Flutter Fully Responsive Design UI Watch it on YouTube Flutter web work on beta make sure you change your channel, Config

Dec 30, 2022
Comments
  • Remove downcast of Activity => FlutterActivity

    Remove downcast of Activity => FlutterActivity

    The plugin only depends on APIs from Activity, and right now fails if a class such as FlutterFragmentActivity or a custom Activity is used as the main Activity for the application.

    opened by jonsheller 1
  • Phone number suggestion not working on Android 12 devices

    Phone number suggestion not working on Android 12 devices

    When we request hints for phone number suggestions, the dialog loads for less than a second and then disappears on android 12 devices. I tried with other android versions and it was working fine there.

    opened by cscipher 1
  • Execution failed for task ':app:checkDebugAarMetadata'

    Execution failed for task ':app:checkDebugAarMetadata'

    I am getting this error message after adding pinput which is dependent on this repository

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:checkDebugAarMetadata'.
    > Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
       > Could not find com.google.android.gms:play-repositories-auth:20.1.0.
         Searched in the following locations:
           - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-repositories-auth/20.1.0/play-repositories-auth-20.1.0.pom
           - https://repo.maven.apache.org/maven2/com/google/android/gms/play-repositories-auth/20.1.0/play-repositories-auth-20.1.0.pom
           - https://storage.googleapis.com/download.flutter.io/com/google/android/gms/play-repositories-auth/20.1.0/play-repositories-auth-20.1.0.pom
         Required by:
             project :app > project :smart_auth
       > Could not find com.google.android.gms:play-repositories-auth-api-phone:18.0.1.
         Searched in the following locations:
           - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-repositories-auth-api-phone/18.0.1/play-repositories-auth-api-phone-18.0.1.pom
           - https://repo.maven.apache.org/maven2/com/google/android/gms/play-repositories-auth-api-phone/18.0.1/play-repositories-auth-api-phone-18.0.1.pom
           - https://storage.googleapis.com/download.flutter.io/com/google/android/gms/play-repositories-auth-api-phone/18.0.1/play-repositories-auth-api-phone-18.0.1.pom
         Required by:
             project :app > project :smart_auth
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 42s
    Exception: Gradle task assembleDebug failed with exit code 1
    
    opened by AsimBhadra 2
  • java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=com.example.sms_flutter (has extras) } in fman.ge.smart_auth.SmartAuthPlugin$SmsBroadcastReceiver@79393a2

    java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=com.example.sms_flutter (has extras) } in fman.ge.smart_auth.SmartAuthPlugin$SmsBroadcastReceiver@79393a2

    As long as you use getSmsCode to receive the verification code, it starts to flash back, prompting this error

    D[/AndroidRuntime]()(31911): Shutting down VM E[/AndroidRuntime]()(31911): FATAL EXCEPTION: main E[/AndroidRuntime]()(31911): Process: com.example.sms_flutter, PID: 31911 E[/AndroidRuntime]()(31911): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=com.example.sms_flutter (has extras) } in fman.ge.smart_auth.SmartAuthPlugin$SmsBroadcastReceiver@79393a2 E[/AndroidRuntime]()(31911): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1581) E[/AndroidRuntime]()(31911): at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) E[/AndroidRuntime]()(31911): at android.os.Handler.handleCallback(Handler.java:938) E[/AndroidRuntime]()(31911): at android.os.Handler.dispatchMessage(Handler.java:99) E[/AndroidRuntime]()(31911): at android.os.Looper.loop(Looper.java:233) E[/AndroidRuntime]()(31911): at android.app.ActivityThread.main(ActivityThread.java:8030) E[/AndroidRuntime]()(31911): at java.lang.reflect.Method.invoke(Native Method) E[/AndroidRuntime]()(31911): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631) E[/AndroidRuntime]()(31911): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978) E[/AndroidRuntime]()(31911): Caused by: java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String E[/AndroidRuntime]()(31911): at fman.ge.smart_auth.SmartAuthPlugin$SmsBroadcastReceiver.onReceive(SmartAuthPlugin.kt:433) E[/AndroidRuntime]()(31911): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1566) E[/AndroidRuntime]()(31911): ... 8 more I[/Process]() (31911): Sending signal. PID: 31911 SIG: 9

    opened by CometNet 1
Owner
Tornike
Tornike
Eder Zambrano 0 Feb 13, 2022
Simple tool to open WhatsApp chat without saving the number, developed using Google's Flutter Framework. for Android/ IOS/ Desktop/ Web

OpenWp Simple tool to open WhatsApp chat without saving the number Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About

Swarup Bhanja Chowdhury 15 Nov 1, 2022
Send-a-msg - Send message to WhatsApp without saving number

Send A Message Send Message to Whatsapp without saving number ToDo add logging s

Sujal 3 Apr 3, 2022
A reference credential wallet built on Flutter and DIDKit.

Check out the Credible documentation here. Credible Credible is a native mobile wallet that supports W3C Verifiable Credentials and Decentralized Iden

Spruce Systems, Inc. 31 Nov 7, 2022
An android app that can automatically dial a phone number.

AutoCallScheduler An android app that can automatically dial a phone number within a given scheduled of time. Basically it's a test base app of google

Rezwan 24 Dec 4, 2022
A simple and customizable flutter package for inputting phone number in intl / international format uses Google's libphonenumber

Intl Phone Number Input A simple and customizable flutter package for inputting phone number in intl / international format uses Google's libphonenumb

Ogunye Nathaniel Oluwatobiloba 138 Dec 11, 2022
null 1 Jan 29, 2022
it's just phone number authentication and connected to firebase

simplevar A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

vivek kumar 0 Dec 27, 2021
a Flutter based - Open Source Listening Experience Training App

eqTrainer Open-source listening experience trainer, Powered by Flutter. Overview eqTrainer is a Flutter-based, Open-source Listening Experience traini

Lee Jinwoo 4 Mar 2, 2022
An app that randomly draws Japanese vocabularies from N5 to N1 level to test your listening skill, providing pronunciation and answer checking.

An app that randomly draws Japanese vocabularies from N5 to N1 level to test your listening skill, providing pronunciation and answer checking.

Eric Lau 13 Jul 17, 2022