@nibssplc/cams-sdk 0.0.1-beta.36 → 0.0.1-beta.38
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 +155 -0
- package/dist/auth.d.ts +12 -2
- package/dist/index.cjs.js +253 -270
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.esm.js +254 -265
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +253 -270
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -1
- package/dist/popupAuth.d.ts +0 -20
- /package/dist/{mfaAuth.d.ts → MFAAuth.d.ts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @nibssplc/cams-sdk
|
|
2
|
+
|
|
3
|
+
Central Authentication Management Service (CAMS) SDK for popup-based authentication with Azure AD and custom 2FA.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nibssplc/cams-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🔐 Popup-based authentication flow
|
|
14
|
+
- 🛡️ Built-in 2FA/MFA support
|
|
15
|
+
- 📦 Session management with automatic timeout
|
|
16
|
+
- 🔄 Retry mechanism for failed authentications
|
|
17
|
+
- 🎯 TypeScript support
|
|
18
|
+
- ✅ Input validation with Zod
|
|
19
|
+
- 🪵 Debug logging capabilities
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { authenticateWithCAMS, CAMSConfig } from '@nibssplc/cams-sdk';
|
|
25
|
+
|
|
26
|
+
const config: CAMSConfig = {
|
|
27
|
+
camsUrl: 'https://your-cams-url.com',
|
|
28
|
+
messageOrigin: 'https://your-cams-url.com',
|
|
29
|
+
windowWidth: 500,
|
|
30
|
+
windowHeight: 600,
|
|
31
|
+
authTimeout: 300000, // 5 minutes
|
|
32
|
+
debug: true
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const appCode = 'your-app-guid';
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const result = await authenticateWithCAMS(appCode, config);
|
|
39
|
+
console.log('Authenticated:', result);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error('Authentication failed:', error);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
### CAMSConfig
|
|
48
|
+
|
|
49
|
+
| Property | Type | Required | Default | Description |
|
|
50
|
+
|----------|------|----------|---------|-------------|
|
|
51
|
+
| `camsUrl` | string | Yes | - | CAMS authentication URL |
|
|
52
|
+
| `messageOrigin` | string | Yes | - | Expected message origin for security |
|
|
53
|
+
| `windowWidth` | number | Yes | - | Popup window width |
|
|
54
|
+
| `windowHeight` | number | Yes | - | Popup window height |
|
|
55
|
+
| `authTimeout` | number | No | 300000 | Authentication timeout (ms) |
|
|
56
|
+
| `idleTimeout` | number | No | 60000 | Idle timeout (ms) |
|
|
57
|
+
| `storageKey` | string | No | 'cams-session' | Custom storage key |
|
|
58
|
+
| `retryAttempts` | number | No | 0 | Auto-retry on failure |
|
|
59
|
+
| `debug` | boolean | No | false | Enable debug logging |
|
|
60
|
+
|
|
61
|
+
## API Reference
|
|
62
|
+
|
|
63
|
+
### authenticateWithCAMS
|
|
64
|
+
|
|
65
|
+
Main authentication function that opens a popup and handles the authentication flow.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
function authenticateWithCAMS(
|
|
69
|
+
appCode: string,
|
|
70
|
+
config: CAMSConfig
|
|
71
|
+
): Promise<AuthResult>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Session Management
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { SessionManager } from '@nibssplc/cams-sdk';
|
|
78
|
+
|
|
79
|
+
const sessionManager = new SessionManager(config);
|
|
80
|
+
|
|
81
|
+
// Check if session is valid
|
|
82
|
+
const isValid = sessionManager.isSessionValid();
|
|
83
|
+
|
|
84
|
+
// Get session data
|
|
85
|
+
const session = sessionManager.getSession();
|
|
86
|
+
|
|
87
|
+
// Clear session
|
|
88
|
+
sessionManager.clearSession();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### MFA Authentication
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { authenticateWithMFA } from '@nibssplc/cams-sdk';
|
|
95
|
+
|
|
96
|
+
const result = await authenticateWithMFA({
|
|
97
|
+
appCode: 'your-app-guid',
|
|
98
|
+
MFAEndpoint: 'https://your-mfa-endpoint.com',
|
|
99
|
+
accessToken: 'user-access-token'
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Error Handling
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { CAMSError, CAMSErrorType } from '@nibssplc/cams-sdk';
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
await authenticateWithCAMS(appCode, config);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error instanceof CAMSError) {
|
|
112
|
+
switch (error.type) {
|
|
113
|
+
case CAMSErrorType.POPUP_BLOCKED:
|
|
114
|
+
console.error('Popup was blocked');
|
|
115
|
+
break;
|
|
116
|
+
case CAMSErrorType.TIMEOUT:
|
|
117
|
+
console.error('Authentication timed out');
|
|
118
|
+
break;
|
|
119
|
+
case CAMSErrorType.USER_CANCELLED:
|
|
120
|
+
console.error('User cancelled authentication');
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
console.error('Authentication error:', error.message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Types
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
export interface Profile {
|
|
133
|
+
email: string;
|
|
134
|
+
name: string;
|
|
135
|
+
// ... other profile fields
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface AuthResult {
|
|
139
|
+
success: boolean;
|
|
140
|
+
profile?: Profile;
|
|
141
|
+
token?: string;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## React Integration
|
|
146
|
+
|
|
147
|
+
For React applications, use the companion package [@nibssplc/cams-sdk-react](./packages/react/README.md).
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT
|
|
152
|
+
|
|
153
|
+
## Author
|
|
154
|
+
|
|
155
|
+
NIBSS PLC, Caleb Boluwade
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { CAMSConfig } from "./types";
|
|
2
2
|
import { Profile } from "./validators";
|
|
3
|
+
/**
|
|
4
|
+
* Generate a secure random window name to prevent targeting
|
|
5
|
+
*/
|
|
3
6
|
export declare const generateSecureWindowName: () => string;
|
|
7
|
+
/**
|
|
8
|
+
* Detect if current window is a popup to prevent recursive popups
|
|
9
|
+
*/
|
|
4
10
|
export declare const isPopupWindow: () => boolean;
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Validate configuration and return parsed URL
|
|
13
|
+
*/
|
|
7
14
|
export declare function validateConfig(config: CAMSConfig): URL;
|
|
15
|
+
/**
|
|
16
|
+
* Open CAMS authentication popup and handle the authentication flow
|
|
17
|
+
*/
|
|
8
18
|
export declare function openCAMSPopUpLogin(config: CAMSConfig): Promise<Profile>;
|