Optimistic Access to Media
Overview
With set_async: true, Create Entitlement returns before the purchase is confirmed. Confirmation takes
from a few seconds to about a minute, and until then the user's token doesn't grant access to the purchased media.
To let the user play right away, give them a token that carries a signed claim for each pending purchase. A claim grants access to that purchase's media until the purchase is confirmed.
Approaches
asset_claimer makes the server run the refresh step for you during the purchase call. Otherwise, the user's app
refreshes its own token.
| Approach | Who refreshes the token | Calls | Claims in the token |
|---|---|---|---|
asset_claimer | The server, during purchase | 1 | All entitlements from the last 10 min |
include_asset_claims | The user's app | 2 | All entitlements from the last 10 min |
asset_claims | The user's app | 2 | Only the ones you send |
Most integrations should use one of the first two.
Server refresh: asset_claimer
Send the user's current session on the purchase call. The server refreshes it and returns the new tokens.
{
"set_async": true,
"asset_claimer": {
"refresh_token": "<user's refresh_token>",
"nonce": "<device_id bound to that refresh_token>"
},
...
}
The 202 response includes asset_claims_tokens, a ready-to-use user token and refresh token:
"asset_claims_tokens": {
"fabric_token": "<new user token, with claims>",
"refresh_token": "<new refresh token>"
}
fabric_tokenis the same kind of token that Token Refresh returns astoken.- The new
refresh_tokenreplaces the one you sent. Give both new tokens to the user's app, and use the new refresh token from then on: a refresh with the old one can fail.
App refresh: include_asset_claims
After the purchase call returns, the user's app calls Token Refresh with
include_asset_claims: true:
{
"refresh_token": "<user's refresh_token>",
"nonce": "<device_id>",
"include_asset_claims": true
}
The returned token carries claims for the user's recent entitlements. User Sign In
accepts the same flag.
Choosing which purchases are included
To include only specific purchases instead of every recent one:
- Call Create Entitlement with
set_async: trueandinclude_pending_claims: true. Leave outasset_claimer. The response includesasset_claims, an array of signed claims for this purchase only, one per SKU. - Create Entitlement is called from your backend, so the claims arrive there. Keep them, and pass the ones you want to the user's app.
- The user's app calls Token Refresh with those claims, without
include_asset_claims:
{
"refresh_token": "<user's refresh_token>",
"nonce": "<device_id>",
"asset_claims": [
"<claim from the latest purchase>",
"<claim from the previous purchase>"
]
}
- Each claim is valid for 10 minutes from when Create Entitlement returned it.
- A claim that has expired, or was issued for a different user, is left out of the token. The refresh still succeeds.
- A token carries only the claims sent with that refresh. Send them again on any refresh made while the purchase is still pending.
- User Sign In doesn't accept
asset_claims.
Notes
- Request claims only while a purchase is still pending. Once Poll Entitlement Status
reports
complete, routine refreshes don't need them. - If a purchase isn't confirmed within 10 minutes, its claim expires and the user can't play it until it's confirmed.