Trading Widget Autenticación

Utiliza partner-token para nuevas integraciones de trading SSO integraciones.

Ver como Markdown

partner-token evita poner tokens cortos en URLs y mantiene apiSecret en el backend del partner.

1const widget = TradingWidget.create('#trading-widget', {
2 baseUrl: 'https://app.6mm.com',
3 auth: {
4 mode: 'partner-token',
5 tokenProvider: async ({ channelId, symbol, reason }) => {
6 const resp = await fetch('/api/trading/embed-token', {
7 method: 'POST',
8 credentials: 'include',
9 headers: { 'Content-Type': 'application/json' },
10 body: JSON.stringify({ channelId, symbol, reason }),
11 })
12
13 if (!resp.ok) {
14 throw new Error('Failed to request embed token')
15 }
16
17 return resp.json()
18 },
19 },
20})

Flujo de backend

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 contrato

CampoDirecciónDescripción
channelIdSDK -> Backend de sociosIdentificador único de sesión de widget. El backend debería pasarlo a createEmbedToken.
SímboloSDK -> Backend de sociosSímbolo de trading solicitado actualmente. Úsalo para el alcance del token cuando sea necesario.
RazónSDK -> Backend de sociosPor qué el SDK solicita un token, como la carga inicial o la actualización.
embedTokenBackend de socios -> SDKToken de corta duración creado por el Agent SDK o Agente API.
expireAtBackend de socios -> SDKLa marca de tiempo de caducidad del token devuelve por 6MM.

Manejo de fallos

EstadoManipulación recomendada
Sesión de socios expiradaDevuelve el 401 desde el endpoint del socio y pide al usuario que inicie sesión de nuevo.
La creación de tokens falló temporalmenteLanza un error en tokenProvider y permite que el widget muestre un error de autenticación.
channelId desajusteRechaza la petición y recrea la instancia del widget.
El usuario no puede operarDevuelve un error controlado por el socio y no crees un token embed.

Modo de compatibilidad: agent-sso

agent-sso mantiene el flujo antiguo de tickets /agent-entry. Prefiero partner-token para nuevas integraciones.

1const widget = TradingWidget.create('#trading-widget', {
2 baseUrl: 'https://app.6mm.com',
3 auth: {
4 mode: 'agent-sso',
5 entryUrlProvider: async ({ redirectPath }) => {
6 const resp = await fetch('/api/trading-entry', {
7 method: 'POST',
8 credentials: 'include',
9 headers: { 'Content-Type': 'application/json' },
10 body: JSON.stringify({ redirectPath }),
11 })
12 const data = await resp.json()
13 return data.webUrl
14 },
15 },
16})