Explanation

The Clice widget will request a token from your backend to identify the currently logged-in user.

Your backend doesn’t need to handle the security, expiration, or validation of this token — Clice servers manage all of that.

However, you must define a route that signs and returns this token when the widget asks for it.


Initialization route

You must create a route on your backend that Clice will call to request an access token.

This token must be signed with your private key, which you can find in the section mentioned earlier.

Keep this key confidential.

Here’s an example of what it looks like:

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAxPquK6ZldHbqmx6B4pS+BFCQg1HBtqC+fb8VPIe872OxpKVd
FjECc4Bi8TAMWscIYzOoec632bSXrussBOZFtyedz61if0EtY/3I5QSMIaMTgtOu
992VF40Qbz/ktwx1wpfxzH3hpF72JcDRwFiTvPYTDfOaCv82vNglY3g7tTjqbCgy
Z2tyqwA2B1tykhLsjPA30g2DBCDtJzO0LDUqLIzDCVwkJgKDM5DCx8ZP2ZS4SkOn
OLptIlSmY5cphToy/6IVX1vm2o3mcSuLGc4PzT85DHQgAbrrCScZ+uTzelkIE9JD
3AzWTdBkniMwpp6giBz5HtuQc+enVGVyqBTlcQIDAQABAoIBAQCBcWahYqCLL1Yu
...
-----END RSA PRIVATE KEY-----

Make sure to preserve line breaks, header, and footer exactly as shown.


The initialization route is a GET request that should return an object containing two properties:

Example implementation:

router.get("/initialize-clice", authMiddleware, async (req, res) => {
	initClice(req.user, req.ip, res);
});

async function initClice(user, ip, res) {
	const ttlSeconds = 10 * 60; // token expires in 10 minutes – adjust as needed for security

	const payload = {
		cuId: user.id,
		email: user.email,
		plan: user.plan,
		name: user.name,
		createdAt: user.createdAt,
	};

	// Sign the token with the RS256 algorithm using your private key as the cryptographic secret
	// Uses the jsonwebtoken library (import * as jwt from "jsonwebtoken")
	const token = jwt.sign(payload, privateKey, {
		algorithm: 'RS256',
		expiresIn: ttlSeconds,
	});

	// Return the token and expiration in ms
	const expMs = Date.now() + ttlSeconds * 1000;
	return res.status(200).send({ token, expMs });
}

Payload field What Clice expects Type
cuId Unique user ID from your application string
email User’s email address string
plan User’s plan (e.g., Premium, Free) string
name User’s name string
createdAt User’s registration date date