Step 1: Add SDK Dependency

  • Open your app’s project file .xcodeproj.
  • Add the following line into the dependencies section of your project’s Podfile:
pod 'OtplessSDK', '2.1.1'

Make sure to run the following commands in your root folder to fetch the dependency.

pod repo update
pod install

Step 2: Configure info.plist

Add the following block to your info.plist file:

info.plist
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>otpless.{{YOUR_APP_ID}}</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>otpless</string>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>whatsapp</string>
    <string>otpless</string>
    <string>gootpless</string>
    <string>com.otpless.ios.app.otpless</string>
    <string>googlegmail</string>
</array>

Replace YOUR_APP_ID with your actual App ID provided in your OTPLESS dashboard.

Step 3: Handle Redirection

Add the following code to your App Delegate to handle redirection:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { 
    if Otpless.sharedInstance.isOtplessDeeplink(url: url){
    Otpless.sharedInstance.processOtplessDeeplink(url: url) }
    return true 
}

Step 4: Initialize OTPLESS

Import OtplessSDK in your signup/sign in file.

import OtplessSDK

Initialise OTPLESS in viewDidLoad() function before proceeding further.

Otpless.sharedInstance.initialise(vc: self, appId: ("{YOUR_APP_ID}"))
Otpless.sharedInstance.headlessDelegate = self

Step 5: Handle Callback

Conform to onHeadlessResponseDelegate in your signup/sign in file to receive callbacks from OtplessSDK.

func onHeadlessResponse(response: OtplessSDK.HeadlessResponse?) {
	if response?.statusCode == 200 {
		let successResponse = response?.responseData
	}
	else {
		let error = (response?.responseData)?["errorMessage"] as? String
	}
}

Step 6: Initiate Authentication

Initiate the authentication process based on the user’s selected method by using the initiate method of the SDK.

let headlessRequest = HeadlessRequest()
headlessRequest.setPhoneNumber(number: "9899XXXXXX", withCountryCode: "+91")
Otpless.sharedInstance.startHeadless(headlessRequest: headlessRequest)

(Optional): Verify OTP

To verify the OTP entered by the user, use the verify method with the necessary parameters.

let headlessRequest = HeadlessRequest()
headlessRequest.setPhoneNumber(number: "9899XXXXXX", withCountryCode: "+91")
Otpless.sharedInstance.verifyOTP(otp: "OTP", headlessRequest: headlessRequest)

Replace YOUR_APP_ID with your actual App ID provided in your OTPLESS dashboard.

Object Attributes

AttributeMandatoryDescription
channelYesThe authentication method selected by the user.
phoneConditionalUser’s phone number (required if channel is PHONE).
countryCodeConditionalCountry code of the phone number (required if channel is PHONE).
emailConditionalUser’s email (required if channel is EMAIL).
channelTypeConditionalType of social login initiated (required if channel is OAUTH).

🏁 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