Headless
Utilize our Headless SDK for ultimate flexibility. This guide provides detailed instructions on integrating custom UI elements with OTPLESS’s backend authentication functions.
Step 1: Install OTPLESS SDK Dependency
Install the OTPLESS SDK dependency by running the following command in your terminal at the root of your Flutter project:
Step 2: Platform-specific Integrations
- Add intent filter inside your
android/app/src/main/AndroidManifest.xml
file into your Main activity code block:
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
- Add Network Security Config inside your
android/app/src/main/AndroidManifest.xml
file into your<application>
code block (Only required if you are using the SNA feature):
- Change your activity launchMode to singleTop and exported true for your Main Activity:
- Add the following override method in
android/app/src/main/kotlin/MainActivity.kt
to handle callback:
- Import the following classes:
- Add this code to your
onBackPressed()
method in your main activity:
Step 3: Initialize OTPless
- Import the OTPLESS
package
on your login page.
- Create an instance of otpless plugin in your dart file.
- Override the
initState
function and add the following code:
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
- Add a method to receive callbacks from OTPless
ResponseType | Description |
---|---|
INITIATE | When authentication is initiated. |
VERIFY | When OTP is verified for an authentication and in case of link based authentication when user redirected back to the application after clicking the link. |
ONETAP | This is the final response of an authentication session. It includes the token that should be sent to your backend for server-to-server validation. |
OTP_AUTO_READ | When the OTP is automatically retrieved from SMS or WhatsApp. It includes OTP value in this responseType |
Error Codes
StatusCode | ErrorMessage | Short Description |
---|---|---|
401 | Unauthorized request! Please check your appId | Suggests missing or invalid app ID for authorization. |
500 | API_ERROR | Indicates a server-side error, possibly due to parameter issues. |
4000 | The request values are incorrect, see details. | Points to incorrect request values; refer to details for corrections. |
4001 | OTPless headless SDK doesn’t support 2FA as of now | Indicates the lack of 2FA support in the SDK. |
4002 | The request parameters are incorrect, see details. | Suggests parameter errors; check details for specifics. |
4003 | The request channel is incorrect, see details. | Notes an incorrect request channel; see details for correct usage. |
5002 | No internet connection is present. | Indicates no internet connection, troubleshoot network and device. |
Step 4: Initiate Authentication
Initiate the authentication process based on the user’s selected method by using the initiate
method of the SDK.
(Optional): Verify OTP
To verify the OTP entered by the user, use the verify
method with the necessary parameters.
Object Attributes
Attribute | Mandatory | Description |
---|---|---|
channel | Yes | The authentication method selected by the user. |
phone | Conditional | User’s phone number (required if channel is PHONE). |
countryCode | Conditional | Country code of the phone number (required if channel is PHONE). |
email | Conditional | User’s email (required if channel is EMAIL). |
channelType | Conditional | Type of social login initiated (required if channel is OAUTH). |
🏁 Checkpoint
To ensure a smooth integration process:
- Deploy your app/website with the included OTPLESS SDK.
- Conduct tests to verify the sign-in flow functions correctly.
- Ensure that after a successful sign-in, the user is redirected back to your app/website and their information is correctly logged in the console.
User Information Response Structure
The structure of the user information returned upon successful sign-in is as follows:
You can check out a complete sample response here.
Next Steps
Was this page helpful?