SDK Authentication
Your SDK key is publishable: it ships inside your website or app, and anyone can read it. On its own it proves which app a request comes from, not which user. SDK Authentication closes that gap. Your server signs a short-lived token for the signed-in user, the SDK sends it with every request that names that user, and Joryio refuses a request whose token is missing, invalid, expired or for someone else.
It is optional and set per app. This page covers the whole flow; each SDK page has a short section with that SDK's methods.
What it protects
Without SDK Authentication, a request that carries a userId is a claim: anyone holding your SDK key and a user's id could act on that user's profile. With it on, these sensitive writes for an identified user need that user's token:
- consent and subscription changes (channel subscriptions, subscription groups, the opt-out record)
- push registration
- profile attributes and aliases
identify, which can merge an anonymous profile into the user- events tracked for the user
Re-subscribing someone who opted out from the SDK also needs a verified user - see Other write responses.
Anonymous visitors keep working. An anonymous id cannot be authenticated, so requests that name no user are accepted without a token - events, attributes, consent, push registration and aliases alike. One rule keeps this from being a way around the token: an anonymousId that already belongs to an identified user cannot write to that user's profile (403 with code: "SDK_ANONYMOUS_ID_IDENTIFIED").
Turn it on for an app
- Create a key pair on your server (see Keys). Keep the private key there.
- In the Joryio dashboard, go to Settings → Apps.
- On the app's row, click the shield icon (SDK Authentication).
- Paste the public key into Public key (PEM) - an RSA or EC public key in PEM format (
-----BEGIN PUBLIC KEY-----). - Click Enable. The status changes to On - public key registered.
Token checks. The same dialog shows the app's ID - put it in every token's aud - and an optional Expected issuer (iss). See Audience and issuer.
It takes effect within a minute. Turn it on for each app separately - your web, iOS and Android apps each have their own setting, and they can share one key pair.
Ship the token first. Once it is on, a request that names a user and carries no valid token is refused. Release the app versions that set tokens before you click Enable, or test on a separate app first. The SDKs keep refused requests of the signed-in user queued while they wait for a token, but users of an older build that never sets one stay refused.
To replace the key, paste the new one and click Save. To turn it off, click Disable: the key is deleted and the app goes back to the SDK key alone.
Sign tokens on your server
The token is a JWT:
| Algorithm | RS256 (RSA key) or ES256 (EC P-256 key). Any other algorithm is refused. |
sub | Required. The user ID exactly as you pass it to identify() - a string. |
exp | Required. A token without an expiry is refused. |
aud | Required. The app's ID (Settings → Apps, or GET /apps) - a string, or an array that contains it. See Audience and issuer. |
iat | Recommended. |
nbf | Optional. A token used before its nbf is refused. |
iss | Required only when the app has an expected issuer set: it must match it exactly. |
Joryio checks the signature, the algorithm, exp, sub, aud and, when set, iss. Keep the lifetime short - 15 minutes to an hour - and give the SDK a fresh token when it asks (see Expired or invalid tokens). Keep your server's clock in sync: the times are compared without a tolerance.
Mint the token only for the user your own session has authenticated, from an endpoint your app calls after sign-in.
Node.js, with jsonwebtoken:
const jwt = require('jsonwebtoken');
// The private key, loaded from your secrets store - never from the app.
const privateKey = process.env.JORYIO_SDK_AUTH_PRIVATE_KEY;
app.get('/joryio-token', requireSignedIn, (req, res) => {
const token = jwt.sign({}, privateKey, {
algorithm: 'RS256', // 'ES256' for an EC key
subject: req.user.id, // the same id your app passes to identify()
audience: process.env.JORYIO_APP_ID, // this app's ID - Settings → Apps
expiresIn: '15m',
});
res.json({ token });
});
Python, with PyJWT:
import os, time, jwt
private_key = os.environ["JORYIO_SDK_AUTH_PRIVATE_KEY"]
def joryio_token(user_id: str) -> str:
now = int(time.time())
return jwt.encode(
{"sub": user_id, "aud": os.environ["JORYIO_APP_ID"], "iat": now, "exp": now + 15 * 60},
private_key,
algorithm="RS256", # "ES256" for an EC key
)
Audience and issuer
aud binds a token to one app, so a token your server minted for one app is refused by another - even when both trust the same key pair. Put the app's ID in aud (one ID per token, or an array of the apps it is for).
- Apps created from 2026-11-27 are strict: a token whose
auddoes not name the app is refused asinvalid. - Apps created before are in compatibility mode: such a token is still accepted, and the SDK Authentication dialog shows a notice with when one last arrived. Add
audto your tokens, then click Require aud - or sendPUT /apps/:id/sdk-auth/claimswith{ "audienceCheck": "strict" }. - Expected issuer (optional): set it in the same dialog (or
{ "issuer": "https://auth.example.com" }). A token whoseissdiffers, or that has none, is then refused asinvalid- in compatibility mode too. Leave it empty to accept any issuer.
The SDKs send the token exactly as you give it, so these claims are only your server's to set.
Keys
Create a key pair with OpenSSL - RSA:
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out joryio-sdk-auth.key
openssl pkey -in joryio-sdk-auth.key -pubout -out joryio-sdk-auth.pub
or EC (P-256, for ES256):
openssl ecparam -name prime256v1 -genkey -noout -out joryio-sdk-auth.key
openssl ec -in joryio-sdk-auth.key -pubout -out joryio-sdk-auth.pub
Paste the contents of joryio-sdk-auth.pub into the dashboard. Keep joryio-sdk-auth.key in your secrets store and never ship it in an app or website.
An app holds one public key at a time, and saving a new one replaces the old one at once. To rotate: switch your server to the new private key and save the new public key in the dashboard together. Tokens signed with the old key are then refused as invalid, and the SDKs ask your app for a fresh one, so a rotation costs one refresh per signed-in user.
Pass the token to the SDK
Get a token from your server after sign-in, hand it to the SDK, and register a handler that fetches a new one when Joryio refuses the current one. Each SDK attaches the token as the X-Joryio-Auth header to the requests of the user it was minted for, and never to an anonymous visitor's.
| SDK | Turn on | Set or replace the token | When the token is refused |
|---|---|---|---|
| Web | enableSdkAuthentication: true, optionally sdkAuthenticationToken | setSdkAuthenticationToken(token) | setSdkAuthenticationErrorCallback(callback) |
| iOS | JoryioConfig(enableSdkAuthentication:sdkAuthenticationToken:), or just set a token | Joryio.shared.setSdkAuthenticationToken(_:) | Joryio.shared.setSdkAuthenticationErrorHandler(_:), clearSdkAuthenticationErrorHandler() |
| Android | JoryioConfig(enableSdkAuthentication = true, sdkAuthenticationToken = ...), or just set a token | Joryio.setSdkAuthenticationToken(token) | Joryio.setSdkAuthenticationErrorHandler(handler) |
| React Native | enableSdkAuthentication: true, optionally sdkAuthenticationToken | Joryio.setSdkAuthenticationToken(token) | Joryio.onSdkAuthenticationError(callback) (returns an unsubscribe function) |
| Unity | JoryioConfig.EnableSdkAuthentication, optionally SdkAuthenticationToken | JoryioSDK.SetSdkAuthenticationToken(token) | JoryioSDK.SetSdkAuthenticationErrorHandler(handler) |
On the web, setSdkAuthenticationToken is ignored unless enableSdkAuthentication is true. On iOS and Android, setting a token turns the header on even without the flag.
At sign-out, call reset() as usual. The outgoing user's token stays with the requests they had already queued, so a sign-out loses nothing, and the next user's requests never carry it. Set the next user's token once they sign in - before or after their identify().
Expired or invalid tokens
A refused token is answered 401 with this body:
{ "statusCode": 401, "error": "sdk_authentication_error", "reason": "expired" }
reason | Meaning | What to do |
|---|---|---|
missing | The request names a user but carries no token. | Set a token after sign-in. |
expired | The token's exp has passed. | Mint a fresh token. |
invalid | Bad signature, wrong key, an algorithm other than RS256/ES256, no exp, not yet valid (nbf), or no public key registered for the app, a missing or wrong aud (strict app), a wrong or missing iss (when an expected issuer is set). | Check the key pair and the claims. |
sub_mismatch | The token's sub is not the user the request names. | Mint the token for the id you pass to identify(). |
What the SDKs do:
- They ask your handler for a fresh token when a request of the signed-in user is refused, including before any token was set (
missing). With a new token they retry the request once at once; otherwise the request stays queued and is retried with the normal backoff, carrying whatever token is set by then. The handler is never called for a user who has since signed out. - A signed-out user's leftovers are dropped when they are refused - no token for that user will come again - so they never hold back the next user's requests.
- Withdrawals still arrive. An unsubscribe, the opt-out record and a push unregister are accepted with a correctly signed token for up to 30 days after it expired, and a push unregister needs no token at all. See Withdrawals are always delivered.
Testing
- Use a test app. Create a separate app for your staging build, turn SDK Authentication on there first, and check that events of a signed-in user still arrive in Analytics → Event Explorer.
- Force each failure once. Mint a token that expires in a minute and wait for your handler to receive
expired; sign with a different key to seeinvalid; set user A's token and identify user B to seesub_mismatch. - Check the claims before you blame the SDK: decode the token on your own machine and confirm
subis the exact id you pass toidentify()andexpis in the future. - Watch for
401from older builds after you turn it on: they are users of a version that never sets a token. - Anonymous traffic should not change. Visitors who never sign in keep sending events without a token.