@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 CHANGED
@@ -1,16 +1,6 @@
1
- # NIBSS CAMS SDK
1
+ # @nibssplc/cams-sdk
2
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
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
- ## Quick Start
11
+ ## Features
22
12
 
23
- ### Basic Usage
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 { openCAMSLogin, CAMSConfig } from '@nibssplc/cams-sdk';
44
+ import { authenticateWithCAMS, CAMSConfig } from '@nibssplc/cams-sdk';
27
45
 
28
46
  const config: CAMSConfig = {
29
- camsUrl: 'https://your-cams-instance.com/auth',
30
- allowedOrigin: 'https://your-cams-instance.com',
47
+ camsUrl: 'https://your-cams-url.com',
48
+ messageOrigin: 'https://your-cams-url.com',
31
49
  windowWidth: 500,
32
50
  windowHeight: 600,
33
- timeout: 300000, // 5 minutes
34
- allowedDomains: ['your-cams-instance.com'], // Security allowlist
51
+ authTimeout: 300000, // 5 minutes
52
+ debug: true
35
53
  };
36
54
 
55
+ const appCode = 'your-app-guid';
56
+
37
57
  try {
38
- const response = await openCAMSPopUpLogin(config);
39
- console.log('Authentication successful:', response.token);
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
- ### Session Management (Recommended)
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
- import { CAMSSession, CAMSEvents } from '@nibssplc/cams-sdk';
88
+ function authenticateWithCAMS(
89
+ appCode: string,
90
+ config: CAMSConfig
91
+ ): Promise<AuthResult>
92
+ ```
49
93
 
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
- };
94
+ ### Session Management
56
95
 
57
- const session = new CAMSSession(sessionStorage, 'my_app_token', events);
96
+ ```typescript
97
+ import { SessionManager } from '@nibssplc/cams-sdk';
58
98
 
59
- // Login with retry logic
60
- const config = {
61
- // ... your config
62
- retryAttempts: 2, // Retry twice on failure
63
- };
99
+ const sessionManager = new SessionManager(config);
64
100
 
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
- }
101
+ // Check if session is valid
102
+ const isValid = sessionManager.isSessionValid();
103
+
104
+ // Get session data
105
+ const session = sessionManager.getSession();
76
106
 
77
- // Logout
78
- await session.logout();
107
+ // Clear session
108
+ sessionManager.clearSession();
79
109
  ```
80
110
 
81
- ## Configuration Options
111
+ ### MFA Authentication
82
112
 
83
113
  ```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
- }
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 session.login(config);
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
- // Handle popup blocker
134
+ console.error('Popup was blocked');
110
135
  break;
111
136
  case CAMSErrorType.TIMEOUT:
112
- // Handle timeout
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
- // Handle user cancellation
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
- ## Security Features
149
+ ## Types
126
150
 
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
151
+ ```typescript
152
+ export interface Profile {
153
+ email: string;
154
+ name: string;
155
+ // ... other profile fields
156
+ }
132
157
 
133
- ## Development
158
+ export interface AuthResult {
159
+ success: boolean;
160
+ profile?: Profile;
161
+ token?: string;
162
+ }
163
+ ```
134
164
 
135
- ```bash
136
- # Install dependencies
137
- npm install
165
+ ## React Integration
138
166
 
139
- # Run tests
140
- npm test
167
+ For React applications, use the companion package [@nibssplc/cams-sdk-react](./packages/react/README.md).
141
168
 
142
- # Build
143
- npm run build
169
+ ## License
144
170
 
145
- # Lint
146
- npm run lint
147
- ```
171
+ MIT
148
172
 
149
- ## License
173
+ ## Author
150
174
 
151
- MIT ยฉ NIBSS PLC
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, CAMSTokenResponse } from "./types";
2
- export declare function validateConfig(config: CAMSConfig): void;
3
- export declare function openCAMSPopUpLogin(config: CAMSConfig): Promise<CAMSTokenResponse>;
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>;