Authenticate UIKit to call IQL Backend APIs

The traditional way for the UIKit to correspond with Zendrive's backend is to relay those API calls via the proxy layer implemented by customers in their backend. We have devised a new mechanism that avoids this expensive setup by implementing one backend API alone that serves as a means to source an end user's identity to the UIKit. UIKit can then correspond with Zendrive's backend APIs directly by anchoring trust to this identity provided by our customer's backend. This API is required to generate an identification token - scoped to each individual end user - and pass it back to their application in response to user login or heartbeat API call.

In this section, we discuss how to authenticate UIKit to uniquely identify users so that UIKit can call Zendrive's IQL Backend APIs in a secure fashion. This is done through generation of an identification token that the app shares with UIKit.

If you implement this authentication, you no longer need to implement a proxy layer in your backend. Hence you can skip completely.

Identification Token Flow

1. Generating Identification Token

  • A new token, identification_token is introduced to facilitate user identification.

  • This token must be generated by the client’s backend system in response to the API call using an identity key , identity key id, and driver_id. Customers can choose to create expiring identification_tokens by adding an expiry timestamp and setting identity_v1 as the token's version. This will set the token's expiry to the timestamp (in UTC epoch seconds). Zendrive's backend APIs will not honour an identification_token beyond its expiry timestamp. Alternatively, for customers that do not wish for identification_tokens to expire can generate tokens by prefixing identity_v2 as the token's version and pass the token generation timestamp instead of an expiry timestamp. The downside of this approach is that identification_tokens remain valid forever or until the identity_key used to generate the token is invalidated. For more details on both the versions, see Identification Token Generation Code.

To get the identity key and identity key id, contact Zendrive support.

2. Registration Process

  • The UIKit initially registers a user by passing the identification_token to the backend.

  • The backend validates the identification_token and responds by sharing an access_token with the UIKit.

For more information, see .

3. Subsequent API Calls

  • The UIKit utilizes the received access_token for authentication in all subsequent API calls to Zendrive’s servers.

Identification Token Generation Code

Expiring token generation

import base64
import hmac
import hashlib
import time


def generate_identification_token():
    driver_id = "your_driver_id"
    identity_key_id = "your_identity_key_id"
    identity_key = "your_identity_key"
    expiry_timestamp = "your_expiry_timestamp_in_millis"

    plaintext = "userID=" + driver_id + "\n" + "keyID=" + identity_key_id + "\n" + "expiry=" + expiry_timestamp
    generated_id_token = base64.b64encode(
        hmac.new(identity_key.encode('utf-8'), plaintext.encode('utf-8'), hashlib.sha256).digest()).decode('utf-8')

    identification_token_text = "identity_v1\nid_token=" + generated_id_token + "\nkeyID=" + identity_key_id + "\nexpiry=" + expiry_timestamp
    identification_token = base64.b64encode(identification_token_text.encode('utf-8')).decode('utf-8')

    return identification_token

Non-Expiring token generation

import base64
import hmac
import hashlib
import time


def generate_identification_token():
    driver_id = "your_driver_id"
    identity_key_id = "your_identity_key_id"
    identity_key = "your_identity_key"
    current_timestamp = str(int(time.time()) * 1000)

    plaintext = "userID=" + driver_id + "\n" + "keyID=" + identity_key_id + "\n" + "timestamp=" + current_timestamp
    generated_id_token = base64.b64encode(
        hmac.new(identity_key.encode('utf-8'), plaintext.encode('utf-8'), hashlib.sha256).digest()).decode('utf-8')

    identification_token_text = "identity_v2\nid_token=" + generated_id_token + "\nkeyID=" + identity_key_id + "\ntimestamp=" + current_timestamp
    identification_token = base64.b64encode(identification_token_text.encode('utf-8')).decode('utf-8')

    return identification_token

Last updated