Skip to navigation

Trading Widget Authentication

Use partner-token for new embedded trading SSO integrations.

View as Markdown

partner-token avoids putting short tokens in URLs and keeps apiSecret on the partner backend.

const widget = TradingWidget.create('#trading-widget', {
baseUrl: 'https://app.6mm.com',
auth: {
mode: 'partner-token',
tokenProvider: async ({ channelId, symbol, reason }) => {
const resp = await fetch('/api/trading/embed-token', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ channelId, symbol, reason }),
})
if (!resp.ok) {
throw new Error('Failed to request embed token')
}
return resp.json()
},
},
})

Backend flow

1. Partner frontend receives auth_request from the iframe.
2. SDK calls tokenProvider.
3. Partner frontend calls its own backend.
4. Partner backend validates the partner session.
5. Partner backend calls 6MM Agent API or Java SDK createEmbedToken.
6. SDK sends embedToken to the iframe through postMessage.
7. iframe exchanges embedToken for a 6MM access token.
8. iframe continues initialization and emits ready.

tokenProvider contract

FieldDirectionDescription
channelIdSDK -> Partner backendUnique widget session identifier. The backend should pass it to createEmbedToken.
symbolSDK -> Partner backendCurrent or initial trading symbol passed as integration context; it is not a token trading-pair permission restriction.
reasonSDK -> Partner backendWhy the SDK is requesting a token, such as initial load or refresh.
embedTokenPartner backend -> SDKShort-lived token created by the Agent SDK or Agent API.
expireAtPartner backend -> SDKToken expiration timestamp returned by 6MM.

Failure handling

ConditionRecommended handling
Partner session expiredReturn 401 from the partner endpoint and ask the user to sign in again.
Token creation failed temporarilyThrow an error in tokenProvider and allow the widget to surface an auth error.
channelId mismatchReject the request and recreate the widget instance.
User is not allowed to tradeReturn a partner-controlled error and do not create an embed token.

Compatibility mode: agent-sso

agent-sso keeps the older /agent-entry ticket flow. Prefer partner-token for new integrations.

const widget = TradingWidget.create('#trading-widget', {
baseUrl: 'https://app.6mm.com',
auth: {
mode: 'agent-sso',
entryUrlProvider: async ({ redirectPath }) => {
const resp = await fetch('/api/trading-entry', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ redirectPath }),
})
const data = await resp.json()
return data.webUrl
},
},
})

Seconds trading and environment rules

For seconds pages, use the same partner-token authentication with page and tradingMode configured on the Widget. There is no separate prediction token. Every tokenProvider call must obtain a fresh one-time token from your backend.

Return embedToken, expireAt in Unix seconds, and the original channelId as a top-level object. The Agent SDK token response does not contain channelId; your backend echoes the current Widget channel. If your endpoint wraps responses in data, unwrap it before returning from tokenProvider.

Full seconds integration · Funds environment guide