Creating app switch URLs

In rare cases you may need to programmatically create an app switch URL from an existing key. In those cases, you need to hand-craft the URL in the following format:

ai.unloc.pro://use-key?id=<key ID>&r=<return URL>&n=<partner ID>&s=<HMAC>

Example URL:

ai.unloc.pro://use-key?id=86477029-5db2-4bc4-bdf9-eaf2e9aad759&r=myapp://&n=acbpartner&s=09ffe07e72343e1e456b2e64618f99fba4691e4c1323d0f98dba139d6bca83ba

Tapping the URL on an iPhone or Android phone will bring up the Unloc Work app and make the key available for use. Dismissing the key screen in the Unloc Work app will bring the user back to the originating app, via the return URL.

Info

The simplest way to create app switch URLs is to use the returnUrl parameter when you create new keys.

The App Switch URL requires the following query parameters:

Parameter Meaning
id  The key ID
r The return URL that the Unloc app will open when the key screen is dismissed
n The partner ID
s HMAC-SHA256 signature (see below)

HMAC

The URL is authenticated with an HMAC-SHA256 signature. The signature is produced with the partner's HMAC secret.

The HMAC is generated from the query parameters as follows:

HMAC_SHA256(hmacSecret, "id=<Key ID>&r=<return URL>&n=<partner ID>")

Note

Partners receive their HMAC secret when they sign up with Unloc.

Examples on how to implement the HMAC signature in Node and Ruby:

// node.js example
// generate app switch url with hmac signature

const crypto = require('crypto');
const hmacSecret = 'secret-123';
const hmac = crypto.createHmac('sha256', hmacSecret);
const returnUrl = 'myapp://';
const partnerId = 'partner-x';

const keyId = '117ec32d-5ac3-422b-82de-cbb64540bffd';
console.log(appSwitchUrl(keyId));

function appSwitchUrl(keyId) {
    const params = `id=${keyId}&r=${returnUrl}&n=${partnerId}`;
    hmac.update(params);
    const s = hmac.digest('hex');
    return `ai.unloc.pro://use-key?${params}&s=${s}`;
}
# ruby example
# generate app switch url with hmac signature

require 'openssl'

def app_switch_url(key_id)
    hmac_secret = 'secret-123'
    return_url = 'myapp://'
    partner_id = 'partner-x'
    params = "id=#{key_id}&r=#{return_url}&n=#{partner_id}"
    s = OpenSSL::HMAC.hexdigest('SHA256', hmac_secret, params)
    return "ai.unloc.pro://use-key?#{params}&s=#{s}"
end

key_id = '117ec32d-5ac3-422b-82de-cbb64540bffd'
print app_switch_url(key_id)