@nibssplc/cams-sdk 0.0.1-beta.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 +151 -0
- package/dist/__tests__/auth.test.d.ts +1 -0
- package/dist/__tests__/session.test.d.ts +1 -0
- package/dist/__tests__/validators.test.d.ts +1 -0
- package/dist/auth.d.ts +2 -0
- package/dist/index.cjs.js +320 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +310 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +324 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/session.d.ts +19 -0
- package/dist/tokenManager.d.ts +12 -0
- package/dist/types.d.ts +28 -0
- package/dist/validators.d.ts +26 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# NIBSS CAMS SDK
|
|
2
|
+
|
|
3
|
+
Central Authentication Management Service (CAMS) SDK for popup-based authentication with Azure AD + custom 2FA.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ Secure popup-based authentication
|
|
8
|
+
- ๐ก๏ธ URL validation and domain allowlisting
|
|
9
|
+
- โฑ๏ธ Configurable timeouts and retry logic
|
|
10
|
+
- ๐ Automatic token management with expiration checking
|
|
11
|
+
- ๐ฑ Session management with event callbacks
|
|
12
|
+
- ๐งช Comprehensive TypeScript support
|
|
13
|
+
- โ
Full test coverage
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @nibssplc/cams-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### Basic Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { openCAMSLogin, CAMSConfig } from '@nibssplc/cams-sdk';
|
|
27
|
+
|
|
28
|
+
const config: CAMSConfig = {
|
|
29
|
+
camsUrl: 'https://your-cams-instance.com/auth',
|
|
30
|
+
allowedOrigin: 'https://your-cams-instance.com',
|
|
31
|
+
windowWidth: 500,
|
|
32
|
+
windowHeight: 600,
|
|
33
|
+
timeout: 300000, // 5 minutes
|
|
34
|
+
allowedDomains: ['your-cams-instance.com'], // Security allowlist
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const response = await openCAMSPopUpLogin(config);
|
|
39
|
+
console.log('Authentication successful:', response.token);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error('Authentication failed:', error);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Session Management (Recommended)
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { CAMSSession, CAMSEvents } from '@nibssplc/cams-sdk';
|
|
49
|
+
|
|
50
|
+
const events: CAMSEvents = {
|
|
51
|
+
onAuthStart: () => console.log('Authentication started'),
|
|
52
|
+
onAuthSuccess: (token) => console.log('Login successful'),
|
|
53
|
+
onAuthError: (error) => console.error('Login failed:', error),
|
|
54
|
+
onTokenExpired: () => console.log('Token expired'),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const session = new CAMSSession(sessionStorage, 'my_app_token', events);
|
|
58
|
+
|
|
59
|
+
// Login with retry logic
|
|
60
|
+
const config = {
|
|
61
|
+
// ... your config
|
|
62
|
+
retryAttempts: 2, // Retry twice on failure
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
await session.login(config);
|
|
67
|
+
|
|
68
|
+
// Check authentication status
|
|
69
|
+
if (session.isAuthenticated()) {
|
|
70
|
+
const token = session.getAccessToken();
|
|
71
|
+
const profile = await session.getProfile();
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// Handle authentication error
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Logout
|
|
78
|
+
await session.logout();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Configuration Options
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface CAMSConfig {
|
|
85
|
+
camsUrl: string; // CAMS authentication URL
|
|
86
|
+
allowedOrigin: string; // Expected message origin
|
|
87
|
+
windowWidth: number; // Popup window width
|
|
88
|
+
windowHeight: number; // Popup window height
|
|
89
|
+
timeout?: number; // Auth timeout in ms (default: 300000)
|
|
90
|
+
allowedDomains?: string[]; // URL allowlist for security
|
|
91
|
+
storageKey?: string; // Custom storage key
|
|
92
|
+
retryAttempts?: number; // Auto-retry on failure (default: 0)
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Error Handling
|
|
97
|
+
|
|
98
|
+
The SDK provides typed errors for better error handling:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { CAMSError, CAMSErrorType } from '@nibssplc/cams-sdk';
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await session.login(config);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof CAMSError) {
|
|
107
|
+
switch (error.type) {
|
|
108
|
+
case CAMSErrorType.POPUP_BLOCKED:
|
|
109
|
+
// Handle popup blocker
|
|
110
|
+
break;
|
|
111
|
+
case CAMSErrorType.TIMEOUT:
|
|
112
|
+
// Handle timeout
|
|
113
|
+
break;
|
|
114
|
+
case CAMSErrorType.INVALID_URL:
|
|
115
|
+
// Handle invalid URL
|
|
116
|
+
break;
|
|
117
|
+
case CAMSErrorType.USER_CANCELLED:
|
|
118
|
+
// Handle user cancellation
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Security Features
|
|
126
|
+
|
|
127
|
+
- **URL Validation**: Prevents open redirect attacks
|
|
128
|
+
- **Domain Allowlisting**: Restricts authentication to approved domains
|
|
129
|
+
- **Origin Validation**: Validates message origins
|
|
130
|
+
- **Token Validation**: Uses Zod schemas for runtime validation
|
|
131
|
+
- **Secure Storage**: Configurable storage with automatic cleanup
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Install dependencies
|
|
137
|
+
npm install
|
|
138
|
+
|
|
139
|
+
# Run tests
|
|
140
|
+
npm test
|
|
141
|
+
|
|
142
|
+
# Build
|
|
143
|
+
npm run build
|
|
144
|
+
|
|
145
|
+
# Lint
|
|
146
|
+
npm run lint
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT ยฉ NIBSS PLC
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
exports.CAMSErrorType = void 0;
|
|
6
|
+
(function (CAMSErrorType) {
|
|
7
|
+
CAMSErrorType["POPUP_BLOCKED"] = "POPUP_BLOCKED";
|
|
8
|
+
CAMSErrorType["TIMEOUT"] = "TIMEOUT";
|
|
9
|
+
CAMSErrorType["INVALID_ORIGIN"] = "INVALID_ORIGIN";
|
|
10
|
+
CAMSErrorType["USER_CANCELLED"] = "USER_CANCELLED";
|
|
11
|
+
CAMSErrorType["INVALID_URL"] = "INVALID_URL";
|
|
12
|
+
CAMSErrorType["MAX_RETRIES_EXCEEDED"] = "MAX_RETRIES_EXCEEDED";
|
|
13
|
+
})(exports.CAMSErrorType || (exports.CAMSErrorType = {}));
|
|
14
|
+
class CAMSError extends Error {
|
|
15
|
+
constructor(type, message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.type = type;
|
|
18
|
+
this.name = 'CAMSError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Validate the returned token - Base64 format with minimum 20 chars
|
|
23
|
+
const TokenMessageSchema = zod.z.object({
|
|
24
|
+
access_token: zod.z.string().regex(/^[A-Za-z0-9+/]{20,}={0,2}$/, "Invalid NIBSS CAMS token format"),
|
|
25
|
+
});
|
|
26
|
+
const ErrorMessageSchema = zod.z.object({
|
|
27
|
+
error: zod.z.string(),
|
|
28
|
+
});
|
|
29
|
+
const TokenSchema = zod.z.object({
|
|
30
|
+
access_token: zod.z.string(),
|
|
31
|
+
refresh_token: zod.z.string().optional(),
|
|
32
|
+
expires_in: zod.z.number(), // in seconds
|
|
33
|
+
token_type: zod.z.string().default("Bearer"),
|
|
34
|
+
id_token: zod.z.string().optional(),
|
|
35
|
+
});
|
|
36
|
+
const ProfileSchema = zod.z.object({
|
|
37
|
+
sub: zod.z.string(), // user ID
|
|
38
|
+
name: zod.z.string().optional(),
|
|
39
|
+
email: zod.z.email({ message: "Invalid email address" }).optional(),
|
|
40
|
+
given_name: zod.z.string().optional(),
|
|
41
|
+
family_name: zod.z.string().optional(),
|
|
42
|
+
roles: zod.z.array(zod.z.string()).optional(),
|
|
43
|
+
});
|
|
44
|
+
// URL validation schema - only HTTPS for production security
|
|
45
|
+
const URLSchema = zod.z.string().url().refine((url) => url.startsWith('https://'), { message: "Only HTTPS URLs are allowed" });
|
|
46
|
+
|
|
47
|
+
function validateConfig(config) {
|
|
48
|
+
var _a;
|
|
49
|
+
// Validate URL format
|
|
50
|
+
const urlValidation = URLSchema.safeParse(config.camsUrl);
|
|
51
|
+
if (!urlValidation.success) {
|
|
52
|
+
throw new CAMSError(exports.CAMSErrorType.INVALID_URL, 'Invalid CAMS URL format');
|
|
53
|
+
}
|
|
54
|
+
// Domain validation is mandatory for security
|
|
55
|
+
if (!((_a = config.allowedDomains) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
56
|
+
throw new CAMSError(exports.CAMSErrorType.INVALID_URL, 'allowedDomains must be specified for security');
|
|
57
|
+
}
|
|
58
|
+
const url = new URL(config.camsUrl); // URLSchema already validated this
|
|
59
|
+
const isAllowed = config.allowedDomains.some(domain => url.hostname === domain || url.hostname.endsWith('.' + domain));
|
|
60
|
+
if (!isAllowed) {
|
|
61
|
+
throw new CAMSError(exports.CAMSErrorType.INVALID_URL, 'URL not in allowed domains list');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function openCAMSPopUpLogin(config) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
try {
|
|
67
|
+
validateConfig(config);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
reject(error);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { camsUrl, allowedOrigin, windowHeight, windowWidth, timeout = 300000 } = config;
|
|
74
|
+
let authWindow;
|
|
75
|
+
let timeoutId = null;
|
|
76
|
+
let checkClosedInterval = null;
|
|
77
|
+
try {
|
|
78
|
+
authWindow = window.open(camsUrl, "NIBSS CAMS Login", `width=${windowWidth},height=${windowHeight}`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
reject(new CAMSError(exports.CAMSErrorType.POPUP_BLOCKED, "Failed to open authentication window: " + (error instanceof Error ? error.message : "Unknown error")));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (!authWindow) {
|
|
85
|
+
reject(new CAMSError(exports.CAMSErrorType.POPUP_BLOCKED, "Failed to open authentication window. Please allow popups."));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const cleanup = () => {
|
|
89
|
+
window.removeEventListener("message", listener);
|
|
90
|
+
if (timeoutId)
|
|
91
|
+
clearTimeout(timeoutId);
|
|
92
|
+
if (checkClosedInterval)
|
|
93
|
+
clearInterval(checkClosedInterval);
|
|
94
|
+
};
|
|
95
|
+
const cleanupAndClose = (error) => {
|
|
96
|
+
cleanup();
|
|
97
|
+
try {
|
|
98
|
+
if (authWindow && !authWindow.closed) {
|
|
99
|
+
authWindow.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Ignore close errors
|
|
104
|
+
}
|
|
105
|
+
if (error)
|
|
106
|
+
reject(error);
|
|
107
|
+
};
|
|
108
|
+
const listener = (event) => {
|
|
109
|
+
if (event.origin !== allowedOrigin) {
|
|
110
|
+
// Sanitize origin for logging to prevent log injection
|
|
111
|
+
const sanitizedOrigin = event.origin.replace(/[\r\n]/g, '');
|
|
112
|
+
console.warn("Blocked message from origin:", sanitizedOrigin);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// โ
Validate payload
|
|
116
|
+
const tokenMsg = TokenMessageSchema.safeParse(event.data);
|
|
117
|
+
if (tokenMsg.success) {
|
|
118
|
+
cleanupAndClose();
|
|
119
|
+
resolve({ token: tokenMsg.data.access_token });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const errorMsg = ErrorMessageSchema.safeParse(event.data);
|
|
123
|
+
if (errorMsg.success) {
|
|
124
|
+
cleanupAndClose(new CAMSError(exports.CAMSErrorType.USER_CANCELLED, "Authentication failed: " + errorMsg.data.error));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
cleanupAndClose(new CAMSError(exports.CAMSErrorType.INVALID_ORIGIN, "Invalid message format"));
|
|
128
|
+
};
|
|
129
|
+
// Timeout handler
|
|
130
|
+
timeoutId = setTimeout(() => {
|
|
131
|
+
cleanupAndClose(new CAMSError(exports.CAMSErrorType.TIMEOUT, `Authentication timeout after ${timeout}ms`));
|
|
132
|
+
}, timeout);
|
|
133
|
+
checkClosedInterval = setInterval(() => {
|
|
134
|
+
if (authWindow && authWindow.closed) {
|
|
135
|
+
cleanupAndClose(new CAMSError(exports.CAMSErrorType.USER_CANCELLED, "Authentication window was closed"));
|
|
136
|
+
}
|
|
137
|
+
}, 2000); // Reduced polling frequency
|
|
138
|
+
try {
|
|
139
|
+
window.addEventListener("message", listener);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
cleanup();
|
|
143
|
+
reject(new CAMSError(exports.CAMSErrorType.POPUP_BLOCKED, "Failed to set up message listener: " + (error instanceof Error ? error.message : "Unknown error")));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
class TokenManager {
|
|
150
|
+
constructor(storage = sessionStorage, storageKey = "cams_token") {
|
|
151
|
+
this.storage = storage;
|
|
152
|
+
this.token = null;
|
|
153
|
+
this.storageKey = storageKey;
|
|
154
|
+
}
|
|
155
|
+
setToken(token) {
|
|
156
|
+
const parsed = TokenSchema.parse(token);
|
|
157
|
+
this.token = parsed;
|
|
158
|
+
this.storage.setItem(this.storageKey, JSON.stringify(parsed));
|
|
159
|
+
}
|
|
160
|
+
loadToken() {
|
|
161
|
+
if (this.token)
|
|
162
|
+
return this.token;
|
|
163
|
+
const raw = this.storage.getItem(this.storageKey);
|
|
164
|
+
if (!raw)
|
|
165
|
+
return null;
|
|
166
|
+
try {
|
|
167
|
+
const parsed = JSON.parse(raw);
|
|
168
|
+
try {
|
|
169
|
+
this.token = TokenSchema.parse(parsed);
|
|
170
|
+
return this.token;
|
|
171
|
+
}
|
|
172
|
+
catch (validationError) {
|
|
173
|
+
console.warn('Token validation failed:', validationError instanceof Error ? validationError.message : 'Unknown error');
|
|
174
|
+
this.storage.removeItem(this.storageKey);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (parseError) {
|
|
179
|
+
console.warn('Failed to parse stored token JSON:', parseError instanceof Error ? parseError.message : 'Unknown error');
|
|
180
|
+
this.storage.removeItem(this.storageKey);
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
clearToken() {
|
|
185
|
+
this.token = null;
|
|
186
|
+
this.storage.removeItem(this.storageKey);
|
|
187
|
+
}
|
|
188
|
+
getAccessToken() {
|
|
189
|
+
var _a;
|
|
190
|
+
const token = this.loadToken();
|
|
191
|
+
return (_a = token === null || token === void 0 ? void 0 : token.access_token) !== null && _a !== void 0 ? _a : null;
|
|
192
|
+
}
|
|
193
|
+
isExpired() {
|
|
194
|
+
const token = this.loadToken();
|
|
195
|
+
if (!token)
|
|
196
|
+
return true;
|
|
197
|
+
// JWT expiration check if available
|
|
198
|
+
if (token.id_token) {
|
|
199
|
+
try {
|
|
200
|
+
const parts = token.id_token.split(".");
|
|
201
|
+
if (parts.length < 3)
|
|
202
|
+
return true; // Invalid JWT format
|
|
203
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
204
|
+
const exp = payload.exp * 1000;
|
|
205
|
+
return Date.now() > exp;
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.warn('Failed to parse JWT token:', error instanceof Error ? error.message : 'Unknown error');
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Fallback: return true for safety when expiration cannot be determined
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
class CAMSSession {
|
|
218
|
+
constructor(storage = sessionStorage, storageKey, events = {}) {
|
|
219
|
+
this.tokenManager = new TokenManager(storage, storageKey);
|
|
220
|
+
this.events = events;
|
|
221
|
+
}
|
|
222
|
+
async login(config) {
|
|
223
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
224
|
+
try {
|
|
225
|
+
(_b = (_a = this.events).onAuthStart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
226
|
+
let attempts = 0;
|
|
227
|
+
const maxAttempts = ((_c = config.retryAttempts) !== null && _c !== void 0 ? _c : 0) + 1;
|
|
228
|
+
while (attempts < maxAttempts) {
|
|
229
|
+
try {
|
|
230
|
+
const response = await openCAMSPopUpLogin(config);
|
|
231
|
+
(_e = (_d = this.events).onAuthSuccess) === null || _e === void 0 ? void 0 : _e.call(_d, response);
|
|
232
|
+
return response;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
attempts++;
|
|
236
|
+
if (attempts >= maxAttempts || !(error instanceof CAMSError)) {
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
// Only retry on specific error types
|
|
240
|
+
if (![exports.CAMSErrorType.TIMEOUT, exports.CAMSErrorType.POPUP_BLOCKED].includes(error.type)) {
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
throw new CAMSError(exports.CAMSErrorType.MAX_RETRIES_EXCEEDED, 'Max retry attempts exceeded');
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
const camsError = error instanceof CAMSError ? error :
|
|
249
|
+
new CAMSError(exports.CAMSErrorType.USER_CANCELLED, error instanceof Error ? error.message : 'Unknown error');
|
|
250
|
+
(_g = (_f = this.events).onAuthError) === null || _g === void 0 ? void 0 : _g.call(_f, camsError);
|
|
251
|
+
throw camsError;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async logout() {
|
|
255
|
+
this.tokenManager.clearToken();
|
|
256
|
+
}
|
|
257
|
+
isAuthenticated() {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
const token = this.tokenManager.loadToken();
|
|
260
|
+
if (!token)
|
|
261
|
+
return false;
|
|
262
|
+
if (this.tokenManager.isExpired()) {
|
|
263
|
+
(_b = (_a = this.events).onTokenExpired) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
getAccessToken() {
|
|
269
|
+
var _a, _b;
|
|
270
|
+
const token = this.tokenManager.loadToken();
|
|
271
|
+
if (!token)
|
|
272
|
+
return null;
|
|
273
|
+
if (this.tokenManager.isExpired()) {
|
|
274
|
+
(_b = (_a = this.events).onTokenExpired) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
return token.access_token;
|
|
278
|
+
}
|
|
279
|
+
decodeBase64Url(str) {
|
|
280
|
+
// Convert base64url to base64
|
|
281
|
+
str = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
282
|
+
// Add padding if needed
|
|
283
|
+
while (str.length % 4) {
|
|
284
|
+
str += '=';
|
|
285
|
+
}
|
|
286
|
+
return atob(str);
|
|
287
|
+
}
|
|
288
|
+
async getProfile() {
|
|
289
|
+
const storedToken = this.tokenManager.loadToken();
|
|
290
|
+
if (!(storedToken === null || storedToken === void 0 ? void 0 : storedToken.id_token))
|
|
291
|
+
return null;
|
|
292
|
+
try {
|
|
293
|
+
const parts = storedToken.id_token.split('.');
|
|
294
|
+
if (parts.length >= 3) { // JWT has header.payload.signature format
|
|
295
|
+
try {
|
|
296
|
+
const payload = JSON.parse(this.decodeBase64Url(parts[1]));
|
|
297
|
+
return ProfileSchema.parse(payload);
|
|
298
|
+
}
|
|
299
|
+
catch (decodeError) {
|
|
300
|
+
console.warn('Failed to decode JWT payload:', decodeError instanceof Error ? decodeError.message : 'Unknown error');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
console.warn('Failed to extract profile from token:', error instanceof Error ? error.message : 'Unknown error');
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
exports.CAMSError = CAMSError;
|
|
312
|
+
exports.CAMSSession = CAMSSession;
|
|
313
|
+
exports.ErrorMessageSchema = ErrorMessageSchema;
|
|
314
|
+
exports.ProfileSchema = ProfileSchema;
|
|
315
|
+
exports.TokenManager = TokenManager;
|
|
316
|
+
exports.TokenMessageSchema = TokenMessageSchema;
|
|
317
|
+
exports.TokenSchema = TokenSchema;
|
|
318
|
+
exports.URLSchema = URLSchema;
|
|
319
|
+
exports.openCAMSPopUpLogin = openCAMSPopUpLogin;
|
|
320
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/validators.ts","../src/auth.ts","../src/tokenManager.ts","../src/session.ts"],"sourcesContent":["export interface CAMSConfig {\n camsUrl: string;\n allowedOrigin: string;\n windowWidth: number;\n windowHeight: number;\n timeout?: number; // Auth timeout in ms (default: 300000)\n allowedDomains?: string[]; // URL allowlist for security\n storageKey?: string; // Custom storage key\n retryAttempts?: number; // Auto-retry on failure (default: 0)\n}\n\nexport enum CAMSErrorType {\n POPUP_BLOCKED = 'POPUP_BLOCKED',\n TIMEOUT = 'TIMEOUT',\n INVALID_ORIGIN = 'INVALID_ORIGIN',\n USER_CANCELLED = 'USER_CANCELLED',\n INVALID_URL = 'INVALID_URL',\n MAX_RETRIES_EXCEEDED = 'MAX_RETRIES_EXCEEDED'\n}\n\nexport class CAMSError extends Error {\n constructor(public type: CAMSErrorType, message: string) {\n super(message);\n this.name = 'CAMSError';\n }\n}\n\nexport interface CAMSTokenResponse {\n token: string;\n}\n\nexport interface CAMSErrorResponse {\n error: string;\n}\n","import { z } from \"zod\";\n\n// Validate the returned token - Base64 format with minimum 20 chars\nexport const TokenMessageSchema = z.object({\n access_token: z.string().regex(/^[A-Za-z0-9+/]{20,}={0,2}$/, \"Invalid NIBSS CAMS token format\"),\n});\n\nexport type TokenMessage = z.infer<typeof TokenMessageSchema>;\n\nexport const ErrorMessageSchema = z.object({\n error: z.string(),\n});\n\nexport const TokenSchema = z.object({\n access_token: z.string(),\n refresh_token: z.string().optional(),\n expires_in: z.number(), // in seconds\n token_type: z.string().default(\"Bearer\"),\n id_token: z.string().optional(),\n});\n\nexport type Token = z.infer<typeof TokenSchema>;\n\nexport const ProfileSchema = z.object({\n sub: z.string(), // user ID\n name: z.string().optional(),\n email: z.email({ message: \"Invalid email address\" }).optional(),\n given_name: z.string().optional(),\n family_name: z.string().optional(),\n roles: z.array(z.string()).optional(),\n});\n\nexport type Profile = z.infer<typeof ProfileSchema>;\n\n// URL validation schema - only HTTPS for production security\nexport const URLSchema = z.string().url().refine(\n (url) => url.startsWith('https://'),\n { message: \"Only HTTPS URLs are allowed\" }\n);","import { CAMSConfig, CAMSTokenResponse, CAMSError, CAMSErrorType } from \"./types\";\nimport { TokenMessageSchema, ErrorMessageSchema, URLSchema } from \"./validators\";\n\nfunction validateConfig(config: CAMSConfig): void {\n // Validate URL format\n const urlValidation = URLSchema.safeParse(config.camsUrl);\n if (!urlValidation.success) {\n throw new CAMSError(CAMSErrorType.INVALID_URL, 'Invalid CAMS URL format');\n }\n\n // Domain validation is mandatory for security\n if (!config.allowedDomains?.length) {\n throw new CAMSError(CAMSErrorType.INVALID_URL, 'allowedDomains must be specified for security');\n }\n\n const url = new URL(config.camsUrl); // URLSchema already validated this\n const isAllowed = config.allowedDomains.some(domain => \n url.hostname === domain || url.hostname.endsWith('.' + domain)\n );\n if (!isAllowed) {\n throw new CAMSError(CAMSErrorType.INVALID_URL, 'URL not in allowed domains list');\n }\n}\n\nexport function openCAMSPopUpLogin(config: CAMSConfig): Promise<CAMSTokenResponse> {\n return new Promise((resolve, reject) => {\n try {\n validateConfig(config);\n } catch (error) {\n reject(error);\n return;\n }\n\n const { camsUrl, allowedOrigin, windowHeight, windowWidth, timeout = 300000 } = config;\n let authWindow: Window | null;\n let timeoutId: NodeJS.Timeout | null = null;\n let checkClosedInterval: NodeJS.Timeout | null = null;\n \n try {\n authWindow = window.open(\n camsUrl,\n \"NIBSS CAMS Login\",\n `width=${windowWidth},height=${windowHeight}`\n );\n } catch (error) {\n reject(new CAMSError(CAMSErrorType.POPUP_BLOCKED, \"Failed to open authentication window: \" + (error instanceof Error ? error.message : \"Unknown error\")));\n return;\n }\n\n if (!authWindow) {\n reject(new CAMSError(CAMSErrorType.POPUP_BLOCKED, \"Failed to open authentication window. Please allow popups.\"));\n return;\n }\n\n const cleanup = () => {\n window.removeEventListener(\"message\", listener);\n if (timeoutId) clearTimeout(timeoutId);\n if (checkClosedInterval) clearInterval(checkClosedInterval);\n };\n \n const cleanupAndClose = (error?: CAMSError) => {\n cleanup();\n try {\n if (authWindow && !authWindow.closed) {\n authWindow.close();\n }\n } catch {\n // Ignore close errors\n }\n if (error) reject(error);\n };\n\n const listener = (event: MessageEvent) => {\n if (event.origin !== allowedOrigin) {\n // Sanitize origin for logging to prevent log injection\n const sanitizedOrigin = event.origin.replace(/[\\r\\n]/g, '');\n console.warn(\"Blocked message from origin:\", sanitizedOrigin);\n return;\n }\n\n // โ
Validate payload\n const tokenMsg = TokenMessageSchema.safeParse(event.data);\n if (tokenMsg.success) {\n cleanupAndClose();\n resolve({ token: tokenMsg.data.access_token });\n return;\n }\n\n const errorMsg = ErrorMessageSchema.safeParse(event.data);\n if (errorMsg.success) {\n cleanupAndClose(new CAMSError(CAMSErrorType.USER_CANCELLED, \"Authentication failed: \" + errorMsg.data.error));\n return;\n }\n\n cleanupAndClose(new CAMSError(CAMSErrorType.INVALID_ORIGIN, \"Invalid message format\"));\n };\n\n // Timeout handler\n timeoutId = setTimeout(() => {\n cleanupAndClose(new CAMSError(CAMSErrorType.TIMEOUT, `Authentication timeout after ${timeout}ms`));\n }, timeout);\n\n checkClosedInterval = setInterval(() => {\n if (authWindow && authWindow.closed) {\n cleanupAndClose(new CAMSError(CAMSErrorType.USER_CANCELLED, \"Authentication window was closed\"));\n }\n }, 2000); // Reduced polling frequency\n\n try {\n window.addEventListener(\"message\", listener);\n } catch (error) {\n cleanup();\n reject(new CAMSError(CAMSErrorType.POPUP_BLOCKED, \"Failed to set up message listener: \" + (error instanceof Error ? error.message : \"Unknown error\")));\n return;\n }\n });\n}\n","import { Token, TokenSchema } from \"./validators\";\n\nexport class TokenManager {\n private token: Token | null = null;\n private readonly storageKey: string;\n\n constructor(\n private readonly storage: Storage = sessionStorage,\n storageKey: string = \"cams_token\"\n ) {\n this.storageKey = storageKey;\n }\n\n setToken(token: Token) {\n const parsed = TokenSchema.parse(token);\n this.token = parsed;\n this.storage.setItem(this.storageKey, JSON.stringify(parsed));\n }\n\n loadToken(): Token | null {\n if (this.token) return this.token;\n const raw = this.storage.getItem(this.storageKey);\n if (!raw) return null;\n \n try {\n const parsed = JSON.parse(raw);\n try {\n this.token = TokenSchema.parse(parsed);\n return this.token;\n } catch (validationError) {\n console.warn('Token validation failed:', validationError instanceof Error ? validationError.message : 'Unknown error');\n this.storage.removeItem(this.storageKey);\n return null;\n }\n } catch (parseError) {\n console.warn('Failed to parse stored token JSON:', parseError instanceof Error ? parseError.message : 'Unknown error');\n this.storage.removeItem(this.storageKey);\n return null;\n }\n }\n\n clearToken() {\n this.token = null;\n this.storage.removeItem(this.storageKey);\n }\n\n getAccessToken(): string | null {\n const token = this.loadToken();\n return token?.access_token ?? null;\n }\n\n isExpired(): boolean {\n const token = this.loadToken();\n if (!token) return true;\n\n // JWT expiration check if available\n if (token.id_token) {\n try {\n const parts = token.id_token.split(\".\");\n if (parts.length < 3) return true; // Invalid JWT format\n const payload = JSON.parse(atob(parts[1]));\n const exp = payload.exp * 1000;\n return Date.now() > exp;\n } catch (error) {\n console.warn('Failed to parse JWT token:', error instanceof Error ? error.message : 'Unknown error');\n return true;\n }\n }\n\n // Fallback: return true for safety when expiration cannot be determined\n return true;\n }\n}\n","import { CAMSConfig, CAMSTokenResponse, CAMSError, CAMSErrorType } from \"./types\";\nimport { TokenManager } from \"./tokenManager\";\nimport { openCAMSPopUpLogin } from \"./auth\";\nimport { Profile, ProfileSchema } from \"./validators\";\n\nexport interface CAMSEvents {\n onAuthStart?: () => void;\n onAuthSuccess?: (token: CAMSTokenResponse) => void;\n onAuthError?: (error: CAMSError) => void;\n onTokenExpired?: () => void;\n}\n\nexport class CAMSSession {\n private readonly tokenManager: TokenManager;\n private readonly events: CAMSEvents;\n\n constructor(\n storage: Storage = sessionStorage,\n storageKey?: string,\n events: CAMSEvents = {}\n ) {\n this.tokenManager = new TokenManager(storage, storageKey);\n this.events = events;\n }\n\n async login(config: CAMSConfig): Promise<CAMSTokenResponse> {\n try {\n this.events.onAuthStart?.();\n \n let attempts = 0;\n const maxAttempts = (config.retryAttempts ?? 0) + 1;\n \n while (attempts < maxAttempts) {\n try {\n const response = await openCAMSPopUpLogin(config);\n this.events.onAuthSuccess?.(response);\n return response;\n } catch (error) {\n attempts++;\n if (attempts >= maxAttempts || !(error instanceof CAMSError)) {\n throw error;\n }\n // Only retry on specific error types\n if (![CAMSErrorType.TIMEOUT, CAMSErrorType.POPUP_BLOCKED].includes(error.type)) {\n throw error;\n }\n }\n }\n \n throw new CAMSError(CAMSErrorType.MAX_RETRIES_EXCEEDED, 'Max retry attempts exceeded');\n } catch (error) {\n const camsError = error instanceof CAMSError ? error : \n new CAMSError(CAMSErrorType.USER_CANCELLED, error instanceof Error ? error.message : 'Unknown error');\n this.events.onAuthError?.(camsError);\n throw camsError;\n }\n }\n\n async logout(): Promise<void> {\n this.tokenManager.clearToken();\n }\n\n isAuthenticated(): boolean {\n const token = this.tokenManager.loadToken();\n if (!token) return false;\n \n if (this.tokenManager.isExpired()) {\n this.events.onTokenExpired?.();\n return false;\n }\n \n return true;\n }\n\n getAccessToken(): string | null {\n const token = this.tokenManager.loadToken();\n if (!token) return null;\n \n if (this.tokenManager.isExpired()) {\n this.events.onTokenExpired?.();\n return null;\n }\n \n return token.access_token;\n }\n\n private decodeBase64Url(str: string): string {\n // Convert base64url to base64\n str = str.replace(/-/g, '+').replace(/_/g, '/');\n // Add padding if needed\n while (str.length % 4) {\n str += '=';\n }\n return atob(str);\n }\n\n async getProfile(): Promise<Profile | null> {\n const storedToken = this.tokenManager.loadToken();\n if (!storedToken?.id_token) return null;\n\n try {\n const parts = storedToken.id_token.split('.');\n if (parts.length >= 3) { // JWT has header.payload.signature format\n try {\n const payload = JSON.parse(this.decodeBase64Url(parts[1]));\n return ProfileSchema.parse(payload);\n } catch (decodeError) {\n console.warn('Failed to decode JWT payload:', decodeError instanceof Error ? decodeError.message : 'Unknown error');\n }\n }\n } catch (error) {\n console.warn('Failed to extract profile from token:', error instanceof Error ? error.message : 'Unknown error');\n }\n\n return null;\n }\n}"],"names":["CAMSErrorType","z"],"mappings":";;;;AAWYA;AAAZ,CAAA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