Pre-Built UI
Leverage our Pre-Built UI for rapid integration and customization of authentication flows in your application. This setup allows you to adjust appearance and functionality through the OTPLESS dashboard with minimal coding.
Step 1: Add SDK Dependency
To get started, incorporate the OTPLESS SDK into your project. Update your app’s build.gradle
file by adding the following dependency:
implementation 'io.github.otpless-tech:otpless-android-sdk:2.5.1'
Make sure to synchronize
your Gradle project to fetch the dependency.
Step 2: Configure AndroidManifest.xml
Modify your AndroidManifest.xml
to include an intent filter within the activity responsible for sign-up or sign-in. This setup is crucial for handling deep links.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="otpless" android:scheme="otpless.your_app_id_in_lowercase" />
</intent-filter>
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
Additionally, ensure your activity is set to singleTop
launch mode and exported
attribute is true:
android:launchMode="singleTop"
android:exported="true"
Step 3: Configure Your Signup/Sign In Activity
First, import necessary classes from the OTPLESS SDK:
import com.otpless.dto.OtplessResponse;
import com.otpless.main.OtplessManager;
import com.otpless.main.OtplessView;
Declare an OtplessView
instance:
OtplessView otplessView;
Within your onCreate()
method, initialize and set up the OTPLESS Sign in:
// Initialise OtplessView
otplessView = OtplessManager.getInstance().getOtplessView(this);
OtplessRequest request = new OtplessRequest("YOUR_APP_ID");
otplessView.setCallback(request, this::onOtplessCallback);
otplessView.showOtplessLoginPage(request, this::onOtplessCallback);
Configure Auth Method
Select from a wide array of auth methods, including SMS, WhatsApp, Email, Google, and many more
Configure UI
Customize logos, headings, color schemes, and more to match your brand identity and improve UX.
Step 4: Handle Callback
Implement a callback method to handle the response from the OTPLESS SDK:
private void onOtplessCallback(OtplessResponse response) {
if (response.getErrorMessage() != null) {
// Handle error
} else {
final String token = response.getData().optString("token");
// Proceed with token verification
Log.d("Otpless", "Token: " + token);
}
}
Override onNewIntent()
Ensure you override the onNewIntent()
method to correctly handle intent verification:
if (otplessView != null) {
otplessView.onNewIntent(intent);
}
Step 5: Handle Back Press
Override the onBackPressed()
method to manage back press actions properly:
// make sure you call this code before super.onBackPressed();
if (otplessView.onBackPressed()) return;
🏁 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:
{
"status": "SUCCESS",
"token": "unique_token_here",
"userId": "unique_user_id_here",
"timestamp": "ISO_timestamp_here",
"identities": [
{
"identityType": "EMAIL",
"identityValue": "user@example.com",
"channel": "OAUTH",
"methods": [
"GOOGLE"
],
"name": "User Name",
"verified": true,
"verifiedAt": "ISO_timestamp_here",
"isCompanyEmail": "true"
}
],
"idToken": "jwt_token",
"network": {
"ip": "127.0.0.1",
"timezone": "Asia/Kolkata",
"ipLocation": {}
},
"deviceInfo": {},
"sessionInfo": {},
"firebaseInfo": {},
}
You can check out a complete sample response here.
Next Steps
Was this page helpful?