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:

build.gradle
implementation 'io.github.otpless-tech:otpless-android-sdk:2.3.3'

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.

AndroidManifest.xml
<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}}" />
</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:

AndroidManifest.xml
android:launchMode="singleTop"
android:exported="true"

Step 3: Configure Your Signup/Sign In Activity

Import SDK Classes

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_HERE}}");
otplessView.setCallback(request, this::onOtplessCallback);
otplessView.showOtplessLoginPage(request, this::onOtplessCallback);
otplessView.verifyIntent(getIntent());

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.verifyIntent(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:

  1. Deploy your app/website with the included OTPLESS SDK.
  2. Conduct tests to verify the sign-in flow functions correctly.
  3. 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 JSON

The structure of the user information returned upon successful sign-in is as follows:

{
  "token": "unique_token_here",
  "userId": "unique_user_id_here",
  "timestamp": "ISO_timestamp_here",
  "identities": [
    {
      "identityType": "EMAIL",
      "identityValue": "user@example.com",
      "channel": "GMAIL",
      "methods": ["OAUTH"],
      "name": "User Name",
      "verified": "true",
      "verifiedAt": "ISO_timestamp_here",
      "isCompanyEmail": "true"
    },
    ...
  ],
  ...
}

Next Steps