Skip to content

techsmsidea/authyo-flutter-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Authyo Flutter Plugin

A Flutter plugin for integrating Authyo – a powerful multi-channel MFA service supporting WhatsApp, SMS, Email, and Call for OTP verification.

This plugin enables developers to implement OTP-based authentication for both legacy systems and modern, passwordless solutions with minimal configuration.

πŸš€ Features

  • πŸ“± Multi-channel support (WhatsApp, SMS, Email, Call)
  • 🧩 Plug-and-play OTP UI (or bring your own)
  • 🧾 Works for both new and legacy systems
  • πŸ” Configurable channel priority (no redeploy needed)
  • πŸ” JWT-based login for new systems
  • πŸ”§ REST API Support
  • πŸ“Š Transparent billing & usage dashboard
  • πŸ†“ Free trial for all new accounts
  • 🀝 Affiliate support built-in

πŸ”§ Installation

Add the dependency in your pubspec.yaml:

dependencies:
  authyo_flutter: <latest_version>

Run:

flutter pub get

πŸ› οΈ Usage

1. Legacy Systems (UI Provided)

2. Modern Systems (Passwordless)

Process

πŸ› οΈ Getting Started

1. Install

Add to your pubspec.yaml:

dependencies:
	authyo_plugin: ^1.0.0 //Latest versions may vary

Import in your Dart code:

import 'package:authyo_plugin/authyo_plugin.dart';

2. Initialize

Important:
You must initialize AuthyoService with your clientId and clientSecret before making any requests.

//Get AuthyoService Instance
final AuthyoService authyoService = AuthyoService.instance;

//Initialize AuthyoService using your Authyo credentials
authyoService.init(clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET");

🚦 Usage

πŸ”‘ Send OTP

// Call sendOtp function using AuthyoService
AuthyoResult otpResult = await authyoService.sendOtp(
    ctx: context,
    to: β€˜+1234567890’, // or β€˜user@email.com’
    otpLength: 6, // optional, defaults to 6
    expiry: 180, // optional, in seconds
    authWay: AuthwayEnum.SMS, // optional, can be SMS, Whatsapp, Email, Voice
    onVerificationComplete: (authyoResult) {
        // This callback is optional and only necessary if plugin's default OTP verification dialog is used.
        // If custom UI for OTP verification is used, you can omit this callback.
        // Check for result.
        if (authyoResult.result?.error == null) {
            // Verification successful.
        }
    });

bool success = otpResult.result?.data?.results?.firstWhere((element) => element.success == true, orElse: () => Results(success: false)).success;

if (success == true) {
  print("βœ… OTP Sent: ${otpResult.result?.message}");
} else {
  print("❌ Error: ${otpResult.error?.message}");
}

πŸ›‘οΈ Verify OTP

// Call verifyOtp function using AuthyoService instance
AuthyoResult otpResult = await AuthyoService.instance.verifyOtp(maskId: "Mask ID",otp: "Received OTP");

if(otpResult.result!=null){
	print("Success: ${otpResult.result?.message}");
}
else{
	print("Error: ${otpResult.error?.message}");
}

πŸ“š API Reference

Methods

init
init({required String clientId, required String clientSecret, Duration? connectTimeout, Duration? receiveTimeout, bool? showVerificationDialog})
sendOtp
Future<AuthyoResult> sendOtp({
required String to,
int otpLength = 6,                 
int? expiry,
AuthwayEnum? authWay,
void Function(AuthyoResult authyoResult)? onVerificationComplete
});
  • to: Phone number or email (required)
  • otpLength: Length of OTP (optional, defaults to 6)
  • expiry: OTP expiry in seconds (optional)
  • authWay: Channel to send OTP (optional, defaults to dashboard preference)
  • onVerificationComplete: Optional callback function which provide if authentication is successful or not. Only required when plugin's default OTP verification dialog is being used.

Returns: AuthyoResult

verifyOtp
Future<AuthyoResult> verifyOtp({required String maskId, required String otp})
  • maskId: Received from sendOtp response (required)
  • otp: The OTP entered by the user (required)

Returns: `AuthyoResult


AuthyoResult

A wrapper for API responses.

class AuthyoResult {  
  final AuthyoResponseModel? result;  
  final AuthyoError? error;  
  AuthyoResult.success(this.result) : error = null;  
  AuthyoResult.failure(this.error) : result = null;  
}

AuthyoBaseResponse

For sendOtp:

{
	"success":  true,
	"message":  "submited successfully",
	"data":  {  
		"isTried":  1,
		"isSent":  1,
	    "results":  [
		    {	"success":  true,
			    "message":  "message submitted successfully",
			    "to":  "919898******",
			    "authtype":  "WHATSAPP",
			    "maskId":  "36eeb3a16fAaAab49b48de0d729b9a35",
			    "createdTime":  1747312374,
			    "expiretime":  1747312434
			}
		]
	}
}

For verifyOtp:

{
    "success": true,
    "message": "OTP Verified Successfully",
    "status": "verified",
    "data": {
        "tokenType": "Bearer",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJGYTh6bE92N2FMUTdRcEl6enVkQnh3R0VxMVhTZUFCalRvcXdjcE0zM2w4PSIsImlzcyI6Imh0dHBzOi8vYXV0aHlvLmlvIiwiYXVkIjoiYWVhNWRhYzBlMjNDhiZmJjYzhjMTdmMDM2ZDlhZjgiLCJpYXQiOiIxNzUxOTA0MzkyIiwiZXhwIjoiMTc1MTkwNDY5MiIsInVzZXJJZCI6IkFZLUZhOHpsT3Y3YUxRN1FwSXp6dWRCeHdHRXExWFNlQUJqVG9xd2NwTTMzbDg9IiwicGhvbmUiOiI5MTc0MDUwODkwOTkifQ.6U3gFxTqSTuHNtsA77pRfvo8i9f0wfgvqbWb088v8Lg",
        "expiresIn": 300,
        "user": {
            "phone": "9174050*****",
            "userId": "AY-Fa8zlOv7aLQ7QpIzzudBGEq1XSeABjToqwcpM33l8="
        }
    }
}

❗ Error Handling

All errors are subclasses of AuthyoError, including:

  • BadRequestError (400)
  • UnauthorizedError (401)
  • ForbiddenError (403)
  • NotFoundError (404)
  • TooManyRequestsError (429)
  • InternalServerError (500)
  • ServiceUnavailableError (503)
  • NetworkError
  • TimeoutError
  • UnknownApiError

πŸ“˜ Documentation

Read the full documentation for implementation steps, API tokens, dashboard configuration, and more.

πŸ§ͺ Try It Free

Sign up at authyo.io and get free credits to test MFA in your app.

🧍 Affiliate Program

Promote Authyo and earn revenue. Details on your Authyo Dashboard.

πŸ“« Support

For issues, feature requests, or contributions, file a GitHub issue or contact support via authyo.io.

About

Authyo sdk for flutter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •