@bigso/auth-sdk 0.4.7 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -135
- package/dist/browser/index.cjs +11 -23
- package/dist/browser/index.d.cts +3 -20
- package/dist/browser/index.d.ts +3 -20
- package/dist/browser/index.js +12 -24
- package/dist/chunk-5ECHA2VH.js +32 -0
- package/dist/express/index.cjs +61 -122
- package/dist/express/index.d.cts +16 -13
- package/dist/express/index.d.ts +16 -13
- package/dist/express/index.js +61 -122
- package/dist/node/index.cjs +69 -98
- package/dist/node/index.d.cts +6 -30
- package/dist/node/index.d.ts +6 -30
- package/dist/node/index.js +53 -99
- package/dist/types-BQzACpj3.d.cts +73 -0
- package/dist/types-BQzACpj3.d.ts +73 -0
- package/package.json +2 -2
- package/dist/chunk-LDDK6SJD.js +0 -13
- package/dist/types-CoXgtTry.d.cts +0 -51
- package/dist/types-CoXgtTry.d.ts +0 -51
package/README.md
CHANGED
|
@@ -1,188 +1,233 @@
|
|
|
1
1
|
# @bigso/auth-sdk
|
|
2
2
|
|
|
3
|
-
SDK oficial de autenticación para Bigso SSO
|
|
3
|
+
SDK oficial de autenticación para Bigso SSO v2. Flujo basado en JWT Bearer tokens con PKCE, comunicación por iframe seguro, y validación JWKS.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Características
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Flujo PKCE completo** — codeVerifier se expone al consuming app para enviar al backend
|
|
8
|
+
- **JWT Bearer tokens** — accessToken + refreshToken con revoke y rotación automática
|
|
9
|
+
- **Comunicación por iframe** con postMessage v2.3 y validación de origen
|
|
10
|
+
- **JWS verification** en frontend con JWKS remoto
|
|
11
|
+
- **3 entry points**: Browser, Node.js, Express middleware
|
|
12
|
+
- **Server-to-server** login, exchange, refresh, logout via API v2
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
## Instalación
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
```bash
|
|
17
|
+
npm install @bigso/auth-sdk
|
|
18
|
+
```
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
## Arquitectura v2
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
```
|
|
23
|
+
┌──────────────┐ postMessage (v2.3) ┌──────────────┐
|
|
24
|
+
│ App Web │◄──────────────────────────►│ SSO Portal │
|
|
25
|
+
│ (consuming) │ sso-init / sso-success │ (iframe) │
|
|
26
|
+
└──────┬───────┘ └──────┬───────┘
|
|
27
|
+
│ │
|
|
28
|
+
│ 1. auth.login() → codeVerifier │
|
|
29
|
+
│ 2. POST /exchange-v2-pkce │
|
|
30
|
+
│ { code, codeVerifier } │
|
|
31
|
+
▼ ▼
|
|
32
|
+
┌──────────────┐ POST /api/v2/auth/exchange ┌──────────────┐
|
|
33
|
+
│ App Backend │──────────────────────────────────►│ SSO Core │
|
|
34
|
+
│ (Express) │◄─────────────────────────────────│ (API v2) │
|
|
35
|
+
│ │ { accessToken, refreshToken } │ │
|
|
36
|
+
└──────────────┘ └──────────────┘
|
|
37
|
+
```
|
|
18
38
|
|
|
19
|
-
|
|
39
|
+
## Uso
|
|
20
40
|
|
|
21
|
-
|
|
41
|
+
### Browser (iframe login)
|
|
22
42
|
|
|
23
|
-
|
|
43
|
+
```typescript
|
|
44
|
+
import { BigsoAuth } from '@bigso/auth-sdk';
|
|
24
45
|
|
|
25
|
-
|
|
46
|
+
const auth = new BigsoAuth({
|
|
47
|
+
clientId: 'crm',
|
|
48
|
+
ssoOrigin: 'https://sso.bigso.co',
|
|
49
|
+
jwksUrl: 'https://sso.bigso.co/.well-known/jwks.json',
|
|
50
|
+
});
|
|
26
51
|
|
|
27
|
-
|
|
52
|
+
auth.on('success', async (result) => {
|
|
53
|
+
// result.code → authorization code
|
|
54
|
+
// result.codeVerifier → PKCE verifier (send to your backend!)
|
|
55
|
+
// result.signed_payload → JWS signed payload
|
|
56
|
+
// result.state → matches your original state
|
|
57
|
+
// result.nonce → matches your original nonce
|
|
58
|
+
|
|
59
|
+
// Send to your backend:
|
|
60
|
+
const response = await fetch('/api/auth/exchange-v2-pkce', {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
payload: result.signed_payload,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
});
|
|
28
68
|
|
|
29
|
-
|
|
30
|
-
npm install @bigso/auth-sdk
|
|
31
|
-
# o
|
|
32
|
-
yarn add @bigso/auth-sdk
|
|
33
|
-
# o
|
|
34
|
-
pnpm add @bigso/auth-sdk
|
|
69
|
+
auth.login();
|
|
35
70
|
```
|
|
36
71
|
|
|
37
|
-
|
|
72
|
+
### Express backend
|
|
38
73
|
|
|
39
74
|
```typescript
|
|
40
|
-
import {
|
|
75
|
+
import { BigsoSsoClient } from '@bigso/auth-sdk/node';
|
|
76
|
+
import { createSsoAuthRouter, ssoAuthMiddleware } from '@bigso/auth-sdk/express';
|
|
41
77
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
timeout: 5000, // opcional, por defecto 5000ms
|
|
47
|
-
debug: true, // opcional, logs de depuración
|
|
48
|
-
redirectUri: 'https://miapp.com/callback', // opcional
|
|
49
|
-
tenantHint: 'mi-tenant' // opcional
|
|
78
|
+
const ssoClient = new BigsoSsoClient({
|
|
79
|
+
ssoBackendUrl: 'https://sso.bigso.co',
|
|
80
|
+
ssoJwksUrl: 'https://sso.bigso.co/.well-known/jwks.json',
|
|
81
|
+
appId: 'crm',
|
|
50
82
|
});
|
|
51
83
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
auth.on('error', (error) => console.error('❌ Error:', error));
|
|
59
|
-
auth.on('fallback', () => console.log('⚠️ Fallback por redirección activado'));
|
|
84
|
+
// Auth routes: /exchange, /exchange-v2, /session, /refresh, /logout
|
|
85
|
+
app.use('/api/auth', createSsoAuthRouter({
|
|
86
|
+
ssoClient,
|
|
87
|
+
frontendUrl: 'https://myapp.com',
|
|
88
|
+
}));
|
|
60
89
|
|
|
61
|
-
|
|
90
|
+
// Protected routes: validates Bearer JWT token
|
|
91
|
+
app.get('/api/protected', ssoAuthMiddleware({ ssoClient }), (req, res) => {
|
|
92
|
+
res.json({ user: req.user, tenant: req.tenant });
|
|
93
|
+
});
|
|
62
94
|
```
|
|
63
95
|
|
|
64
|
-
|
|
96
|
+
### Node.js (server-to-server)
|
|
65
97
|
|
|
66
|
-
|
|
67
|
-
|
|
98
|
+
```typescript
|
|
99
|
+
import { BigsoSsoClient } from '@bigso/auth-sdk/node';
|
|
68
100
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
| `jwksUrl` | `string` | ✅ | — | URL del JWKS para verificar firmas (ej. `/.well-known/jwks.json`). |
|
|
75
|
-
| `timeout` | `number` | ❌ | `5000` | Tiempo máximo de espera tras `sso-ready` (milisegundos). |
|
|
76
|
-
| `debug` | `boolean` | ❌ | `false` | Activa logs de depuración en consola. |
|
|
77
|
-
| `redirectUri` | `string` | ❌ | `''` | URI de redirección registrada (se valida exactamente en el SSO). |
|
|
78
|
-
| `tenantHint` | `string` | ❌ | `''` | Sugerencia de tenant para flujos multi-tenant. |
|
|
101
|
+
const client = new BigsoSsoClient({
|
|
102
|
+
ssoBackendUrl: 'https://sso.bigso.co',
|
|
103
|
+
ssoJwksUrl: 'https://sso.bigso.co/.well-known/jwks.json',
|
|
104
|
+
appId: 'crm',
|
|
105
|
+
});
|
|
79
106
|
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
// Exchange authorization code with PKCE
|
|
108
|
+
const session = await client.exchangeCode('ac_abc123...', 'dBjftJeZ4CVP...');
|
|
82
109
|
|
|
83
|
-
|
|
110
|
+
// Validate an access token locally (no network call)
|
|
111
|
+
const payload = await client.validateAccessToken('eyJhbG...');
|
|
84
112
|
|
|
85
|
-
|
|
113
|
+
// Refresh tokens (uses httpOnly cookie)
|
|
114
|
+
const refreshed = await client.refreshTokens();
|
|
86
115
|
|
|
87
|
-
|
|
88
|
-
|
|
116
|
+
// Logout
|
|
117
|
+
await client.logout('eyJhbG...', true); // revokeAll = true
|
|
118
|
+
```
|
|
89
119
|
|
|
90
|
-
|
|
91
|
-
Registra un manejador para los eventos del SDK.
|
|
120
|
+
## API Reference
|
|
92
121
|
|
|
93
|
-
|
|
94
|
-
| Evento | Descripción | Parámetros |
|
|
95
|
-
| :--- | :--- | :--- |
|
|
96
|
-
| `ready` | Se emite cuando el iframe está listo y se ha enviado `sso-init`. | — |
|
|
97
|
-
| `success` | Se emite tras verificar exitosamente la firma JWS y validar `state`/`nonce` en el frontend. | `payload: any` (payload del JWS) |
|
|
98
|
-
| `error` | Se emite cuando ocurre un error (incluyendo `version_mismatch` antes del fallback automático). | `error: Error | SsoErrorPayload` |
|
|
99
|
-
| `fallback` | Se emite justo antes de redirigir a la URL de fallback (por timeout o `version_mismatch`). | — |
|
|
100
|
-
| `debug` | Se emite cuando `debug: true` para logs internos. | `args: any[]` |
|
|
122
|
+
### Browser: `BigsoAuth`
|
|
101
123
|
|
|
102
|
-
|
|
124
|
+
#### Constructor
|
|
103
125
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
| Param | Type | Required | Default | Description |
|
|
127
|
+
|---|---|---|---|---|
|
|
128
|
+
| `clientId` | `string` | Yes | — | App ID registered in SSO |
|
|
129
|
+
| `ssoOrigin` | `string` | Yes | — | SSO origin (e.g. `https://sso.bigso.co`) |
|
|
130
|
+
| `jwksUrl` | `string` | Yes | — | JWKS URL for JWS verification |
|
|
131
|
+
| `timeout` | `number` | No | `5000` | Timeout after `sso-ready` (ms) |
|
|
132
|
+
| `debug` | `boolean` | No | `false` | Debug logging |
|
|
133
|
+
| `redirectUri` | `string` | No | `''` | Redirect URI |
|
|
134
|
+
| `tenantHint` | `string` | No | `''` | Tenant hint for multi-tenant |
|
|
113
135
|
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
const auth = new BigsoAuth({
|
|
117
|
-
clientId: 'abc123',
|
|
118
|
-
ssoOrigin: 'https://sso.bigso.co',
|
|
119
|
-
jwksUrl: 'https://sso.bigso.co/.well-known/jwks.json',
|
|
120
|
-
redirectUri: 'https://admin.miapp.com/callback',
|
|
121
|
-
tenantHint: 'enterprise'
|
|
122
|
-
});
|
|
123
|
-
```
|
|
136
|
+
#### `auth.login()`
|
|
124
137
|
|
|
125
|
-
|
|
126
|
-
Puedes escuchar el evento `fallback` para ejecutar tu propia lógica antes de la redirección automática:
|
|
138
|
+
Returns `Promise<BigsoAuthResult>`:
|
|
127
139
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
| Field | Type | Description |
|
|
141
|
+
|---|---|---|
|
|
142
|
+
| `code` | `string` | Authorization code from SSO |
|
|
143
|
+
| `codeVerifier` | `string` | PKCE code verifier — send to backend |
|
|
144
|
+
| `state` | `string` | Matches your original state |
|
|
145
|
+
| `nonce` | `string` | Matches your original nonce |
|
|
146
|
+
| `signed_payload` | `string` | JWS signed payload |
|
|
147
|
+
| `tenant` | `SsoTenant` | Tenant data (if included) |
|
|
136
148
|
|
|
137
|
-
|
|
149
|
+
### Node: `BigsoSsoClient`
|
|
138
150
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
151
|
+
| Method | Description |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `exchangeCode(code, codeVerifier)` | Exchange auth code for tokens via `/api/v2/auth/exchange` |
|
|
154
|
+
| `refreshTokens()` | Refresh tokens via `/api/v2/auth/refresh` (uses cookie) |
|
|
155
|
+
| `logout(accessToken, revokeAll?)` | Revoke session via `/api/v2/auth/logout` |
|
|
156
|
+
| `validateAccessToken(token)` | Verify JWT locally against JWKS |
|
|
157
|
+
| `verifySignedPayload(token, audience)` | Verify JWS signed payload |
|
|
145
158
|
|
|
146
|
-
|
|
159
|
+
### Express: `createSsoAuthRouter(options)`
|
|
147
160
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
| Route | Method | Description |
|
|
162
|
+
|---|---|---|
|
|
163
|
+
| `/exchange` | POST | `{code, codeVerifier}` → v2 exchange |
|
|
164
|
+
| `/exchange-v2` | POST | `{payload}` → verify JWS, then v2 exchange |
|
|
165
|
+
| `/session` | GET | Validate Bearer token, return user data |
|
|
166
|
+
| `/refresh` | POST | Proxy to `/api/v2/auth/refresh` |
|
|
167
|
+
| `/logout` | POST | Bearer token → `/api/v2/auth/logout` |
|
|
168
|
+
|
|
169
|
+
### Express: `ssoAuthMiddleware({ ssoClient })`
|
|
170
|
+
|
|
171
|
+
Reads `Authorization: Bearer <token>`, validates JWT against JWKS, populates `req.user`, `req.tenant`, `req.tokenPayload`.
|
|
172
|
+
|
|
173
|
+
## Flujo PKCE completo
|
|
152
174
|
|
|
153
|
-
### Pruebas
|
|
154
|
-
```bash
|
|
155
|
-
npm test # ejecuta vitest
|
|
156
175
|
```
|
|
176
|
+
1. Browser SDK genera: state, nonce, codeVerifier
|
|
177
|
+
2. Browser SDK computa: codeChallenge = SHA256(codeVerifier)
|
|
178
|
+
3. Browser SDK → iframe: {codeChallenge, state, nonce}
|
|
179
|
+
4. Iframe → SSO Core: POST /api/v2/auth/authorize (con codeChallenge)
|
|
180
|
+
5. Iframe → Browser SDK: {code, state} (firmado como JWS)
|
|
181
|
+
6. Browser SDK verifica JWS, valida state y nonce
|
|
182
|
+
7. Browser SDK retorna {code, codeVerifier} al consuming app
|
|
183
|
+
8. Consuming app → su backend: POST /exchange-v2-pkce {payload, codeVerifier}
|
|
184
|
+
9. Backend verifica JWS, extrae code, llama /api/v2/auth/exchange {code, appId, codeVerifier}
|
|
185
|
+
10. SSO Core verifica: SHA256(codeVerifier) === codeChallenge → emite tokens
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Seguridad
|
|
189
|
+
|
|
190
|
+
- **PKCE**: codeVerifier nunca sale del browser hasta el paso 7, pero jamás se envía al SSO iframe
|
|
191
|
+
- **JWS**: El signed_payload se verifica contra JWKS en frontend y backend
|
|
192
|
+
- **state + nonce**: Validados en ambos lados para prevenir CSRF y replay
|
|
193
|
+
- **JWT Bearer**: Access tokens validados localmente contra JWKS, revocables en Redis/PG
|
|
194
|
+
- **httpOnly cookies**: Refresh tokens via cookie, nunca accesibles via JS
|
|
195
|
+
|
|
196
|
+
## Desarrollo
|
|
157
197
|
|
|
158
|
-
### Linting
|
|
159
198
|
```bash
|
|
160
|
-
npm run
|
|
199
|
+
npm run build # ESM + CJS + types → dist/
|
|
200
|
+
npm run dev # watch mode
|
|
201
|
+
npm run lint # eslint
|
|
202
|
+
npm test # vitest
|
|
161
203
|
```
|
|
162
204
|
|
|
163
|
-
##
|
|
205
|
+
## Changelog
|
|
164
206
|
|
|
165
|
-
### v0.
|
|
166
|
-
Protocolo actualizado a SSO v2.3
|
|
167
|
-
- Mensaje `sso-init` con `v: '2.3'`.
|
|
168
|
-
- Timeout reactivo (se inicia tras `sso-ready`).
|
|
169
|
-
- Validación de `requestId` en respuestas.
|
|
170
|
-
- Soporte para `redirect_uri`, `tenant_hint`, `timeout_ms`.
|
|
171
|
-
- Manejo de error `version_mismatch` con fallback automático.
|
|
172
|
-
- Validación de `nonce` en el frontend tras verificar JWS.
|
|
207
|
+
### v0.5.0 (2026-04-07) — Full v2
|
|
173
208
|
|
|
174
|
-
**
|
|
175
|
-
-
|
|
176
|
-
-
|
|
177
|
-
-
|
|
209
|
+
**Breaking changes:**
|
|
210
|
+
- All v1 API endpoints removed (`/api/v1/auth/token`, `/api/v1/auth/verify-session`, etc.)
|
|
211
|
+
- `SsoSessionData`, `SsoRefreshData`, `SsoExchangeResponse` types removed
|
|
212
|
+
- `ssoAuthMiddleware` now validates Bearer JWT (no cookies)
|
|
213
|
+
- Express routes use v2 endpoints exclusively
|
|
214
|
+
- `BigsoSsoClient` methods renamed/changed
|
|
178
215
|
|
|
179
|
-
**
|
|
216
|
+
**New features:**
|
|
217
|
+
- `BigsoAuthResult.codeVerifier` — PKCE verifier exposed for backend exchange
|
|
218
|
+
- `BigsoSsoClient.exchangeCode(code, codeVerifier)` — PKCE exchange via `/api/v2/auth/exchange`
|
|
219
|
+
- `BigsoSsoClient.refreshTokens()` — via `/api/v2/auth/refresh`
|
|
220
|
+
- `BigsoSsoClient.logout(accessToken)` — via `/api/v2/auth/logout`
|
|
221
|
+
- `BigsoSsoClient.validateAccessToken(token)` — Local JWT verification against JWKS
|
|
222
|
+
- Express `/exchange-v2-pkce` route with full PKCE support
|
|
223
|
+
- Express `/refresh` and `/logout` routes for v2 API
|
|
224
|
+
- `ssoAuthMiddleware` validates Bearer JWT tokens locally
|
|
180
225
|
|
|
181
|
-
### v0.
|
|
182
|
-
-
|
|
226
|
+
### v0.4.0 (2026-03-23)
|
|
227
|
+
- SSO v2.3 protocol support (iframe postMessage)
|
|
228
|
+
- PKCE, JWS verification, nonce validation
|
|
229
|
+
- Timeout reactive (starts after `sso-ready`)
|
|
183
230
|
|
|
184
|
-
##
|
|
185
|
-
MIT © Bigso
|
|
231
|
+
## Licencia
|
|
186
232
|
|
|
187
|
-
|
|
188
|
-
Por favor, abre un issue o pull request en el repositorio oficial.
|
|
233
|
+
MIT © Bigso
|
package/dist/browser/index.cjs
CHANGED
|
@@ -80,7 +80,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
80
80
|
this.loginInProgress = false;
|
|
81
81
|
this.options = {
|
|
82
82
|
timeout: 5e3,
|
|
83
|
-
// por defecto 5s (estándar v2.3)
|
|
84
83
|
debug: false,
|
|
85
84
|
redirectUri: "",
|
|
86
85
|
tenantHint: "",
|
|
@@ -88,10 +87,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
88
87
|
...options
|
|
89
88
|
};
|
|
90
89
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Inicia el flujo de autenticación.
|
|
93
|
-
* @returns Promise que resuelve con el payload decodificado del JWS (solo para información; el backend debe validar)
|
|
94
|
-
*/
|
|
95
90
|
async login() {
|
|
96
91
|
if (this.loginInProgress) {
|
|
97
92
|
this.debug("login() ya en curso, ignorando llamada duplicada");
|
|
@@ -149,11 +144,9 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
149
144
|
...this.options.redirectUri && { redirect_uri: this.options.redirectUri },
|
|
150
145
|
...this.options.tenantHint && { tenant_hint: this.options.tenantHint },
|
|
151
146
|
timeout_ms: this.options.timeout
|
|
152
|
-
// pasar el timeout configurado (opcional)
|
|
153
147
|
};
|
|
154
148
|
this.iframe?.contentWindow?.postMessage({
|
|
155
149
|
v: "2.3",
|
|
156
|
-
// versión del protocolo (estándar v2.3)
|
|
157
150
|
source: "@app/widget",
|
|
158
151
|
type: "sso-init",
|
|
159
152
|
requestId: this.requestId,
|
|
@@ -175,7 +168,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
175
168
|
payload.signed_payload,
|
|
176
169
|
this.options.jwksUrl,
|
|
177
170
|
window.location.origin
|
|
178
|
-
// aud esperado
|
|
179
171
|
);
|
|
180
172
|
if (decoded.nonce !== ctx.nonce) {
|
|
181
173
|
throw new Error("Invalid nonce");
|
|
@@ -184,8 +176,17 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
184
176
|
this.closeUI();
|
|
185
177
|
cleanup();
|
|
186
178
|
const result = {
|
|
187
|
-
|
|
188
|
-
|
|
179
|
+
code: decoded.code,
|
|
180
|
+
state: decoded.state || ctx.state,
|
|
181
|
+
nonce: ctx.nonce,
|
|
182
|
+
codeVerifier: ctx.verifier,
|
|
183
|
+
signed_payload: payload.signed_payload,
|
|
184
|
+
tenant: decoded.tenant,
|
|
185
|
+
jti: decoded.jti,
|
|
186
|
+
iss: decoded.iss,
|
|
187
|
+
aud: typeof decoded.aud === "string" ? decoded.aud : void 0,
|
|
188
|
+
exp: decoded.exp,
|
|
189
|
+
iat: decoded.iat
|
|
189
190
|
};
|
|
190
191
|
this.emit("success", result);
|
|
191
192
|
resolve(result);
|
|
@@ -229,15 +230,10 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
229
230
|
});
|
|
230
231
|
});
|
|
231
232
|
}
|
|
232
|
-
/** Cancela el flujo de autenticación en curso */
|
|
233
233
|
abort() {
|
|
234
234
|
this.abortController?.abort();
|
|
235
235
|
}
|
|
236
236
|
// ─── UI Management ───────────────────────────────────────────────
|
|
237
|
-
/**
|
|
238
|
-
* Crea (o reutiliza) el overlay con Shadow DOM y el iframe visible.
|
|
239
|
-
* Patrón tomado del CDN widget v1: Shadow DOM para aislar estilos.
|
|
240
|
-
*/
|
|
241
237
|
createUI() {
|
|
242
238
|
if (!this.hostEl) {
|
|
243
239
|
this.hostEl = document.createElement("div");
|
|
@@ -271,10 +267,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
271
267
|
this.overlayEl.classList.remove("sso-closing");
|
|
272
268
|
this.overlayEl.style.display = "flex";
|
|
273
269
|
}
|
|
274
|
-
/**
|
|
275
|
-
* Cierra el overlay con animación suave (fadeOut + slideDown).
|
|
276
|
-
* El overlay persiste en el DOM (solo se oculta).
|
|
277
|
-
*/
|
|
278
270
|
closeUI() {
|
|
279
271
|
if (!this.overlayEl || this.overlayEl.style.display === "none") return;
|
|
280
272
|
this.overlayEl.classList.add("sso-closing");
|
|
@@ -285,10 +277,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
285
277
|
}
|
|
286
278
|
}, 200);
|
|
287
279
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Estilos CSS encapsulados dentro del Shadow DOM.
|
|
290
|
-
* Migrados del widget CDN v1 con las mismas animaciones y responsive.
|
|
291
|
-
*/
|
|
292
280
|
getOverlayStyles() {
|
|
293
281
|
return `
|
|
294
282
|
.sso-overlay {
|
package/dist/browser/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BigsoAuthOptions } from '../types-
|
|
1
|
+
import { B as BigsoAuthOptions, a as BigsoAuthResult } from '../types-BQzACpj3.cjs';
|
|
2
2
|
|
|
3
3
|
declare class EventEmitter {
|
|
4
4
|
private events;
|
|
@@ -20,30 +20,13 @@ declare class BigsoAuth extends EventEmitter {
|
|
|
20
20
|
private overlayEl?;
|
|
21
21
|
private loginInProgress;
|
|
22
22
|
constructor(options: BigsoAuthOptions);
|
|
23
|
-
|
|
24
|
-
* Inicia el flujo de autenticación.
|
|
25
|
-
* @returns Promise que resuelve con el payload decodificado del JWS (solo para información; el backend debe validar)
|
|
26
|
-
*/
|
|
27
|
-
login(): Promise<any>;
|
|
28
|
-
/** Cancela el flujo de autenticación en curso */
|
|
23
|
+
login(): Promise<BigsoAuthResult>;
|
|
29
24
|
abort(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Crea (o reutiliza) el overlay con Shadow DOM y el iframe visible.
|
|
32
|
-
* Patrón tomado del CDN widget v1: Shadow DOM para aislar estilos.
|
|
33
|
-
*/
|
|
34
25
|
private createUI;
|
|
35
|
-
/**
|
|
36
|
-
* Cierra el overlay con animación suave (fadeOut + slideDown).
|
|
37
|
-
* El overlay persiste en el DOM (solo se oculta).
|
|
38
|
-
*/
|
|
39
26
|
private closeUI;
|
|
40
|
-
/**
|
|
41
|
-
* Estilos CSS encapsulados dentro del Shadow DOM.
|
|
42
|
-
* Migrados del widget CDN v1 con las mismas animaciones y responsive.
|
|
43
|
-
*/
|
|
44
27
|
private getOverlayStyles;
|
|
45
28
|
private buildFallbackUrl;
|
|
46
29
|
private debug;
|
|
47
30
|
}
|
|
48
31
|
|
|
49
|
-
export { BigsoAuth, BigsoAuthOptions };
|
|
32
|
+
export { BigsoAuth, BigsoAuthOptions, BigsoAuthResult };
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BigsoAuthOptions } from '../types-
|
|
1
|
+
import { B as BigsoAuthOptions, a as BigsoAuthResult } from '../types-BQzACpj3.js';
|
|
2
2
|
|
|
3
3
|
declare class EventEmitter {
|
|
4
4
|
private events;
|
|
@@ -20,30 +20,13 @@ declare class BigsoAuth extends EventEmitter {
|
|
|
20
20
|
private overlayEl?;
|
|
21
21
|
private loginInProgress;
|
|
22
22
|
constructor(options: BigsoAuthOptions);
|
|
23
|
-
|
|
24
|
-
* Inicia el flujo de autenticación.
|
|
25
|
-
* @returns Promise que resuelve con el payload decodificado del JWS (solo para información; el backend debe validar)
|
|
26
|
-
*/
|
|
27
|
-
login(): Promise<any>;
|
|
28
|
-
/** Cancela el flujo de autenticación en curso */
|
|
23
|
+
login(): Promise<BigsoAuthResult>;
|
|
29
24
|
abort(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Crea (o reutiliza) el overlay con Shadow DOM y el iframe visible.
|
|
32
|
-
* Patrón tomado del CDN widget v1: Shadow DOM para aislar estilos.
|
|
33
|
-
*/
|
|
34
25
|
private createUI;
|
|
35
|
-
/**
|
|
36
|
-
* Cierra el overlay con animación suave (fadeOut + slideDown).
|
|
37
|
-
* El overlay persiste en el DOM (solo se oculta).
|
|
38
|
-
*/
|
|
39
26
|
private closeUI;
|
|
40
|
-
/**
|
|
41
|
-
* Estilos CSS encapsulados dentro del Shadow DOM.
|
|
42
|
-
* Migrados del widget CDN v1 con las mismas animaciones y responsive.
|
|
43
|
-
*/
|
|
44
27
|
private getOverlayStyles;
|
|
45
28
|
private buildFallbackUrl;
|
|
46
29
|
private debug;
|
|
47
30
|
}
|
|
48
31
|
|
|
49
|
-
export { BigsoAuth, BigsoAuthOptions };
|
|
32
|
+
export { BigsoAuth, BigsoAuthOptions, BigsoAuthResult };
|
package/dist/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
verifySignedPayload
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-5ECHA2VH.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/crypto.ts
|
|
6
6
|
async function sha256Base64Url(input) {
|
|
@@ -48,7 +48,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
48
48
|
this.loginInProgress = false;
|
|
49
49
|
this.options = {
|
|
50
50
|
timeout: 5e3,
|
|
51
|
-
// por defecto 5s (estándar v2.3)
|
|
52
51
|
debug: false,
|
|
53
52
|
redirectUri: "",
|
|
54
53
|
tenantHint: "",
|
|
@@ -56,10 +55,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
56
55
|
...options
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Inicia el flujo de autenticación.
|
|
61
|
-
* @returns Promise que resuelve con el payload decodificado del JWS (solo para información; el backend debe validar)
|
|
62
|
-
*/
|
|
63
58
|
async login() {
|
|
64
59
|
if (this.loginInProgress) {
|
|
65
60
|
this.debug("login() ya en curso, ignorando llamada duplicada");
|
|
@@ -117,11 +112,9 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
117
112
|
...this.options.redirectUri && { redirect_uri: this.options.redirectUri },
|
|
118
113
|
...this.options.tenantHint && { tenant_hint: this.options.tenantHint },
|
|
119
114
|
timeout_ms: this.options.timeout
|
|
120
|
-
// pasar el timeout configurado (opcional)
|
|
121
115
|
};
|
|
122
116
|
this.iframe?.contentWindow?.postMessage({
|
|
123
117
|
v: "2.3",
|
|
124
|
-
// versión del protocolo (estándar v2.3)
|
|
125
118
|
source: "@app/widget",
|
|
126
119
|
type: "sso-init",
|
|
127
120
|
requestId: this.requestId,
|
|
@@ -143,7 +136,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
143
136
|
payload.signed_payload,
|
|
144
137
|
this.options.jwksUrl,
|
|
145
138
|
window.location.origin
|
|
146
|
-
// aud esperado
|
|
147
139
|
);
|
|
148
140
|
if (decoded.nonce !== ctx.nonce) {
|
|
149
141
|
throw new Error("Invalid nonce");
|
|
@@ -152,8 +144,17 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
152
144
|
this.closeUI();
|
|
153
145
|
cleanup();
|
|
154
146
|
const result = {
|
|
155
|
-
|
|
156
|
-
|
|
147
|
+
code: decoded.code,
|
|
148
|
+
state: decoded.state || ctx.state,
|
|
149
|
+
nonce: ctx.nonce,
|
|
150
|
+
codeVerifier: ctx.verifier,
|
|
151
|
+
signed_payload: payload.signed_payload,
|
|
152
|
+
tenant: decoded.tenant,
|
|
153
|
+
jti: decoded.jti,
|
|
154
|
+
iss: decoded.iss,
|
|
155
|
+
aud: typeof decoded.aud === "string" ? decoded.aud : void 0,
|
|
156
|
+
exp: decoded.exp,
|
|
157
|
+
iat: decoded.iat
|
|
157
158
|
};
|
|
158
159
|
this.emit("success", result);
|
|
159
160
|
resolve(result);
|
|
@@ -197,15 +198,10 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
197
198
|
});
|
|
198
199
|
});
|
|
199
200
|
}
|
|
200
|
-
/** Cancela el flujo de autenticación en curso */
|
|
201
201
|
abort() {
|
|
202
202
|
this.abortController?.abort();
|
|
203
203
|
}
|
|
204
204
|
// ─── UI Management ───────────────────────────────────────────────
|
|
205
|
-
/**
|
|
206
|
-
* Crea (o reutiliza) el overlay con Shadow DOM y el iframe visible.
|
|
207
|
-
* Patrón tomado del CDN widget v1: Shadow DOM para aislar estilos.
|
|
208
|
-
*/
|
|
209
205
|
createUI() {
|
|
210
206
|
if (!this.hostEl) {
|
|
211
207
|
this.hostEl = document.createElement("div");
|
|
@@ -239,10 +235,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
239
235
|
this.overlayEl.classList.remove("sso-closing");
|
|
240
236
|
this.overlayEl.style.display = "flex";
|
|
241
237
|
}
|
|
242
|
-
/**
|
|
243
|
-
* Cierra el overlay con animación suave (fadeOut + slideDown).
|
|
244
|
-
* El overlay persiste en el DOM (solo se oculta).
|
|
245
|
-
*/
|
|
246
238
|
closeUI() {
|
|
247
239
|
if (!this.overlayEl || this.overlayEl.style.display === "none") return;
|
|
248
240
|
this.overlayEl.classList.add("sso-closing");
|
|
@@ -253,10 +245,6 @@ var BigsoAuth = class extends EventEmitter {
|
|
|
253
245
|
}
|
|
254
246
|
}, 200);
|
|
255
247
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Estilos CSS encapsulados dentro del Shadow DOM.
|
|
258
|
-
* Migrados del widget CDN v1 con las mismas animaciones y responsive.
|
|
259
|
-
*/
|
|
260
248
|
getOverlayStyles() {
|
|
261
249
|
return `
|
|
262
250
|
.sso-overlay {
|