@nibssplc/cams-sdk 0.0.1-beta.7 โ 0.0.1-beta.70
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 +91 -87
- package/dist/MFAAuth.d.ts +20 -0
- package/dist/auth.d.ts +18 -3
- package/dist/index.cjs.js +806 -197
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.esm.js +799 -194
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +808 -201
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/Axiosinstance.d.ts +1 -0
- package/dist/lib/DeviceID.d.ts +4 -0
- package/dist/logger.d.ts +19 -0
- package/dist/sessionManager.d.ts +47 -0
- package/dist/types.d.ts +57 -8
- package/dist/validators.d.ts +27 -20
- package/package.json +23 -4
- package/dist/session.d.ts +0 -19
- package/dist/tokenManager.d.ts +0 -12
package/README.md
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nibssplc/cams-sdk
|
|
2
2
|
|
|
3
|
-
Central Authentication Management Service (CAMS) SDK for popup-based authentication with Azure AD
|
|
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
|
|
3
|
+
Central Authentication Management Service (CAMS) SDK for popup-based authentication with Azure AD and custom 2FA.
|
|
14
4
|
|
|
15
5
|
## Installation
|
|
16
6
|
|
|
@@ -18,134 +8,148 @@ Central Authentication Management Service (CAMS) SDK for popup-based authenticat
|
|
|
18
8
|
npm install @nibssplc/cams-sdk
|
|
19
9
|
```
|
|
20
10
|
|
|
21
|
-
##
|
|
11
|
+
## Features
|
|
22
12
|
|
|
23
|
-
|
|
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
|
|
24
22
|
|
|
25
23
|
```typescript
|
|
26
|
-
import {
|
|
24
|
+
import { authenticateWithCAMS, CAMSConfig } from '@nibssplc/cams-sdk';
|
|
27
25
|
|
|
28
26
|
const config: CAMSConfig = {
|
|
29
|
-
camsUrl: 'https://your-cams-
|
|
30
|
-
|
|
27
|
+
camsUrl: 'https://your-cams-url.com',
|
|
28
|
+
messageOrigin: 'https://your-cams-url.com',
|
|
31
29
|
windowWidth: 500,
|
|
32
30
|
windowHeight: 600,
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
authTimeout: 300000, // 5 minutes
|
|
32
|
+
debug: true
|
|
35
33
|
};
|
|
36
34
|
|
|
35
|
+
const appCode = 'your-app-guid';
|
|
36
|
+
|
|
37
37
|
try {
|
|
38
|
-
const
|
|
39
|
-
console.log('
|
|
38
|
+
const result = await authenticateWithCAMS(appCode, config);
|
|
39
|
+
console.log('Authenticated:', result);
|
|
40
40
|
} catch (error) {
|
|
41
41
|
console.error('Authentication failed:', error);
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
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.
|
|
46
66
|
|
|
47
67
|
```typescript
|
|
48
|
-
|
|
68
|
+
function authenticateWithCAMS(
|
|
69
|
+
appCode: string,
|
|
70
|
+
config: CAMSConfig
|
|
71
|
+
): Promise<AuthResult>
|
|
72
|
+
```
|
|
49
73
|
|
|
50
|
-
|
|
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
|
-
};
|
|
74
|
+
### Session Management
|
|
56
75
|
|
|
57
|
-
|
|
76
|
+
```typescript
|
|
77
|
+
import { SessionManager } from '@nibssplc/cams-sdk';
|
|
58
78
|
|
|
59
|
-
|
|
60
|
-
const config = {
|
|
61
|
-
// ... your config
|
|
62
|
-
retryAttempts: 2, // Retry twice on failure
|
|
63
|
-
};
|
|
79
|
+
const sessionManager = new SessionManager(config);
|
|
64
80
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const token = session.getAccessToken();
|
|
71
|
-
const profile = await session.getProfile();
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
// Handle authentication error
|
|
75
|
-
}
|
|
81
|
+
// Check if session is valid
|
|
82
|
+
const isValid = sessionManager.isSessionValid();
|
|
83
|
+
|
|
84
|
+
// Get session data
|
|
85
|
+
const session = sessionManager.getSession();
|
|
76
86
|
|
|
77
|
-
//
|
|
78
|
-
|
|
87
|
+
// Clear session
|
|
88
|
+
sessionManager.clearSession();
|
|
79
89
|
```
|
|
80
90
|
|
|
81
|
-
|
|
91
|
+
### MFA Authentication
|
|
82
92
|
|
|
83
93
|
```typescript
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
storageKey?: string; // Custom storage key
|
|
92
|
-
retryAttempts?: number; // Auto-retry on failure (default: 0)
|
|
93
|
-
}
|
|
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
|
+
});
|
|
94
101
|
```
|
|
95
102
|
|
|
96
103
|
## Error Handling
|
|
97
104
|
|
|
98
|
-
The SDK provides typed errors for better error handling:
|
|
99
|
-
|
|
100
105
|
```typescript
|
|
101
106
|
import { CAMSError, CAMSErrorType } from '@nibssplc/cams-sdk';
|
|
102
107
|
|
|
103
108
|
try {
|
|
104
|
-
await
|
|
109
|
+
await authenticateWithCAMS(appCode, config);
|
|
105
110
|
} catch (error) {
|
|
106
111
|
if (error instanceof CAMSError) {
|
|
107
112
|
switch (error.type) {
|
|
108
113
|
case CAMSErrorType.POPUP_BLOCKED:
|
|
109
|
-
|
|
114
|
+
console.error('Popup was blocked');
|
|
110
115
|
break;
|
|
111
116
|
case CAMSErrorType.TIMEOUT:
|
|
112
|
-
|
|
113
|
-
break;
|
|
114
|
-
case CAMSErrorType.INVALID_URL:
|
|
115
|
-
// Handle invalid URL
|
|
117
|
+
console.error('Authentication timed out');
|
|
116
118
|
break;
|
|
117
119
|
case CAMSErrorType.USER_CANCELLED:
|
|
118
|
-
|
|
120
|
+
console.error('User cancelled authentication');
|
|
119
121
|
break;
|
|
122
|
+
default:
|
|
123
|
+
console.error('Authentication error:', error.message);
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
127
|
```
|
|
124
128
|
|
|
125
|
-
##
|
|
129
|
+
## Types
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
```typescript
|
|
132
|
+
export interface Profile {
|
|
133
|
+
email: string;
|
|
134
|
+
name: string;
|
|
135
|
+
// ... other profile fields
|
|
136
|
+
}
|
|
132
137
|
|
|
133
|
-
|
|
138
|
+
export interface AuthResult {
|
|
139
|
+
success: boolean;
|
|
140
|
+
profile?: Profile;
|
|
141
|
+
token?: string;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
134
144
|
|
|
135
|
-
|
|
136
|
-
# Install dependencies
|
|
137
|
-
npm install
|
|
145
|
+
## React Integration
|
|
138
146
|
|
|
139
|
-
|
|
140
|
-
npm test
|
|
147
|
+
For React applications, use the companion package [@nibssplc/cams-sdk-react](./packages/react/README.md).
|
|
141
148
|
|
|
142
|
-
|
|
143
|
-
npm run build
|
|
149
|
+
## License
|
|
144
150
|
|
|
145
|
-
|
|
146
|
-
npm run lint
|
|
147
|
-
```
|
|
151
|
+
MIT
|
|
148
152
|
|
|
149
|
-
##
|
|
153
|
+
## Author
|
|
150
154
|
|
|
151
|
-
|
|
155
|
+
NIBSS PLC, Caleb Boluwade
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AttestationResult, StandaloneMFARequest, type Credentials, type MFAAuthenticatedResponse, type MFASDKRequest, type UserValidatedResponse } from "./types";
|
|
2
|
+
export interface MFAAuthenticator {
|
|
3
|
+
LoginADCredentials(credentials: Credentials, appCode: string, CredentialsAuthEndpoint: string): Promise<MFAAuthenticatedResponse>;
|
|
4
|
+
VerifyMFAOTP(ValidateRequest: StandaloneMFARequest, MFAEndpoint: string): Promise<MFAAuthenticatedResponse>;
|
|
5
|
+
HandleFIDOLogin(RetrieveAuthChallengeEndpoint: string, AuthChallengeVerifyEndpoint: string, authenticate: (options: PublicKeyCredentialRequestOptions) => Promise<PublicKeyCredential>): Promise<boolean>;
|
|
6
|
+
HandleRegister(RegisterNewChallengeEndpoint: string, RegisterVerify: string, register: (options: PublicKeyCredentialCreationOptions) => Promise<AttestationResult>, data: Record<string, unknown>): Promise<boolean>;
|
|
7
|
+
GetRemainingAttempts(): number;
|
|
8
|
+
ResetUserAttempts(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class CAMSMFAAuthenticator implements MFAAuthenticator {
|
|
11
|
+
private attemptCount;
|
|
12
|
+
private readonly maxAttempts;
|
|
13
|
+
GetUserMFAConfig(config: MFASDKRequest): Promise<UserValidatedResponse>;
|
|
14
|
+
VerifyMFAOTP(ValidateRequest: StandaloneMFARequest, MFAEndpoint: string): Promise<MFAAuthenticatedResponse>;
|
|
15
|
+
LoginADCredentials(credentials: Credentials, CredentialsAuthEndpoint: string): Promise<MFAAuthenticatedResponse>;
|
|
16
|
+
HandleFIDOLogin(RetrieveAuthChallengeEndpoint: string, AuthChallengeVerifyEndpoint: string, authenticate: (options: PublicKeyCredentialRequestOptions) => Promise<PublicKeyCredential>): Promise<boolean>;
|
|
17
|
+
HandleRegister(RegisterNewChallengeEndpoint: string, RegisterVerify: string, register: (options: PublicKeyCredentialCreationOptions) => Promise<AttestationResult>, data: Record<string, unknown>): Promise<boolean>;
|
|
18
|
+
GetRemainingAttempts(): number;
|
|
19
|
+
ResetUserAttempts(): void;
|
|
20
|
+
}
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
import { CAMSConfig
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CAMSConfig } from "./types";
|
|
2
|
+
import { Profile } from "./validators";
|
|
3
|
+
/**
|
|
4
|
+
* Generate a secure random window name to prevent targeting
|
|
5
|
+
*/
|
|
6
|
+
export declare const generateSecureWindowName: () => string;
|
|
7
|
+
/**
|
|
8
|
+
* Detect if current window is a popup to prevent recursive popups
|
|
9
|
+
*/
|
|
10
|
+
export declare const isPopupWindow: () => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Validate configuration and return parsed URL
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateConfig(config: CAMSConfig): URL;
|
|
15
|
+
/**
|
|
16
|
+
* Open CAMS authentication popup and handle the authentication flow
|
|
17
|
+
*/
|
|
18
|
+
export declare function openCAMSPopUpLogin(config: CAMSConfig): Promise<Profile>;
|