@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.
- package/README.md +180 -135
- package/package.json +2 -2
- package/dist/browser/index.cjs +0 -376
- package/dist/browser/index.d.cts +0 -49
- package/dist/browser/index.d.ts +0 -49
- package/dist/browser/index.js +0 -343
- package/dist/chunk-LDDK6SJD.js +0 -13
- package/dist/express/index.cjs +0 -287
- package/dist/express/index.d.cts +0 -48
- package/dist/express/index.d.ts +0 -48
- package/dist/express/index.js +0 -257
- package/dist/node/index.cjs +0 -170
- package/dist/node/index.d.cts +0 -45
- package/dist/node/index.d.ts +0 -45
- package/dist/node/index.js +0 -137
- package/dist/types-CoXgtTry.d.cts +0 -51
- package/dist/types-CoXgtTry.d.ts +0 -51
package/dist/express/index.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction, Router } from 'express';
|
|
2
|
-
import { BigsoSsoClient } from '../node/index.js';
|
|
3
|
-
import { S as SsoSessionData } from '../types-CoXgtTry.js';
|
|
4
|
-
|
|
5
|
-
interface SsoAuthMiddlewareOptions {
|
|
6
|
-
ssoClient: BigsoSsoClient;
|
|
7
|
-
cookieName?: string;
|
|
8
|
-
cookieDomain?: string;
|
|
9
|
-
isProduction?: boolean;
|
|
10
|
-
onSessionValidated?: (session: SsoSessionData, req: Request) => Promise<void> | void;
|
|
11
|
-
}
|
|
12
|
-
declare global {
|
|
13
|
-
namespace Express {
|
|
14
|
-
interface Request {
|
|
15
|
-
user?: SsoSessionData['user'];
|
|
16
|
-
tenant?: SsoSessionData['tenant'];
|
|
17
|
-
ssoSession?: SsoSessionData;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
declare function ssoAuthMiddleware(options: SsoAuthMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
22
|
-
|
|
23
|
-
interface SsoSyncGuardOptions {
|
|
24
|
-
ssoBackendUrl: string;
|
|
25
|
-
isProduction?: boolean;
|
|
26
|
-
}
|
|
27
|
-
declare function ssoSyncGuardMiddleware(options: SsoSyncGuardOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
28
|
-
|
|
29
|
-
interface CreateSsoAuthRouterOptions {
|
|
30
|
-
ssoClient: BigsoSsoClient;
|
|
31
|
-
frontendUrl: string;
|
|
32
|
-
cookieName?: string;
|
|
33
|
-
cookieDomain?: string;
|
|
34
|
-
isProduction?: boolean;
|
|
35
|
-
onLoginSuccess?: (session: SsoSessionData) => void | Promise<void>;
|
|
36
|
-
onLogout?: (sessionToken: string) => void | Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
declare function createSsoAuthRouter(options: CreateSsoAuthRouterOptions): Router;
|
|
39
|
-
|
|
40
|
-
interface SsoSyncRouterOptions {
|
|
41
|
-
resources: any[];
|
|
42
|
-
appId: string;
|
|
43
|
-
ssoBackendUrl: string;
|
|
44
|
-
isProduction?: boolean;
|
|
45
|
-
}
|
|
46
|
-
declare function createSsoSyncRouter(options: SsoSyncRouterOptions): Router;
|
|
47
|
-
|
|
48
|
-
export { type CreateSsoAuthRouterOptions, type SsoAuthMiddlewareOptions, type SsoSyncGuardOptions, type SsoSyncRouterOptions, createSsoAuthRouter, createSsoSyncRouter, ssoAuthMiddleware, ssoSyncGuardMiddleware };
|
package/dist/express/index.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
// src/express/middlewares/ssoAuth.ts
|
|
2
|
-
function ssoAuthMiddleware(options) {
|
|
3
|
-
const cookieName = options.cookieName || "sso_session";
|
|
4
|
-
const isProduction = options.isProduction ?? process.env.NODE_ENV === "production";
|
|
5
|
-
return async (req, res, next) => {
|
|
6
|
-
try {
|
|
7
|
-
let sessionToken = req.cookies?.[cookieName];
|
|
8
|
-
let session = null;
|
|
9
|
-
if (sessionToken) {
|
|
10
|
-
session = await options.ssoClient.validateSessionToken(sessionToken);
|
|
11
|
-
}
|
|
12
|
-
if (!session) {
|
|
13
|
-
const refreshToken = req.cookies?.[`${cookieName}_refresh`];
|
|
14
|
-
if (refreshToken) {
|
|
15
|
-
const newSessionData = await options.ssoClient.refreshAppSession(refreshToken);
|
|
16
|
-
if (newSessionData) {
|
|
17
|
-
const sessionMaxAge = new Date(newSessionData.expiresAt).getTime() - Date.now();
|
|
18
|
-
const refreshMaxAge = newSessionData.refreshExpiresAt ? new Date(newSessionData.refreshExpiresAt).getTime() - Date.now() : 7 * 24 * 60 * 60 * 1e3;
|
|
19
|
-
const sessionCookieOptions = {
|
|
20
|
-
httpOnly: true,
|
|
21
|
-
secure: isProduction,
|
|
22
|
-
sameSite: "lax",
|
|
23
|
-
path: "/",
|
|
24
|
-
maxAge: sessionMaxAge > 0 ? sessionMaxAge : 0,
|
|
25
|
-
...isProduction && options.cookieDomain ? { domain: options.cookieDomain } : {}
|
|
26
|
-
};
|
|
27
|
-
const refreshCookieOptions = {
|
|
28
|
-
...sessionCookieOptions,
|
|
29
|
-
maxAge: refreshMaxAge > 0 ? refreshMaxAge : 0
|
|
30
|
-
};
|
|
31
|
-
res.cookie(cookieName, newSessionData.sessionToken, sessionCookieOptions);
|
|
32
|
-
res.cookie(`${cookieName}_refresh`, newSessionData.refreshToken, refreshCookieOptions);
|
|
33
|
-
session = await options.ssoClient.validateSessionToken(newSessionData.sessionToken);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (!session) {
|
|
37
|
-
res.clearCookie(cookieName);
|
|
38
|
-
res.clearCookie(`${cookieName}_refresh`);
|
|
39
|
-
res.status(401).json({ error: "Session expired or invalid" });
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (options.onSessionValidated) {
|
|
44
|
-
await options.onSessionValidated(session, req);
|
|
45
|
-
}
|
|
46
|
-
req.user = session.user;
|
|
47
|
-
req.tenant = session.tenant;
|
|
48
|
-
req.ssoSession = session;
|
|
49
|
-
next();
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error("\u274C [BigsoAuthSDK] Authentication Middleware Error:", error instanceof Error ? error.message : error);
|
|
52
|
-
res.status(500).json({ error: "Internal authentication error" });
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/express/middlewares/ssoSyncGuard.ts
|
|
58
|
-
import { promises as dns } from "dns";
|
|
59
|
-
function ssoSyncGuardMiddleware(options) {
|
|
60
|
-
const isProduction = options.isProduction ?? process.env.NODE_ENV === "production";
|
|
61
|
-
return async (req, res, next) => {
|
|
62
|
-
try {
|
|
63
|
-
const isSecure = req.secure || req.headers["x-forwarded-proto"] === "https";
|
|
64
|
-
if (!isSecure && isProduction) {
|
|
65
|
-
console.warn("\u26A0\uFE0F [BigsoAuthSDK] Blocked non-HTTPS sync request");
|
|
66
|
-
res.status(403).json({ error: "HTTPS required" });
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const clientIp = req.ip || req.socket.remoteAddress || "";
|
|
70
|
-
const isLoopback = clientIp === "::1" || clientIp === "127.0.0.1" || clientIp === "::ffff:127.0.0.1";
|
|
71
|
-
if (!isProduction && isLoopback) {
|
|
72
|
-
return next();
|
|
73
|
-
}
|
|
74
|
-
const ssoUrl = new URL(options.ssoBackendUrl);
|
|
75
|
-
const ssoHostname = ssoUrl.hostname;
|
|
76
|
-
const ssoIps = await dns.resolve4(ssoHostname).catch(() => []);
|
|
77
|
-
const cleanClientIp = clientIp.replace(/^.*:/, "");
|
|
78
|
-
const isPrivateIp = cleanClientIp.startsWith("10.") || cleanClientIp.startsWith("192.168.") || cleanClientIp.startsWith("172.") && parseInt(cleanClientIp.split(".")[1], 10) >= 16 && parseInt(cleanClientIp.split(".")[1], 10) <= 31;
|
|
79
|
-
if (!ssoIps.includes(cleanClientIp) && !isPrivateIp) {
|
|
80
|
-
console.warn(`\u26D4\uFE0F [BigsoAuthSDK] Blocked sync request from unauthorized IP: ${clientIp}`);
|
|
81
|
-
res.status(403).json({ error: "Unauthorized origin" });
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
next();
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error("\u274C [BigsoAuthSDK] Sync Guard Validation Error:", error instanceof Error ? error.message : error);
|
|
87
|
-
res.status(500).json({ error: "Security validation failed" });
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// src/express/routes/createSsoAuthRouter.ts
|
|
93
|
-
import { Router } from "express";
|
|
94
|
-
function createSsoAuthRouter(options) {
|
|
95
|
-
const router = Router();
|
|
96
|
-
const cookieName = options.cookieName || "sso_session";
|
|
97
|
-
const isProduction = options.isProduction ?? process.env.NODE_ENV === "production";
|
|
98
|
-
const getCookieOptions = (customOptions = {}) => {
|
|
99
|
-
const base = {
|
|
100
|
-
httpOnly: true,
|
|
101
|
-
secure: isProduction,
|
|
102
|
-
sameSite: "lax",
|
|
103
|
-
path: "/",
|
|
104
|
-
...customOptions
|
|
105
|
-
};
|
|
106
|
-
if (isProduction && options.cookieDomain) {
|
|
107
|
-
base.domain = options.cookieDomain;
|
|
108
|
-
}
|
|
109
|
-
return base;
|
|
110
|
-
};
|
|
111
|
-
router.post("/exchange", async (req, res) => {
|
|
112
|
-
try {
|
|
113
|
-
const { code } = req.body;
|
|
114
|
-
if (!code) {
|
|
115
|
-
res.status(400).json({ error: "Authorization code is required" });
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const ssoResponse = await options.ssoClient.exchangeCodeForToken(code);
|
|
119
|
-
if (!ssoResponse.success) {
|
|
120
|
-
res.status(401).json({ error: "Invalid authorization code" });
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const sessionMaxAge = new Date(ssoResponse.expiresAt).getTime() - Date.now();
|
|
124
|
-
const refreshMaxAge = ssoResponse.refreshExpiresAt ? new Date(ssoResponse.refreshExpiresAt).getTime() - Date.now() : 7 * 24 * 60 * 60 * 1e3;
|
|
125
|
-
const sessionCookieOptions = getCookieOptions({
|
|
126
|
-
maxAge: sessionMaxAge > 0 ? sessionMaxAge : 0
|
|
127
|
-
});
|
|
128
|
-
const refreshCookieOptions = getCookieOptions({
|
|
129
|
-
maxAge: refreshMaxAge > 0 ? refreshMaxAge : 0
|
|
130
|
-
});
|
|
131
|
-
res.cookie(cookieName, ssoResponse.sessionToken, sessionCookieOptions);
|
|
132
|
-
if (ssoResponse.refreshToken) {
|
|
133
|
-
res.cookie(`${cookieName}_refresh`, ssoResponse.refreshToken, refreshCookieOptions);
|
|
134
|
-
}
|
|
135
|
-
if (options.onLoginSuccess) {
|
|
136
|
-
await options.onLoginSuccess(ssoResponse);
|
|
137
|
-
}
|
|
138
|
-
res.json({
|
|
139
|
-
success: true,
|
|
140
|
-
user: ssoResponse.user,
|
|
141
|
-
tenant: ssoResponse.tenant,
|
|
142
|
-
expiresAt: ssoResponse.expiresAt
|
|
143
|
-
});
|
|
144
|
-
} catch (error) {
|
|
145
|
-
console.error("\u274C [BigsoAuthSDK] Error exchanging code:", error.message);
|
|
146
|
-
res.status(500).json({
|
|
147
|
-
error: error.message || "Failed to exchange authorization code"
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
router.post("/exchange-v2", async (req, res) => {
|
|
152
|
-
try {
|
|
153
|
-
const { payload } = req.body;
|
|
154
|
-
if (!payload) {
|
|
155
|
-
res.status(400).json({ error: "Signed payload is required" });
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const verified = await options.ssoClient.verifySignedPayload(payload, options.frontendUrl);
|
|
159
|
-
if (!verified.code) {
|
|
160
|
-
res.status(400).json({ error: "No authorization code found in payload" });
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const ssoResponse = await options.ssoClient.exchangeCodeForToken(verified.code);
|
|
164
|
-
if (!ssoResponse.success) {
|
|
165
|
-
res.status(401).json({ error: "Invalid authorization code" });
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const sessionMaxAge = new Date(ssoResponse.expiresAt).getTime() - Date.now();
|
|
169
|
-
const refreshMaxAge = ssoResponse.refreshExpiresAt ? new Date(ssoResponse.refreshExpiresAt).getTime() - Date.now() : 7 * 24 * 60 * 60 * 1e3;
|
|
170
|
-
const sessionCookieOptions = getCookieOptions({
|
|
171
|
-
maxAge: sessionMaxAge > 0 ? sessionMaxAge : 0
|
|
172
|
-
});
|
|
173
|
-
const refreshCookieOptions = getCookieOptions({
|
|
174
|
-
maxAge: refreshMaxAge > 0 ? refreshMaxAge : 0
|
|
175
|
-
});
|
|
176
|
-
res.cookie(cookieName, ssoResponse.sessionToken, sessionCookieOptions);
|
|
177
|
-
if (ssoResponse.refreshToken) {
|
|
178
|
-
res.cookie(`${cookieName}_refresh`, ssoResponse.refreshToken, refreshCookieOptions);
|
|
179
|
-
}
|
|
180
|
-
if (options.onLoginSuccess) {
|
|
181
|
-
await options.onLoginSuccess(ssoResponse);
|
|
182
|
-
}
|
|
183
|
-
res.json({
|
|
184
|
-
success: true,
|
|
185
|
-
user: ssoResponse.user,
|
|
186
|
-
tenant: ssoResponse.tenant,
|
|
187
|
-
expiresAt: ssoResponse.expiresAt
|
|
188
|
-
});
|
|
189
|
-
} catch (error) {
|
|
190
|
-
console.error("\u274C [BigsoAuthSDK] Error exchanging v2 payload:", error.message);
|
|
191
|
-
res.status(401).json({
|
|
192
|
-
error: error.message || "Failed to verify signed payload"
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
router.get("/session", ssoAuthMiddleware(options), (req, res) => {
|
|
197
|
-
res.set("Cache-Control", "no-store, no-cache, must-revalidate, private");
|
|
198
|
-
res.set("Pragma", "no-cache");
|
|
199
|
-
res.set("Expires", "0");
|
|
200
|
-
res.json({
|
|
201
|
-
success: true,
|
|
202
|
-
user: req.user,
|
|
203
|
-
tenant: req.tenant,
|
|
204
|
-
expiresAt: req.ssoSession?.expiresAt
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
router.post("/logout", async (req, res) => {
|
|
208
|
-
const sessionToken = req.cookies?.[cookieName];
|
|
209
|
-
if (sessionToken) {
|
|
210
|
-
try {
|
|
211
|
-
await options.ssoClient.revokeSession(sessionToken);
|
|
212
|
-
} catch (error) {
|
|
213
|
-
console.warn("\u26A0\uFE0F [BigsoAuthSDK] Failed to revoke session in SSO Backend. Clearing local anyway.", error.message);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const cookieOptions = getCookieOptions({ maxAge: 0 });
|
|
217
|
-
res.clearCookie(cookieName, cookieOptions);
|
|
218
|
-
res.clearCookie(`${cookieName}_refresh`, cookieOptions);
|
|
219
|
-
if (options.onLogout && sessionToken) {
|
|
220
|
-
await options.onLogout(sessionToken);
|
|
221
|
-
}
|
|
222
|
-
res.json({ success: true, message: "Logged out" });
|
|
223
|
-
});
|
|
224
|
-
return router;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// src/express/routes/createSsoSyncRouter.ts
|
|
228
|
-
import { Router as Router2 } from "express";
|
|
229
|
-
function createSsoSyncRouter(options) {
|
|
230
|
-
const router = Router2();
|
|
231
|
-
router.get("/resources", ssoSyncGuardMiddleware({
|
|
232
|
-
ssoBackendUrl: options.ssoBackendUrl,
|
|
233
|
-
isProduction: options.isProduction
|
|
234
|
-
}), (req, res) => {
|
|
235
|
-
try {
|
|
236
|
-
res.json({
|
|
237
|
-
success: true,
|
|
238
|
-
resources: options.resources,
|
|
239
|
-
meta: {
|
|
240
|
-
appId: options.appId,
|
|
241
|
-
count: options.resources.length,
|
|
242
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
} catch (error) {
|
|
246
|
-
console.error("\u274C [BigsoAuthSDK] Error in sync endpoint:", error.message);
|
|
247
|
-
res.status(500).json({ error: error.message });
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
return router;
|
|
251
|
-
}
|
|
252
|
-
export {
|
|
253
|
-
createSsoAuthRouter,
|
|
254
|
-
createSsoSyncRouter,
|
|
255
|
-
ssoAuthMiddleware,
|
|
256
|
-
ssoSyncGuardMiddleware
|
|
257
|
-
};
|
package/dist/node/index.cjs
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/node/index.ts
|
|
21
|
-
var node_exports = {};
|
|
22
|
-
__export(node_exports, {
|
|
23
|
-
BigsoSsoClient: () => BigsoSsoClient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(node_exports);
|
|
26
|
-
|
|
27
|
-
// src/utils/jws.ts
|
|
28
|
-
var import_jose = require("jose");
|
|
29
|
-
async function verifySignedPayload(token, jwksUrl, expectedAudience) {
|
|
30
|
-
const JWKS = (0, import_jose.createRemoteJWKSet)(new URL(jwksUrl));
|
|
31
|
-
const { payload } = await (0, import_jose.jwtVerify)(token, JWKS, {
|
|
32
|
-
audience: expectedAudience
|
|
33
|
-
});
|
|
34
|
-
return payload;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/node/SsoClient.ts
|
|
38
|
-
var BigsoSsoClient = class {
|
|
39
|
-
constructor(options) {
|
|
40
|
-
this.ssoBackendUrl = options.ssoBackendUrl;
|
|
41
|
-
this.appId = options.appId;
|
|
42
|
-
this.ssoJwksUrl = options.ssoJwksUrl;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Verify a signed payload (JWS) against the SSO's JWKS
|
|
46
|
-
* @param token - The compact JWS token
|
|
47
|
-
* @param expectedAudience - The expected audience (app origin)
|
|
48
|
-
* @returns The verified payload
|
|
49
|
-
*/
|
|
50
|
-
async verifySignedPayload(token, expectedAudience) {
|
|
51
|
-
if (!this.ssoJwksUrl) {
|
|
52
|
-
throw new Error("ssoJwksUrl is required for verifySignedPayload");
|
|
53
|
-
}
|
|
54
|
-
return await verifySignedPayload(token, this.ssoJwksUrl, expectedAudience);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Validate session token with SSO Backend
|
|
58
|
-
* @param sessionToken - JWT token from cookie
|
|
59
|
-
* @returns Session data or null if invalid
|
|
60
|
-
*/
|
|
61
|
-
async validateSessionToken(sessionToken) {
|
|
62
|
-
try {
|
|
63
|
-
const response = await fetch(`${this.ssoBackendUrl}/api/v1/auth/verify-session`, {
|
|
64
|
-
method: "POST",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json"
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify({
|
|
69
|
-
sessionToken,
|
|
70
|
-
appId: this.appId
|
|
71
|
-
})
|
|
72
|
-
// Node 18+ allows abort signals to enforce timeout, but we will rely on native fetch timeout if available or no timeout for simplicity.
|
|
73
|
-
// In production, we might want to implement an AbortController wrapper.
|
|
74
|
-
});
|
|
75
|
-
if (!response.ok) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
const data = await response.json();
|
|
79
|
-
if (data.valid) {
|
|
80
|
-
return {
|
|
81
|
-
user: data.user,
|
|
82
|
-
tenant: data.tenant,
|
|
83
|
-
appId: data.appId,
|
|
84
|
-
expiresAt: data.expiresAt
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error("\u274C [BigsoSsoClient] Error validating session:", error instanceof Error ? error.message : error);
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Exchange authorization code for session token from SSO
|
|
95
|
-
* @param code - The auth code
|
|
96
|
-
* @returns The SSO exchange response
|
|
97
|
-
*/
|
|
98
|
-
async exchangeCodeForToken(code) {
|
|
99
|
-
const response = await fetch(`${this.ssoBackendUrl}/api/v1/auth/token`, {
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: {
|
|
102
|
-
"Content-Type": "application/json"
|
|
103
|
-
},
|
|
104
|
-
body: JSON.stringify({
|
|
105
|
-
authCode: code,
|
|
106
|
-
appId: this.appId
|
|
107
|
-
})
|
|
108
|
-
});
|
|
109
|
-
if (!response.ok) {
|
|
110
|
-
const errData = await response.json().catch(() => ({}));
|
|
111
|
-
throw new Error(errData.message || "Failed to exchange token");
|
|
112
|
-
}
|
|
113
|
-
return await response.json();
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Revoke session in SSO backend
|
|
117
|
-
* @param sessionToken - The active session token
|
|
118
|
-
*/
|
|
119
|
-
async revokeSession(sessionToken) {
|
|
120
|
-
const response = await fetch(`${this.ssoBackendUrl}/api/v1/session/revoke`, {
|
|
121
|
-
method: "POST",
|
|
122
|
-
headers: {
|
|
123
|
-
"Content-Type": "application/json",
|
|
124
|
-
"Authorization": `Bearer ${sessionToken}`
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
throw new Error("Failed to revoke session");
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Refreshes the application session using a refresh token
|
|
133
|
-
* @param refreshToken - The stored refresh token
|
|
134
|
-
* @returns The new session tokens or null if failed
|
|
135
|
-
*/
|
|
136
|
-
async refreshAppSession(refreshToken) {
|
|
137
|
-
try {
|
|
138
|
-
const response = await fetch(`${this.ssoBackendUrl}/api/v1/auth/app-refresh`, {
|
|
139
|
-
method: "POST",
|
|
140
|
-
headers: {
|
|
141
|
-
"Content-Type": "application/json"
|
|
142
|
-
},
|
|
143
|
-
body: JSON.stringify({
|
|
144
|
-
refreshToken,
|
|
145
|
-
appId: this.appId
|
|
146
|
-
})
|
|
147
|
-
});
|
|
148
|
-
if (!response.ok) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
const data = await response.json();
|
|
152
|
-
if (data.success) {
|
|
153
|
-
return {
|
|
154
|
-
sessionToken: data.sessionToken,
|
|
155
|
-
refreshToken: data.refreshToken,
|
|
156
|
-
expiresAt: data.expiresAt,
|
|
157
|
-
refreshExpiresAt: data.refreshExpiresAt
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error("\u274C [BigsoSsoClient] Error refreshing app session:", error instanceof Error ? error.message : error);
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
-
0 && (module.exports = {
|
|
169
|
-
BigsoSsoClient
|
|
170
|
-
});
|
package/dist/node/index.d.cts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { S as SsoSessionData, a as SsoExchangeResponse, b as SsoRefreshData } from '../types-CoXgtTry.cjs';
|
|
2
|
-
|
|
3
|
-
interface SsoClientOptions {
|
|
4
|
-
ssoBackendUrl: string;
|
|
5
|
-
ssoJwksUrl?: string;
|
|
6
|
-
appId: string;
|
|
7
|
-
}
|
|
8
|
-
declare class BigsoSsoClient {
|
|
9
|
-
private ssoBackendUrl;
|
|
10
|
-
private appId;
|
|
11
|
-
private ssoJwksUrl?;
|
|
12
|
-
constructor(options: SsoClientOptions);
|
|
13
|
-
/**
|
|
14
|
-
* Verify a signed payload (JWS) against the SSO's JWKS
|
|
15
|
-
* @param token - The compact JWS token
|
|
16
|
-
* @param expectedAudience - The expected audience (app origin)
|
|
17
|
-
* @returns The verified payload
|
|
18
|
-
*/
|
|
19
|
-
verifySignedPayload(token: string, expectedAudience: string): Promise<any>;
|
|
20
|
-
/**
|
|
21
|
-
* Validate session token with SSO Backend
|
|
22
|
-
* @param sessionToken - JWT token from cookie
|
|
23
|
-
* @returns Session data or null if invalid
|
|
24
|
-
*/
|
|
25
|
-
validateSessionToken(sessionToken: string): Promise<SsoSessionData | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Exchange authorization code for session token from SSO
|
|
28
|
-
* @param code - The auth code
|
|
29
|
-
* @returns The SSO exchange response
|
|
30
|
-
*/
|
|
31
|
-
exchangeCodeForToken(code: string): Promise<SsoExchangeResponse>;
|
|
32
|
-
/**
|
|
33
|
-
* Revoke session in SSO backend
|
|
34
|
-
* @param sessionToken - The active session token
|
|
35
|
-
*/
|
|
36
|
-
revokeSession(sessionToken: string): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Refreshes the application session using a refresh token
|
|
39
|
-
* @param refreshToken - The stored refresh token
|
|
40
|
-
* @returns The new session tokens or null if failed
|
|
41
|
-
*/
|
|
42
|
-
refreshAppSession(refreshToken: string): Promise<SsoRefreshData | null>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { BigsoSsoClient, type SsoClientOptions };
|
package/dist/node/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { S as SsoSessionData, a as SsoExchangeResponse, b as SsoRefreshData } from '../types-CoXgtTry.js';
|
|
2
|
-
|
|
3
|
-
interface SsoClientOptions {
|
|
4
|
-
ssoBackendUrl: string;
|
|
5
|
-
ssoJwksUrl?: string;
|
|
6
|
-
appId: string;
|
|
7
|
-
}
|
|
8
|
-
declare class BigsoSsoClient {
|
|
9
|
-
private ssoBackendUrl;
|
|
10
|
-
private appId;
|
|
11
|
-
private ssoJwksUrl?;
|
|
12
|
-
constructor(options: SsoClientOptions);
|
|
13
|
-
/**
|
|
14
|
-
* Verify a signed payload (JWS) against the SSO's JWKS
|
|
15
|
-
* @param token - The compact JWS token
|
|
16
|
-
* @param expectedAudience - The expected audience (app origin)
|
|
17
|
-
* @returns The verified payload
|
|
18
|
-
*/
|
|
19
|
-
verifySignedPayload(token: string, expectedAudience: string): Promise<any>;
|
|
20
|
-
/**
|
|
21
|
-
* Validate session token with SSO Backend
|
|
22
|
-
* @param sessionToken - JWT token from cookie
|
|
23
|
-
* @returns Session data or null if invalid
|
|
24
|
-
*/
|
|
25
|
-
validateSessionToken(sessionToken: string): Promise<SsoSessionData | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Exchange authorization code for session token from SSO
|
|
28
|
-
* @param code - The auth code
|
|
29
|
-
* @returns The SSO exchange response
|
|
30
|
-
*/
|
|
31
|
-
exchangeCodeForToken(code: string): Promise<SsoExchangeResponse>;
|
|
32
|
-
/**
|
|
33
|
-
* Revoke session in SSO backend
|
|
34
|
-
* @param sessionToken - The active session token
|
|
35
|
-
*/
|
|
36
|
-
revokeSession(sessionToken: string): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Refreshes the application session using a refresh token
|
|
39
|
-
* @param refreshToken - The stored refresh token
|
|
40
|
-
* @returns The new session tokens or null if failed
|
|
41
|
-
*/
|
|
42
|
-
refreshAppSession(refreshToken: string): Promise<SsoRefreshData | null>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { BigsoSsoClient, type SsoClientOptions };
|