User Authorization
User authorization is the process of obtaining the user’s consent to access their information. It is based on the industry-standard OAuth 2.0 authorization mechanism: a Mini Program must get permission from the user before obtaining and using any user information.Terminology
Access Process
Taking user information as an example:- The Mini Program calls
my.getAuthCodeto get anauthCodefrom the Rebell app. - The Mini Program sends the
authCodeto the merchant server. - The merchant server calls applyToken and receives the access token.
- The merchant server stores the access token and returns the authorization result to the Mini Program.
- With the access token, the merchant server can call other authorized OpenAPIs, such as inquiryUserInfo, within the token’s scope and validity period.
scopes when calling my.getAuthCode.
Obtain the authCode
Obtain the accessToken
The merchant server exchanges theauthCode with applyToken:
accessToken, accessTokenExpiryTime, refreshToken, refreshTokenExpiryTime and customerId. When the access token expires, call applyToken with grantType = REFRESH_TOKEN and the refreshToken; after refreshTokenExpiryTime, the user must authorize again. To revoke an authorization, call cancelToken.
Every authorization returns a different
authCode. An authCode can be used only once and expires automatically (at most within one day; codes from agreement signing expire after 10 minutes), so exchange it immediately.Authorization Modes
- Silent mode
- User consent mode
auth_base returns the authCode without showing a consent dialog. Your server exchanges it for an access token and the user identifier.Silent authorization is only available for first-party Mini Programs. All third-party Mini Programs require explicit user authorization.Getting User Information
Authorization Rules
- Do not request authorization on the Mini Program’s first screen. Users must be able to understand the Mini Program and its business before being asked for authorization. Integrate the request into the business flow.
- Request only information related to your business, and only what you need. Do not request the user ID or real name through
my.getOpenUserInfo; it returns only basic information. - Basic user information and the user’s mobile phone number are obtained by two different JSAPIs and cannot be requested in the same modal.
- Handle refusal: if the user denies authorization, offer an alternative (for example, entering the information manually), and show the authorization request again when the business needs it.
API List
FAQ
Why use my.getAuthCode?
Why use my.getAuthCode?
All reading and writing of user information on the Mini Program Platform requires the user’s consent. User authorization, based on OAuth 2.0, is the mechanism through which developers obtain user information.
Can the userId be obtained through my.getAuthCode?
Can the userId be obtained through my.getAuthCode?
No. The Mini Program only receives an
authCode. The user identity is obtained server-side: applyToken returns the customerId, and inquiryUserInfo returns userInfo.userId within the granted scopes.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:Authorization Code (authCode) Concept
AnauthCode is a short-lived, single-use authorization artifact issued by Rebell after user consent.
Properties
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 (applyToken, 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:
result.resultStatusisScustomerIdandaccessTokenare presentaccessTokenExpiryTimeis in the future
4
Create Session
Persist a backend session context
Backend Exchange Implementation
What the Backend Should Store
Store a backend session record like: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
Backend Endpoint Reference
Bootstrap Endpoint
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
Next Steps
With backend authentication implemented, you can now integrate payments:Payments in Mini Apps
Integrate payment functionality within your Mini App
Payment Integration
Review the complete payment integration guide