Trust Model Overview
Actors
User
Rebell customer using the SuperApp
Mini App
Runs in Rebell SuperApp (untrusted)
Merchant Backend
Trusted system of record
Rebell OpenAPI
Trusted authorization provider
Key Rule
Why Mini Apps Cannot Be Trusted
Mini Apps must not be trusted because:| Risk | Description |
|---|---|
| Environment | They run on end-user devices (modifiable environment) |
| Replay | Requests can be replayed or forged |
| Tampering | User identity fields can be tampered with |
| Secrets | Secrets cannot be safely stored client-side |
Authorization Code (authCode) Concept
AnauthCode is a short-lived, single-use authorization artifact issued by Rebell after user consent.
Properties
| Property | Description |
|---|---|
| Short-lived | Expires quickly (typically minutes) |
| Single-use | Cannot be reused after exchange |
| Bound | Tied to user session, Mini App, and requested scopes |
What authCode Is NOT
- Not a long-lived token
- Not an API key
- Not client-verifiable
The authCode expires quickly and cannot be stored for later use
What authCode Is Used For
To let the Merchant Backend exchange it for a trusted user context (and optionally a platform access token / user identifiers, depending on scope).End-to-End Authorization Flow
Sequence Diagram
Flow Steps
1
Mini App Requests Authorization
Mini App calls JSAPI to request user authorization with specific scopes
2
User Grants Consent
Platform shows consent prompt; user approves or denies
3
Mini App Receives authCode
Platform returns short-lived, single-use authCode
4
Mini App Sends to Backend
Mini App sends authCode to merchant backend bootstrap endpoint
5
Backend Exchanges authCode
Backend exchanges authCode with Rebell OpenAPI (server-to-server, signed)
6
Backend Establishes Session
Backend creates internal session and returns session identifier to Mini App
Result
The backend now has a verified user context and can securely act on behalf of that user, within granted scopes.Backend Token Exchange & Validation
Exchange Step (Mandatory)
When the backend receivesauthCode, it must:
1
Validate Format
Validate basic format (non-empty, expected length)
2
Exchange with Rebell
Exchange it with Rebell OpenAPI (server-to-server, signed request)
3
Validate Response
Validate the response:
- Mini App identifier (if provided)
- Granted scopes match what is required
- Token/user context is not expired
4
Create Session
Persist a backend session context
Backend Exchange Implementation
What the Backend Should Store
Store a backend session record like:| Field | Description |
|---|---|
sessionId | Your internal session identifier |
rebellUserId | Stable user identifier from OpenAPI |
scopesGranted | List of granted authorization scopes |
issuedAt | When the session was created |
expiresAt | When the session expires |
miniAppId | (Optional) Mini App identifier |
deviceId | (Optional) Device identifier |
Session Establishment Patterns
Choose one approach:- Session Token
Using the Authenticated Context
Once a session is established, every request from Mini App to backend should rely on the backend session to identify the user — not on client-provided identifiers.Authenticated Request Flow
Backend Implementation
Payments Built on Top of Backend Authorization
Payments inside Mini Apps should follow the same trust pattern:1
Mini App Triggers
The Mini App triggers a payment action
2
Backend Creates Payment
The backend creates the payment (using session’s rebellUserId)
3
Webhook Confirms
The backend receives webhook confirmation
4
UI Updates
The Mini App UI updates based on backend-confirmed state
Payment Flow Sequence
Security Rules & Anti-Patterns
Hard Rules
Anti-Patterns to Avoid
| Anti-Pattern | Risk | Correct Approach |
|---|---|---|
Using authCode as long-lived token | Replay attacks | Exchange immediately, use session |
Passing rebellUserId from client | Identity spoofing | Get from session context only |
| Creating payments client-side | Unauthorized payments | Create via backend |
| Trusting client payment callback | False success | Wait for webhook |
Backend Endpoint Reference
Bootstrap Endpoint
| Status | Description |
|---|---|
200 OK | Session established, returns cookie/token |
400 Bad Request | Invalid authCode format |
401 Unauthorized | authCode exchange failed |
403 Forbidden | Required scope not granted |
Backend Must Enforce
AuthCode One-Time Use
AuthCode One-Time Use
Never accept the same authCode twice. Mark as used after successful exchange.
Scope Checking
Scope Checking
Don’t allow user-info access if scope not granted. Validate scopes match requirements.
Session Expiry
Session Expiry
If session expired, require re-authorization. Don’t extend sessions indefinitely.
Payment Idempotency
Payment Idempotency
Same
paymentRequestId rules as Payment Integration chapter. Prevent duplicate payments.Testing Authentication Flow
Test Checklist
Happy Path
Happy Path
- User grants authorization
- authCode exchanged successfully
- Session created with correct user context
- Subsequent requests use session correctly
Error Cases
Error Cases
- User denies authorization
- Invalid authCode format
- Expired authCode
- authCode reuse attempt
- Session expiration
Security
Security
- Client-provided userId is ignored
- authCode cannot be replayed
- Session is properly invalidated
- Scopes are enforced