Skip to main content

Requirements

  • iOS 13.0+
  • Xcode 12.0+
  • Swift 5.5+
This is the new Headless authentication SDK that is significantly faster and more robust than the previous version. This upgrade enhances performance, reliability, and security, ensuring a seamless authentication experience, along with a seamless integration process. We strongly recommend migrating to the new SDK for improved efficiency and better support. To migrate from the old SDK, remove the previous SDK dependency and integration and follow the below mentioned steps.

Overview

OTPless SDK accepts the user’s identity (phone number or email), authenticates through multiple channels, and returns a secure token upon success.The merchant app sends this token to its backend, which verifies it with the OTPless Server before proceeding with the user journey. SDK Overview Chart

Integration Steps

Step 1: Add SDK Dependency

SDK can be installed via both Cocoapods and Swift Package Manager.
Please find the latest version of the SDK here.

Cocoapods

  • Open your app’s project file .xcodeproj.
  • Add the following line into the dependencies section of your project’s Podfile:
Make sure to run the following commands in your root folder to fetch the dependency.

Swift Package Manager

  1. In Xcode, click File > Swift Packages > Add Package Dependency.
  2. In the dialog that appears, enter the repository URL: https://github.com/otpless-tech/otpless-headless-iOS-sdk.git.
  3. Select the dependency rule as exact version and use the latest version.

Step 2: Configure info.plist

Add the following block to your Info.plist file:
This step is only needed for Magic Link. Smart Auth integration do not require this step.
info.plist
Add the following block to your Info.plist file only if you are using the SNA feature.
  • If the NSAppTransportSecurity key is not already present, add the entire block below.
  • If the NSAppTransportSecurity key is already present, add the listed domains one by one under NSExceptionDomains.
info.plist
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:
This step is only needed for Magic Link. Smart Auth integration do not require this step.

Step 4: Initialize OTPLESS

Import OtplessBM in your signup/sign in file.
Initialise OTPLESS in viewDidLoad() function before proceeding further.
ViewController.swift
Replace YOUR_APP_ID with your actual App ID provided in your OTPLESS dashboard.

Step 5: Handle Callback

Conform to OtplessResponseDelegate in your signup/sign in file to receive callbacks from OtplessBM (SDK callback flow).

Handle Initiate error response:

Handle Verify error response:

Step 6: Create a Task:

Create a task to initiate the authentication process based on the user’s selected method.
  • Store the tasks created during Otpless authentication in the otplessTask variable.
  • Cancel the ongoing task before creating a new task to prevent duplication of requests or sending same request twice.

Response Objects Structure

Step 7: Initiate Authentication

Initiate the authentication process based on the user’s selected method by using the initiate method of the SDK.
Phone Authentication πŸ“±
Phone authentication allows users to verify their identity using their phone number. Merchants can choose from various authentication methods:
  • Silent Authentication (SNA) – Automatically verifies the user without requiring OTP or MAGICLINK.
  • OTP on Desired Channel – Sends a one-time password (OTP) via SMS, WhatsApp, or another preferred channel.
  • Magic Link – Sends a link that users can click to authenticate.
  • SNA + OTP – Uses silent authentication first and falls back to OTP if needed.
  • OTP + Magic Link – Sends both an OTP and a magic link, allowing users to authenticate via either method.

Verify OTP

To verify the OTP entered by the user, use the verify method with the necessary parameters. Verifying OTP is required only in case of OTP authentication. No need to verify OTP in case of MAGICLINK.

🏁 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 Response Structure

The structure of the user information returned upon successful sign-in is as follows:
You can check out a complete sample response here.

Next Steps