Cashfree’s react native DigiLocker SDK allows you to seamlessly integrate DigiLocker-based identity verification into your mobile application. With this SDK, you can securely initiate DigiLocker flows, collect user consent, and retrieve verified government-issued documents. This guide provides step-by-step instructions to help you:
  • Install and configure the React Native SDK.
  • Generate DigiLocker consent URLs from your backend.
  • Launch DigiLocker in your React Native app.
  • Handle consent flows and user responses.
  • Fetch and verify user documents via secure APIs.
All sensitive operations such as generating DigiLocker URLs and retrieving documents, must be performed on your backend server. Don’t call these APIs directly from your frontend or mobile application.

Setting up SDK

The React Native SDK is hosted on npm. You can get the latest SDK here. Our React Native SDK supports Android SDK version 19 and above and iOS minimum deployment target of 10.3 and above. Navigate to your project and run the following command:
npm install @cashfreepayments/react-native-digilocker
For iOS, you need to install pods:
cd ios && pod install

Step 1: Create DigiLocker URL

To initiate the DigiLocker integration flow, your application must generate a DigiLocker consent URL. This action must be performed from your backend server, as it requires authentication using your Client Secret. Don’t call this API directly from your frontend or mobile application. Once the DigiLocker URL is successfully generated, the API returns a unique reference_id. Either this reference_id or the verification_id passed by you can be used in all the subsequent API calls. You can view the complete request and response examples in the Create DigiLocker URL API reference.

Step 2: Opening the DigiLocker SDK

Once the DigiLocker URL is created, the next step is to open the DigiLocker URL so the user can give the consent. The React Native SDK offer below digilocker redirection flow:

Initialise app

import { DigiLockerProvider } from '@cashfreepayments/react-native-digilocker';

function App() {
  return (
    <DigiLockerProvider >
      {/* Your app content */}
    </DigiLockerProvider>
  );
}

Step 3: Call verify function to initiate DigiLocker flow

const { verify } = useDigiLocker(); 

verify(
  url: string,                    // DigiLocker URL to load
  redirectUrl?: string,           // Optional redirect URL (default: 'https://verification.cashfree.com/dgl/status')
  options?: {
    userFlow?: 'signin' | 'signup';      // Optional user flow type (restricted to 'signin' or 'signup')
    onSuccess?: (data: any) => void;     // Success callback
    onError?: (error: string) => void;   // Error callback
    onCancel?: () => void;               // Cancel callback
  }
);
Success callback
{
  success: true,
  redirect_url: 'https://example.com/thank-you?verification_id=123'
}
You can view the example implementation in the DigiLocker React Native SDK GitHub repository.

Step 4: Check verification status

Use the Get Verification Status API with the verification_id received in the success callback to retrieve the current verification status.

Step 5: Retrieve document

Once the user has successfully logged in and provided consent, call the Get Document API to fetch verified documents like Aadhaar, PAN, or driving license.
Steps 4 and 5 must be performed from your backend server. Don’t call this APIs directly from your frontend or mobile application.