Overview
The Gameball Customer Session Token is a signed and encrypted JWE token that binds a single logged-in customer to Gameball.- Generated on your backend only, using your SecretKey.
- Contains the customer’s unique identifier and optional metadata.
- Short-lived: expires with the customer’s session.
- Used together with
playerUniqueIdon the client side to securely load Gameball widgets and SDKs.
- Token format and claims.
- Reference generation code in multiple languages.
- When to generate / refresh / drop the token in web and mobile flows.
1. Token Format & Claims
The session token is a nested JWT:- Inner JWT (JWS): signed with HS256 using your SecretKey.
- Outer JWE: encrypts that JWT using A256KW + A256CBC-HS512, again with your SecretKey.
1.1 Claims
Recommended claims payload:-
customerId(required):
Your unique identifier for the customer (must matchplayerUniqueIdyou send to the SDK). -
customerEmail(optional) -
customerMobile(optional) -
exp(required):
Expiry timestamp (Unix seconds). Should match or be shorter than the session duration in your own auth system.
2. Cryptography Details
Signing:
- Algorithm: HS256 (HMAC SHA-256)
- Key: your Gameball SecretKey
Encryption:
- Key management algorithm: A256KW
- Content encryption algorithm: A256CBC-HS512
- Key: same SecretKey (symmetric key)
Key length:
3. Reference Implementations
These snippets show how to generate the token in different languages. You plug them into your own auth / session logic where appropriate.3.1 C# (.NET)
3.2 Node.js / TypeScript with jose
3.3 Python with jwcrypto
4. Web Flows – When to Generate the Token
A key part of a secure integration is deciding when to generate, refresh, or drop the token. The flows below outline recommended patterns you can follow.4.1 Login
Scenario: Customer logs into your web app. Flow:- User submits login credentials.
- Backend validates credentials.
- Backend:
- Creates/refreshes your own app session (cookie/JWT/etc.).
- Calls
generateGameballSessionTokenwith:customerId= the same ID asplayerUniqueId.email/mobileif you want them in the token.expiresAtaligned with your own session.
- Backend returns the Gameball session token to frontend, e.g.:
- Embedded in login response JSON, or
- Via a dedicated “get Gameball token” endpoint that the frontend calls immediately after login.
- Frontend stores the token in memory (or short-lived storage, not long-term persistence) and initializes the widget with:
APIKeyplayerUniqueId= your customer IDsessionToken= the JWE you generated.
4.2 Session extension / refresh
Scenario: You extend the user session (remember-me, silent refresh, etc.). Flow:- Frontend calls your backend to refresh the app session.
- If you extend the app session, the backend:
- Generates a new Gameball session token with a new
exp.
- Generates a new Gameball session token with a new
- Frontend replaces the old token and:
- Re-initializes the widget if needed, or
- Uses SDK APIs to update the token if supported.
4.3 Token expiry while the user is active
Scenario: The user stays on a page long enough for the Gameball token to expire. You have two options: Proactive:- Frontend tracks the token’s
exp(provided by your backend along with the token). - A bit before expiry (e.g. 5 minutes), frontend calls backend for a new token.
- If Gameball responds with an “expired token” error:
- Frontend calls your backend to get a new token.
- Re-initializes the widget.
4.4 Logout
Scenario: User logs out of your app. Flow:- Frontend clears:
- Your own session (cookies/local storage).
- Any in-memory Gameball session token.
5. Mobile Flows – When to Generate the Token
Mobile is almost the same idea, just with different timing.5.1 Mobile login
- User logs into your mobile app.
- App calls backend with credentials.
- Backend:
- Issues your app’s auth token (JWT, opaque token, etc.).
- Generates Gameball session token for that customer.
- Backend returns both to the app.
- Mobile app:
- Stores your auth token as usual (Keychain/Secure Storage).
- Stores Gameball session token in memory or secure storage (but treat it as short-lived).
- Initializes the Gameball SDK with:
APIKeyplayerUniqueIdsessionToken.
5.2 App resume / foreground
Scenario: User returns to the app after some time. Flow:- When the app resumes, check:
- Your auth token is still valid.
- The Gameball session token has not expired (you can have the backend expose its
expor simply call backend to refresh).
- If the Gameball token is expired or close to expiring:
- Call backend to issue a new token for the current customer.
- Update the SDK with the new token.
5.3 Token rotation on account switch
Scenario: User logs out and logs in as another account in the same app. Flow:- When user logs out:
- Delete both your app’s auth token and any stored Gameball session token.
- When a new user logs in:
- Repeat login flow and generate a new Gameball session token for that new
customerId. - Reinitialize Gameball SDK with the new
playerUniqueId+ newsessionToken.
- Repeat login flow and generate a new Gameball session token for that new
6. Using the Token in SDK Configuration
The SDK/Widget side always needs:playerUniqueId— your stable customer identifier.- The session token you generated.
7. Error Handling Patterns
You should assume that tokens might be:- Expired.
- Missing.
- Invalid (bad key, tampering, etc.).
Recommended behavior:
Expired token:- Treat as a signal to refresh.
- Frontend/mobile calls backend to get a new session token (if the user is still authenticated in your system).
- Log the event in your backend or monitoring system.
- Ask the user to re-authenticate if needed.
- Don’t initialize the widget.
- Show a generic “loyalty is temporarily unavailable” message instead of partially loading.
8. Quick Checklist for Session Tokens
- Token is generated only on the backend.
- Token uses
customerId, matchesplayerUniqueId. - Token includes an
expthat matches your app session. - Token signed (HS256) and encrypted (A256KW + A256CBC-HS512) with your SecretKey.
- No SecretKey is ever exposed in JS/mobile.
- Web and mobile flows generate/refresh/drop tokens at:
- Login
- Session extension
- Long active sessions (expiry handling)
- Logout
- Account switch
Related Documentation
Secure Integrations v4.1
Learn about v4.1 security requirements and migration
Authentication Guide
General authentication instructions for Gameball APIs