@bigso/auth-sdk 0.4.7 → 0.5.1

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.
@@ -1,137 +0,0 @@
1
- import {
2
- verifySignedPayload
3
- } from "../chunk-LDDK6SJD.js";
4
-
5
- // src/node/SsoClient.ts
6
- var BigsoSsoClient = class {
7
- constructor(options) {
8
- this.ssoBackendUrl = options.ssoBackendUrl;
9
- this.appId = options.appId;
10
- this.ssoJwksUrl = options.ssoJwksUrl;
11
- }
12
- /**
13
- * Verify a signed payload (JWS) against the SSO's JWKS
14
- * @param token - The compact JWS token
15
- * @param expectedAudience - The expected audience (app origin)
16
- * @returns The verified payload
17
- */
18
- async verifySignedPayload(token, expectedAudience) {
19
- if (!this.ssoJwksUrl) {
20
- throw new Error("ssoJwksUrl is required for verifySignedPayload");
21
- }
22
- return await verifySignedPayload(token, this.ssoJwksUrl, expectedAudience);
23
- }
24
- /**
25
- * Validate session token with SSO Backend
26
- * @param sessionToken - JWT token from cookie
27
- * @returns Session data or null if invalid
28
- */
29
- async validateSessionToken(sessionToken) {
30
- try {
31
- const response = await fetch(`${this.ssoBackendUrl}/api/v1/auth/verify-session`, {
32
- method: "POST",
33
- headers: {
34
- "Content-Type": "application/json"
35
- },
36
- body: JSON.stringify({
37
- sessionToken,
38
- appId: this.appId
39
- })
40
- // Node 18+ allows abort signals to enforce timeout, but we will rely on native fetch timeout if available or no timeout for simplicity.
41
- // In production, we might want to implement an AbortController wrapper.
42
- });
43
- if (!response.ok) {
44
- return null;
45
- }
46
- const data = await response.json();
47
- if (data.valid) {
48
- return {
49
- user: data.user,
50
- tenant: data.tenant,
51
- appId: data.appId,
52
- expiresAt: data.expiresAt
53
- };
54
- }
55
- return null;
56
- } catch (error) {
57
- console.error("\u274C [BigsoSsoClient] Error validating session:", error instanceof Error ? error.message : error);
58
- return null;
59
- }
60
- }
61
- /**
62
- * Exchange authorization code for session token from SSO
63
- * @param code - The auth code
64
- * @returns The SSO exchange response
65
- */
66
- async exchangeCodeForToken(code) {
67
- const response = await fetch(`${this.ssoBackendUrl}/api/v1/auth/token`, {
68
- method: "POST",
69
- headers: {
70
- "Content-Type": "application/json"
71
- },
72
- body: JSON.stringify({
73
- authCode: code,
74
- appId: this.appId
75
- })
76
- });
77
- if (!response.ok) {
78
- const errData = await response.json().catch(() => ({}));
79
- throw new Error(errData.message || "Failed to exchange token");
80
- }
81
- return await response.json();
82
- }
83
- /**
84
- * Revoke session in SSO backend
85
- * @param sessionToken - The active session token
86
- */
87
- async revokeSession(sessionToken) {
88
- const response = await fetch(`${this.ssoBackendUrl}/api/v1/session/revoke`, {
89
- method: "POST",
90
- headers: {
91
- "Content-Type": "application/json",
92
- "Authorization": `Bearer ${sessionToken}`
93
- }
94
- });
95
- if (!response.ok) {
96
- throw new Error("Failed to revoke session");
97
- }
98
- }
99
- /**
100
- * Refreshes the application session using a refresh token
101
- * @param refreshToken - The stored refresh token
102
- * @returns The new session tokens or null if failed
103
- */
104
- async refreshAppSession(refreshToken) {
105
- try {
106
- const response = await fetch(`${this.ssoBackendUrl}/api/v1/auth/app-refresh`, {
107
- method: "POST",
108
- headers: {
109
- "Content-Type": "application/json"
110
- },
111
- body: JSON.stringify({
112
- refreshToken,
113
- appId: this.appId
114
- })
115
- });
116
- if (!response.ok) {
117
- return null;
118
- }
119
- const data = await response.json();
120
- if (data.success) {
121
- return {
122
- sessionToken: data.sessionToken,
123
- refreshToken: data.refreshToken,
124
- expiresAt: data.expiresAt,
125
- refreshExpiresAt: data.refreshExpiresAt
126
- };
127
- }
128
- return null;
129
- } catch (error) {
130
- console.error("\u274C [BigsoSsoClient] Error refreshing app session:", error instanceof Error ? error.message : error);
131
- return null;
132
- }
133
- }
134
- };
135
- export {
136
- BigsoSsoClient
137
- };
@@ -1,51 +0,0 @@
1
- interface BigsoAuthOptions {
2
- /** Client ID registrado en el SSO */
3
- clientId: string;
4
- /** Origen del SSO (ej: https://sso.bigso.co) */
5
- ssoOrigin: string;
6
- /** URL del JWKS para verificar firmas (ej: https://sso.bigso.co/.well-known/jwks.json) */
7
- jwksUrl: string;
8
- /** Timeout en milisegundos (por defecto 5000) */
9
- timeout?: number;
10
- /** Activar logs de depuración */
11
- debug?: boolean;
12
- /** URI de redirección registrada (opcional, si se requiere validación exacta) */
13
- redirectUri?: string;
14
- /** Sugerencia de tenant (opcional) */
15
- tenantHint?: string;
16
- /** Tema visual del iframe ('light' | 'dark', por defecto 'light') */
17
- theme?: 'light' | 'dark';
18
- }
19
- interface SsoUser {
20
- userId: string;
21
- email: string;
22
- firstName: string;
23
- lastName: string;
24
- }
25
- interface SsoTenant {
26
- tenantId: string;
27
- name: string;
28
- slug: string;
29
- role: string;
30
- permissions: string[];
31
- }
32
- interface SsoSessionData {
33
- user: SsoUser;
34
- tenant: SsoTenant;
35
- appId: string;
36
- expiresAt: string;
37
- }
38
- interface SsoRefreshData {
39
- sessionToken: string;
40
- refreshToken: string;
41
- expiresAt: string;
42
- refreshExpiresAt: string;
43
- }
44
- interface SsoExchangeResponse extends SsoSessionData {
45
- success: boolean;
46
- sessionToken: string;
47
- refreshToken?: string;
48
- refreshExpiresAt?: string;
49
- }
50
-
51
- export type { BigsoAuthOptions as B, SsoSessionData as S, SsoExchangeResponse as a, SsoRefreshData as b };
@@ -1,51 +0,0 @@
1
- interface BigsoAuthOptions {
2
- /** Client ID registrado en el SSO */
3
- clientId: string;
4
- /** Origen del SSO (ej: https://sso.bigso.co) */
5
- ssoOrigin: string;
6
- /** URL del JWKS para verificar firmas (ej: https://sso.bigso.co/.well-known/jwks.json) */
7
- jwksUrl: string;
8
- /** Timeout en milisegundos (por defecto 5000) */
9
- timeout?: number;
10
- /** Activar logs de depuración */
11
- debug?: boolean;
12
- /** URI de redirección registrada (opcional, si se requiere validación exacta) */
13
- redirectUri?: string;
14
- /** Sugerencia de tenant (opcional) */
15
- tenantHint?: string;
16
- /** Tema visual del iframe ('light' | 'dark', por defecto 'light') */
17
- theme?: 'light' | 'dark';
18
- }
19
- interface SsoUser {
20
- userId: string;
21
- email: string;
22
- firstName: string;
23
- lastName: string;
24
- }
25
- interface SsoTenant {
26
- tenantId: string;
27
- name: string;
28
- slug: string;
29
- role: string;
30
- permissions: string[];
31
- }
32
- interface SsoSessionData {
33
- user: SsoUser;
34
- tenant: SsoTenant;
35
- appId: string;
36
- expiresAt: string;
37
- }
38
- interface SsoRefreshData {
39
- sessionToken: string;
40
- refreshToken: string;
41
- expiresAt: string;
42
- refreshExpiresAt: string;
43
- }
44
- interface SsoExchangeResponse extends SsoSessionData {
45
- success: boolean;
46
- sessionToken: string;
47
- refreshToken?: string;
48
- refreshExpiresAt?: string;
49
- }
50
-
51
- export type { BigsoAuthOptions as B, SsoSessionData as S, SsoExchangeResponse as a, SsoRefreshData as b };