@nibssplc/cams-sdk 0.0.1-beta.9 โ 0.0.1-beta.90
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 +111 -87
- package/dist/MFAAuth.d.ts +26 -0
- package/dist/__tests__/validators.authState.test.d.ts +1 -0
- package/dist/auth.d.ts +18 -3
- package/dist/index.cjs.js +987 -197
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +974 -194
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +989 -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/lib/WebAuthnUtils.d.ts +27 -0
- package/dist/logger.d.ts +19 -0
- package/dist/sessionManager.d.ts +47 -0
- package/dist/tracing.d.ts +6 -0
- package/dist/types.d.ts +73 -8
- package/dist/validators.d.ts +39 -19
- package/package.json +24 -5
- 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,168 @@ 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
|
+
- ๐ OpenTelemetry tracing support
|
|
21
|
+
|
|
22
|
+
## OpenTelemetry tracing
|
|
23
|
+
|
|
24
|
+
The SDK creates OpenTelemetry spans for popup authentication and outbound MFA
|
|
25
|
+
HTTP requests. It uses `@opentelemetry/api` only: it does not initialize a
|
|
26
|
+
tracer provider, exporter, metrics, or OpenTelemetry logging. Configure a
|
|
27
|
+
tracing provider and exporter in the host application to collect these spans.
|
|
28
|
+
|
|
29
|
+
Spans include the service name `NIBSS-CENTRAL-AUTH-SDK` and W3C trace context is
|
|
30
|
+
propagated on outbound HTTP requests when the host configures a propagator.
|
|
31
|
+
Request URLs, headers, and bodies are not added as span attributes.
|
|
32
|
+
|
|
33
|
+
The React, Angular, and Vue integrations also create spans around their login,
|
|
34
|
+
logout, and MFA verification actions. If the host application does not register
|
|
35
|
+
an OpenTelemetry tracer provider, the API's default no-op implementation makes
|
|
36
|
+
these spans inert: authentication works as usual, but nothing is recorded or
|
|
37
|
+
exported and trace context is not propagated. To collect traces, configure a
|
|
38
|
+
provider, exporter, and propagator in the host application; a context manager is
|
|
39
|
+
also needed to preserve parent-child relationships across async operations.
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
24
42
|
|
|
25
43
|
```typescript
|
|
26
|
-
import {
|
|
44
|
+
import { authenticateWithCAMS, CAMSConfig } from '@nibssplc/cams-sdk';
|
|
27
45
|
|
|
28
46
|
const config: CAMSConfig = {
|
|
29
|
-
camsUrl: 'https://your-cams-
|
|
30
|
-
|
|
47
|
+
camsUrl: 'https://your-cams-url.com',
|
|
48
|
+
messageOrigin: 'https://your-cams-url.com',
|
|
31
49
|
windowWidth: 500,
|
|
32
50
|
windowHeight: 600,
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
authTimeout: 300000, // 5 minutes
|
|
52
|
+
debug: true
|
|
35
53
|
};
|
|
36
54
|
|
|
55
|
+
const appCode = 'your-app-guid';
|
|
56
|
+
|
|
37
57
|
try {
|
|
38
|
-
const
|
|
39
|
-
console.log('
|
|
58
|
+
const result = await authenticateWithCAMS(appCode, config);
|
|
59
|
+
console.log('Authenticated:', result);
|
|
40
60
|
} catch (error) {
|
|
41
61
|
console.error('Authentication failed:', error);
|
|
42
62
|
}
|
|
43
63
|
```
|
|
44
64
|
|
|
45
|
-
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
### CAMSConfig
|
|
68
|
+
|
|
69
|
+
| Property | Type | Required | Default | Description |
|
|
70
|
+
|----------|------|----------|---------|-------------|
|
|
71
|
+
| `camsUrl` | string | Yes | - | CAMS authentication URL |
|
|
72
|
+
| `messageOrigin` | string | Yes | - | Expected message origin for security |
|
|
73
|
+
| `windowWidth` | number | Yes | - | Popup window width |
|
|
74
|
+
| `windowHeight` | number | Yes | - | Popup window height |
|
|
75
|
+
| `authTimeout` | number | No | 300000 | Authentication timeout (ms) |
|
|
76
|
+
| `idleTimeout` | number | No | 60000 | Idle timeout (ms) |
|
|
77
|
+
| `storageKey` | string | No | 'cams-session' | Custom storage key |
|
|
78
|
+
| `retryAttempts` | number | No | 0 | Auto-retry on failure |
|
|
79
|
+
| `debug` | boolean | No | false | Enable debug logging |
|
|
80
|
+
|
|
81
|
+
## API Reference
|
|
82
|
+
|
|
83
|
+
### authenticateWithCAMS
|
|
84
|
+
|
|
85
|
+
Main authentication function that opens a popup and handles the authentication flow.
|
|
46
86
|
|
|
47
87
|
```typescript
|
|
48
|
-
|
|
88
|
+
function authenticateWithCAMS(
|
|
89
|
+
appCode: string,
|
|
90
|
+
config: CAMSConfig
|
|
91
|
+
): Promise<AuthResult>
|
|
92
|
+
```
|
|
49
93
|
|
|
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
|
-
};
|
|
94
|
+
### Session Management
|
|
56
95
|
|
|
57
|
-
|
|
96
|
+
```typescript
|
|
97
|
+
import { SessionManager } from '@nibssplc/cams-sdk';
|
|
58
98
|
|
|
59
|
-
|
|
60
|
-
const config = {
|
|
61
|
-
// ... your config
|
|
62
|
-
retryAttempts: 2, // Retry twice on failure
|
|
63
|
-
};
|
|
99
|
+
const sessionManager = new SessionManager(config);
|
|
64
100
|
|
|
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
|
-
}
|
|
101
|
+
// Check if session is valid
|
|
102
|
+
const isValid = sessionManager.isSessionValid();
|
|
103
|
+
|
|
104
|
+
// Get session data
|
|
105
|
+
const session = sessionManager.getSession();
|
|
76
106
|
|
|
77
|
-
//
|
|
78
|
-
|
|
107
|
+
// Clear session
|
|
108
|
+
sessionManager.clearSession();
|
|
79
109
|
```
|
|
80
110
|
|
|
81
|
-
|
|
111
|
+
### MFA Authentication
|
|
82
112
|
|
|
83
113
|
```typescript
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
storageKey?: string; // Custom storage key
|
|
92
|
-
retryAttempts?: number; // Auto-retry on failure (default: 0)
|
|
93
|
-
}
|
|
114
|
+
import { authenticateWithMFA } from '@nibssplc/cams-sdk';
|
|
115
|
+
|
|
116
|
+
const result = await authenticateWithMFA({
|
|
117
|
+
appCode: 'your-app-guid',
|
|
118
|
+
MFAEndpoint: 'https://your-mfa-endpoint.com',
|
|
119
|
+
accessToken: 'user-access-token'
|
|
120
|
+
});
|
|
94
121
|
```
|
|
95
122
|
|
|
96
123
|
## Error Handling
|
|
97
124
|
|
|
98
|
-
The SDK provides typed errors for better error handling:
|
|
99
|
-
|
|
100
125
|
```typescript
|
|
101
126
|
import { CAMSError, CAMSErrorType } from '@nibssplc/cams-sdk';
|
|
102
127
|
|
|
103
128
|
try {
|
|
104
|
-
await
|
|
129
|
+
await authenticateWithCAMS(appCode, config);
|
|
105
130
|
} catch (error) {
|
|
106
131
|
if (error instanceof CAMSError) {
|
|
107
132
|
switch (error.type) {
|
|
108
133
|
case CAMSErrorType.POPUP_BLOCKED:
|
|
109
|
-
|
|
134
|
+
console.error('Popup was blocked');
|
|
110
135
|
break;
|
|
111
136
|
case CAMSErrorType.TIMEOUT:
|
|
112
|
-
|
|
113
|
-
break;
|
|
114
|
-
case CAMSErrorType.INVALID_URL:
|
|
115
|
-
// Handle invalid URL
|
|
137
|
+
console.error('Authentication timed out');
|
|
116
138
|
break;
|
|
117
139
|
case CAMSErrorType.USER_CANCELLED:
|
|
118
|
-
|
|
140
|
+
console.error('User cancelled authentication');
|
|
119
141
|
break;
|
|
142
|
+
default:
|
|
143
|
+
console.error('Authentication error:', error.message);
|
|
120
144
|
}
|
|
121
145
|
}
|
|
122
146
|
}
|
|
123
147
|
```
|
|
124
148
|
|
|
125
|
-
##
|
|
149
|
+
## Types
|
|
126
150
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
151
|
+
```typescript
|
|
152
|
+
export interface Profile {
|
|
153
|
+
email: string;
|
|
154
|
+
name: string;
|
|
155
|
+
// ... other profile fields
|
|
156
|
+
}
|
|
132
157
|
|
|
133
|
-
|
|
158
|
+
export interface AuthResult {
|
|
159
|
+
success: boolean;
|
|
160
|
+
profile?: Profile;
|
|
161
|
+
token?: string;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
134
164
|
|
|
135
|
-
|
|
136
|
-
# Install dependencies
|
|
137
|
-
npm install
|
|
165
|
+
## React Integration
|
|
138
166
|
|
|
139
|
-
|
|
140
|
-
npm test
|
|
167
|
+
For React applications, use the companion package [@nibssplc/cams-sdk-react](./packages/react/README.md).
|
|
141
168
|
|
|
142
|
-
|
|
143
|
-
npm run build
|
|
169
|
+
## License
|
|
144
170
|
|
|
145
|
-
|
|
146
|
-
npm run lint
|
|
147
|
-
```
|
|
171
|
+
MIT
|
|
148
172
|
|
|
149
|
-
##
|
|
173
|
+
## Author
|
|
150
174
|
|
|
151
|
-
|
|
175
|
+
NIBSS PLC, Caleb Boluwade
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { 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, email: string): Promise<boolean>;
|
|
6
|
+
HandleRegister(RegisterNewChallengeEndpoint: string, RegisterVerifyEndpoint: string, data: {
|
|
7
|
+
email: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
}): Promise<boolean>;
|
|
10
|
+
GetRemainingAttempts(): number;
|
|
11
|
+
ResetUserAttempts(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class CAMSMFAAuthenticator implements MFAAuthenticator {
|
|
14
|
+
private attemptCount;
|
|
15
|
+
private readonly maxAttempts;
|
|
16
|
+
GetUserMFAConfig(config: MFASDKRequest): Promise<UserValidatedResponse>;
|
|
17
|
+
VerifyMFAOTP(ValidateRequest: StandaloneMFARequest, MFAEndpoint: string): Promise<MFAAuthenticatedResponse>;
|
|
18
|
+
LoginADCredentials(credentials: Credentials, CredentialsAuthEndpoint: string): Promise<MFAAuthenticatedResponse>;
|
|
19
|
+
HandleFIDOLogin(RetrieveAuthChallengeEndpoint: string, AuthChallengeVerifyEndpoint: string, email: string): Promise<boolean>;
|
|
20
|
+
HandleRegister(RegisterNewChallengeEndpoint: string, RegisterVerifyEndpoint: string, data: {
|
|
21
|
+
email: string;
|
|
22
|
+
displayName: string;
|
|
23
|
+
}): Promise<boolean>;
|
|
24
|
+
GetRemainingAttempts(): number;
|
|
25
|
+
ResetUserAttempts(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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>;
|