Authentication
ENGAGE® SDK Authentication
Authenticating the host app with the ENGAGE platform is required to validate the communication between the device and platform.
The following authentication mechanisms are possible:
- Silent Registration (PUSH or PIN): Auto resolves in the background and does not require user interaction
- SMS: Requires user interaction to verify a PIN via SMS
Step 1. Configure ENGAGE Plugin
Configure the ENGAGE Plugin before starting the app in the main.dart
.
Use await at method call with the combination of async keyword in front of the function body to declare an asynchronous function in Dart and Flutter.
NOTE:
EngageEnvironment.debug
andgroup.your-app-group-id
are specific parameters used in iOS configuration. Since they are not relevant for Android, passing null for these parameters is acceptable and will not affect the functionality on Android platforms.
import 'package:flutter/material.dart';
import 'package:flutter_engage_plugin/engage.dart';
import 'package:flutter_engage_plugin/utils/const.dart';
void main() async {
// Ensure that Flutter widgets are initialized.
WidgetsFlutterBinding.ensureInitialized();
// Initialize the Engage SDK asynchronously.
await Engage.instance.configureSDK(EngageEnvironment.debug, "group.your-app-group-id");
// Run the Flutter application.
runApp(const MyApp());
}
Step 2. Handlers
There is one main interface that the host app can implement that allows them to receive callbacks for certain actions involved in registration.
EngageRegistrationHandler
abstract class EngageRegistrationHandler {
/// Called when challenge is initialized successfully
void onInitializationSuccess(String? userNumber);
/// Called when number is registered successfully
void onRegistrationSuccess(String? userNumber);
/// Called when registration fails
/// @param phoneNumber Phone number that failed to register
/// @param error The reason of the error
void onRegistrationFailure(
String? phoneNumber, EngageRegistrationError? error);
}
Step 3. Registration
To register a phone number, pass the phone number along with EngageResigistationHandler
callback:
Engage.instance.register(phoneNumber: number, engageRegistrationHandler: this);
NOTE: If the SMS registration is used, the 6-digit code delivered in the SMS needs to be passed to ENGAGE:
Engage.instance.completeChallengeWithCode(code, (usernumber) => {print('sms verify')});
Updated 7 months ago