Skip to main content

Secure Tokens

Secure tokens let you personalize campaigns with user data — pre-filling known fields or identifying the participant — in a way that cannot be tampered with by the client. A token is a signed JWT generated by your backend and attached to the campaign.

When a secure token provider is registered, the SDK calls it every time a campaign is launched or embedded inline and appends the returned token to the campaign URL as the qual_token query parameter.

Registering a token provider (Kotlin)​

Use setSecureTokenProvider with a suspending lambda that returns a token for a given campaign:

import com.qualifio.Qualifio

Qualifio.setSecureTokenProvider { campaign ->
// Ask your backend to mint a signed token for the current user.
backend.mintToken(campaign) // a String, or null to launch without a token
}

The lambda has the following type:

typealias QualifioSecureTokenGenerator = suspend (String) -> String?
AspectDetails
Argumentcampaign — the slug of the campaign about to be launched.
ReturnsThe token String, or null to launch without a token.
  • Return a String to attach it to the campaign as qual_token.
  • Return null to launch the campaign without a token.

Because the provider is suspend and receives the campaign slug, you can perform asynchronous work (such as a network request) and mint campaign-specific tokens if your signing logic depends on the target campaign.

Registering a token provider (Java)​

From Java, implement the QualifioSecureTokenProvider functional interface, which delivers its result through a QualifioCallback:

Qualifio.setSecureTokenProvider((campaign, callback) -> {
try {
String token = backend.mintToken(campaign); // your code
callback.onSuccess(token); // or onSuccess(null)
} catch (Exception e) {
callback.onFailure(e);
}
});

The QualifioCallback interface​

interface QualifioCallback<T> {
fun onSuccess(result: T)
fun onFailure(e: Exception)
}

The same interface is used by the callback overload of launchCampaign.

When and how the token is applied​

Each time a campaign is launched or an inline campaign starts loading, the SDK:

  1. Calls your registered provider with the campaign slug.
  2. If a non-null token is returned, appends it to the campaign URL as ?qual_token=<token>.
  3. Opens the campaign in the Custom Tab, or loads it in the inline view.

Error handling​

Token generation is bounded by a timeout, so a slow provider cannot block a campaign launch indefinitely.

If your provider throws, times out, or its result is null, the SDK logs the problem and launches the campaign without a token. This means a transient token-service failure degrades gracefully rather than blocking the user.

Security best practices​

  • Generate tokens on your server, never on the device. The signing secret must never be embedded in your app.
  • Keep tokens short-lived. Mint them on demand so each launch uses a fresh token.
  • Scope tokens to the current user (and campaign, if applicable).

Next steps​

  • Campaigns — launch or embed a campaign with the token applied.