@nibssplc/cams-sdk 0.0.1-beta.7 โ†’ 0.0.1-beta.71

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,148 @@ 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
+
21
+ ## Quick Start
24
22
 
25
23
  ```typescript
26
- import { openCAMSLogin, CAMSConfig } from '@nibssplc/cams-sdk';
24
+ import { authenticateWithCAMS, CAMSConfig } from '@nibssplc/cams-sdk';
27
25
 
28
26
  const config: CAMSConfig = {
29
- camsUrl: 'https://your-cams-instance.com/auth',
30
- allowedOrigin: 'https://your-cams-instance.com',
27
+ camsUrl: 'https://your-cams-url.com',
28
+ messageOrigin: 'https://your-cams-url.com',
31
29
  windowWidth: 500,
32
30
  windowHeight: 600,
33
- timeout: 300000, // 5 minutes
34
- allowedDomains: ['your-cams-instance.com'], // Security allowlist
31
+ authTimeout: 300000, // 5 minutes
32
+ debug: true
35
33
  };
36
34
 
35
+ const appCode = 'your-app-guid';
36
+
37
37
  try {
38
- const response = await openCAMSPopUpLogin(config);
39
- console.log('Authentication successful:', response.token);
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
- ### Session Management (Recommended)
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
- import { CAMSSession, CAMSEvents } from '@nibssplc/cams-sdk';
68
+ function authenticateWithCAMS(
69
+ appCode: string,
70
+ config: CAMSConfig
71
+ ): Promise<AuthResult>
72
+ ```
49
73
 
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
- };
74
+ ### Session Management
56
75
 
57
- const session = new CAMSSession(sessionStorage, 'my_app_token', events);
76
+ ```typescript
77
+ import { SessionManager } from '@nibssplc/cams-sdk';
58
78
 
59
- // Login with retry logic
60
- const config = {
61
- // ... your config
62
- retryAttempts: 2, // Retry twice on failure
63
- };
79
+ const sessionManager = new SessionManager(config);
64
80
 
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
- }
81
+ // Check if session is valid
82
+ const isValid = sessionManager.isSessionValid();
83
+
84
+ // Get session data
85
+ const session = sessionManager.getSession();
76
86
 
77
- // Logout
78
- await session.logout();
87
+ // Clear session
88
+ sessionManager.clearSession();
79
89
  ```
80
90
 
81
- ## Configuration Options
91
+ ### MFA Authentication
82
92
 
83
93
  ```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
+ 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 session.login(config);
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
- // Handle popup blocker
114
+ console.error('Popup was blocked');
110
115
  break;
111
116
  case CAMSErrorType.TIMEOUT:
112
- // Handle timeout
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
- // Handle user cancellation
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
- ## Security Features
129
+ ## Types
126
130
 
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
131
+ ```typescript
132
+ export interface Profile {
133
+ email: string;
134
+ name: string;
135
+ // ... other profile fields
136
+ }
132
137
 
133
- ## Development
138
+ export interface AuthResult {
139
+ success: boolean;
140
+ profile?: Profile;
141
+ token?: string;
142
+ }
143
+ ```
134
144
 
135
- ```bash
136
- # Install dependencies
137
- npm install
145
+ ## React Integration
138
146
 
139
- # Run tests
140
- npm test
147
+ For React applications, use the companion package [@nibssplc/cams-sdk-react](./packages/react/README.md).
141
148
 
142
- # Build
143
- npm run build
149
+ ## License
144
150
 
145
- # Lint
146
- npm run lint
147
- ```
151
+ MIT
148
152
 
149
- ## License
153
+ ## Author
150
154
 
151
- MIT ยฉ NIBSS PLC
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, 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>;