The flow#
- The user opens your app. SALOPHA creates a launch session and a one-time sign-in code.
- Your page calls
requestAuthCode()and posts{code, launchSessionId, nonce}to your server. - Your server calls
exchangeCode()(orPOST /v1/mini-apps/auth/token) with its client id and secret. - SALOPHA answers with
sub, the granted scopes, the profile fields the user agreed to share, and a user access token for 15 minutes. - Your server creates its own session. SALOPHA tokens never reach the page.
// Page
const { code, launchSessionId } = await app.requestAuthCode();
await fetch("/api/v1/auth/salopha", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code, launchSessionId, nonce: app.launchNonce }) });
// Server
const r = await platform.exchangeCode({ code, launchSessionId, nonce });
// r = { sub, scopes, profile?: { displayName, phone?, avatarUrl?, locale?, city? }, accessToken }
The pairwise sub#
sub(pw_…) identifies the user for your app only. Two apps see two different values for the same person, so apps cannot link users across services.- It is stable: the same user always has the same
subin your app. Use it as your user key. - Never key users by phone number or name; those depend on consent and can change.
Codes and tokens#
| Item | Lifetime | Notes |
|---|---|---|
| Sign-in code | 60 seconds, single use | Replaying a code revokes the launch session. |
| User access token | 15 minutes | Bound to the user; for me, addresses, transactions, businesses. Consent is re-checked on every call. |
| Server token | 15 minutes | From your client credentials (aud miniapp-server:<appId>); for notifications, users and stats. The server SDK caches it. Rotating the secret ends old ones. |
When your session expires, call requestAuthCode() again: after the first call it returns a fresh code without any UI, so re-authentication is silent.
Profile fields#
| Field | Needs | Notes |
|---|---|---|
displayName | profile.basic | |
avatarUrl | profile.basic | Only when the user shows their photo to everyone. |
locale, city | profile.basic | When set |
phone | profile.phone | Verified number. Automatic grants include it only when the user shows their number to everyone; otherwise ask with requestScope("profile.phone"). |
An app is never one of the user's contacts, so privacy settings that say «contacts only» always hide that field from apps.
Automatic sign-in#
Official apps and apps from trusted developers can list autoGrantScopes in the manifest, for example profile.basic, profile.phone and notifications.service. Users are then signed in without a consent sheet. They can still revoke each scope in Settings › Mini apps, and a revoked automatic grant stays revoked.
Other apps ask with requestScope(scope) right before they need something. See Scopes.
When consent is revoked#
When a user revokes your app's access, SALOPHA sends a signed webhook to <webhookUrl>/webhooks:
{ "eventType": "platform.consent.revoked.v1", "appId": "my_shop", "sub": "pw_7f3a9c", "pairwiseSub": "pw_7f3a9c", "scope": "profile.basic" }
End that user's sessions when scope is null or profile.basic. A simple way is a session version per user: bump it in the webhook and check it in your session guard. Treat the event as final and delete cached personal data you no longer may keep.
api.post("/api/v1/platform/webhooks", express.raw({ type: "*/*" }), async (req, res) => {
const r = await platform.handlePlatformCall({ method: "POST", path: req.originalUrl, headers: req.headers, rawBody: req.body }, {
webhook: async (event) => {
if (event.eventType === "platform.consent.revoked.v1" && (!event.scope || event.scope === "profile.basic")) await users.bumpSessionVersion(event.sub);
},
});
res.status(r.status).json(r.body);
});
Merchant staff#
People who manage a store or agency in your app sign in the same way. Decide their access on your server, never from the page: the owner sub stored on the record, staff of a SALOPHA business bound to your app (platform.businesses(accessToken) at sign-in), or a one-time claim code you issue. See Merchant bindings.