Introduction
Welcome to the OTPLESS Headless SDK documentation! This guide will walk you through the steps to integrate our SDK into your Android project, providing you with the flexibility to create custom UI elements for your authentication flows.
Step 1: Install OTPLESS SDK Dependency
Install the OTPLESS SDK dependency by running the following command in your terminal at the root of your Ionic project:
Step 2: Platform-specific Integrations
- Add intent filter inside your
android/app/src/main/AndroidManifest.xml
file into your Main activity code block:
- 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):
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
- Change your activity launchMode to singleTop and exported true for your Main Activity:
- Add the following override method in
android/app/src/main/java/MainActivity.java
to handle callback:
- Import the following classes:
- Add this code to your
onCreate()
method in your main activity:
- Add this code to your
onBackPressed()
method in your main activity:
Step 3: Configure Sign up/Sign in
Great! Now let’s configure your activity for sign-up or sign-in. Below are the steps for both Java and Kotlin.
First, import the necessary classes from the OTPLESS SDK:
Declare an OtplessView
instance:
Within your onCreate()
method, initialize and set up the OTPLESS sign-in:
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
Step 4: Setup your login screen
In your login screen, add the following code to initialize OTPLESS SDK:
Now, let’s implement a callback method to handle the response from the OTPLESS SDK:
Data received from OTPLESS contains the following ResponseTypes
:
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. |
Override onNewIntent()
Ensure you override the onNewIntent()
method to correctly handle intent verification:
Override onBackPressed()
Override the onBackPressed()
method to manage back press actions properly:
Step 5: Initiate Authentication
Well done! You have completed the foundational setup of the SDK. Now, let’s move to the next step and understand how to initiate and verify different authentication modes.
Choose the authentication mode you want to integrate from the options below:
OTP
Send a One-Time Password (OTP) via SMS, WhatsApp, or Email for secure user verification.
Magic Link
Provide a seamless login experience by sending an authentication link through SMS, WhatsApp, or Email.
Social Auth
Authenticate users through popular social applications like WhatsApp, Google, Apple, and GitHub.
Was this page helpful?