Prerequisites

  1. Make sure you have followed the SDK Setup Guide before starting with this document.
  2. Ensure you have admin access to the OTPless Account.

Configure OAuth platforms on Dashboard

  1. Log in to the OTPless dashboard with your registered email ID.
  2. Go to Configure Channel.
  3. Enable the channels from list of social Auth.

Important: Don’t forget to save and publish the configuration.

Choose your Programming Language:

Step 1: Initiate Social Auth

To initiate Social Auth for phone number or email verification

Request

final HeadlessRequest request = new HeadlessRequest();
request.setChannelType(HeadlessChannelType.SOCIAL_CHANNEL_NAME);
otplessView.startHeadless(request, this::onHeadlessCallback);

Enums for social auth

[
  "WHATSAPP",
  "GMAIL",
  "APPLE",
  "LINKEDIN",
  "MICROSOFT",
  "FACEBOOK",
  "SLACK",
  "TWITTER",
  "DISCORD",
  "LINE",
  "LINEAR",
  "NOTION",
  "TWITCH",
  "GITHUB",
  "BITBUCKET",
  "ATLASSIAN",
  "GITLAB",
  "TRUE_CALLER"
]

Response

{
  "statusCode": 200,
  "success": true,
  "response": {
    "channel": "OAuth",
    "channelType": "WHATSAPP",
    "requestId": "xxxxxxxxxxxxxxxx"
  }
}

Step 2: Get Auth Token

Awesome! You’ve completed the client-side integration. Now, after the User identity is verified with social platform, you’ll get a callback with the ONETAP response containing the token. You’ll need to parse the token from the response JSON.

Sample Callback JSON

{
  "responseType": "ONETAP",
  "statusCode": 200,
  "response": {
    "status": "SUCCESS",
    "token": "unique_token_here",
    "userId": "unique_user_id_here",
    "timestamp": "ISO_timestamp_here",
    "identities": [
      {
        "identityType": "MOBILE",
        "identityValue": "919899038845",
        "channel": "WHATSAPP",
        "methods": [
          "WHATSAPP"
        ],
        "name": "Satyam Nathani",
        "verified": true,
        "verifiedAt": "2024-08-05T14:02:57Z"
      }
    ],
    "idToken": "jwt_token",
    "network": {
      "ip": "127.0.0.1",
      "timezone": "Asia/Kolkata",
      "ipLocation": {}
    },
    "deviceInfo":{},
    "sessionInfo":{},
    "firebaseInfo":{}
  }
}

You can view a complete sample response here

How to parse the token from response?

private void onHeadlessCallback(HeadlessResponse response) {
    if (response.getStatusCode() == 200) {
        switch (response.getResponseType()) {
            case "ONETAP":
                // final response with token
                JSONObject responseWithToken = response.getResponse();
                // Your API to send the token to your backend and then follow the next step.
                break;
            // other response types
        }
        JSONObject successResponse = response.getResponse();
    } else {
        // handle error
        String error = response.getResponse().optString("errorMessage");
    }
}

🏁 Check Point : Verify Auth Token

Once you have retrieved the token, send it to your backend and call the verify token API.

Verify Token API →

Was this page helpful?