@nibssplc/cams-sdk-react 0.0.1-beta.77 → 0.0.1-beta.79

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 ADDED
@@ -0,0 +1,295 @@
1
+ # @nibssplc/cams-sdk-react
2
+
3
+ React hooks and components for NIBSS CAMS SDK with support for both regular CAMS authentication and Azure AD MSAL integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @nibssplc/cams-sdk-react
9
+ ```
10
+
11
+ For MSAL mode, also install:
12
+ ```bash
13
+ npm install @azure/msal-browser @azure/msal-react
14
+ ```
15
+
16
+ ## Features
17
+
18
+ - ⚛️ React hooks for authentication
19
+ - 🔄 Unified provider supporting both REGULAR and MSAL modes
20
+ - 🎨 Pre-built UI components (login page, MFA gate)
21
+ - 🛡️ Protected route component
22
+ - 🎯 TypeScript support
23
+ - 🪝 Context-based state management
24
+ - 📱 Next.js compatible
25
+
26
+ ## Quick Start
27
+
28
+ ### MSAL Mode (Azure AD + MFA)
29
+
30
+ ```tsx
31
+ import { UnifiedCAMSProvider, useCAMSContext } from '@nibssplc/cams-sdk-react';
32
+
33
+ const msalConfig = {
34
+ auth: {
35
+ clientId: 'your-client-id',
36
+ authority: 'https://login.microsoftonline.com/your-tenant-id',
37
+ redirectUri: window.location.origin
38
+ }
39
+ };
40
+
41
+ function App() {
42
+ return (
43
+ <UnifiedCAMSProvider
44
+ mode="MSAL"
45
+ appCode="your-app-guid"
46
+ msalConfig={msalConfig}
47
+ MFAEndpoint="https://your-mfa-endpoint.com"
48
+ >
49
+ <YourApp />
50
+ </UnifiedCAMSProvider>
51
+ );
52
+ }
53
+
54
+ function YourApp() {
55
+ const { login, logout, isAuthenticated, userProfile } = useCAMSContext();
56
+
57
+ return (
58
+ <div>
59
+ {isAuthenticated ? (
60
+ <>
61
+ <p>Welcome, {userProfile?.name}</p>
62
+ <button onClick={logout}>Logout</button>
63
+ </>
64
+ ) : (
65
+ <button onClick={login}>Login</button>
66
+ )}
67
+ </div>
68
+ );
69
+ }
70
+ ```
71
+
72
+ ### REGULAR Mode (Popup Authentication)
73
+
74
+ ```tsx
75
+ import { UnifiedCAMSProvider, useCAMSContext } from '@nibssplc/cams-sdk-react';
76
+
77
+ function App() {
78
+ return (
79
+ <UnifiedCAMSProvider
80
+ mode="REGULAR"
81
+ appCode="your-app-guid"
82
+ camsUrl="https://your-cams-url.com"
83
+ messageOrigin="https://your-cams-url.com"
84
+ windowWidth={500}
85
+ windowHeight={600}
86
+ >
87
+ <YourApp />
88
+ </UnifiedCAMSProvider>
89
+ );
90
+ }
91
+ ```
92
+
93
+ ## Components
94
+
95
+ ### UnifiedCAMSProvider
96
+
97
+ Main provider component supporting both authentication modes.
98
+
99
+ **Props (MSAL Mode):**
100
+ ```tsx
101
+ interface MSALProviderProps {
102
+ mode: "MSAL";
103
+ appCode: string;
104
+ msalConfig: Configuration;
105
+ msalInstance?: PublicClientApplication;
106
+ MFAEndpoint: string;
107
+ children: React.ReactNode;
108
+ }
109
+ ```
110
+
111
+ **Props (REGULAR Mode):**
112
+ ```tsx
113
+ interface RegularProviderProps {
114
+ mode: "REGULAR";
115
+ appCode: string;
116
+ camsUrl: string;
117
+ messageOrigin: string;
118
+ windowWidth: number;
119
+ windowHeight: number;
120
+ authTimeout?: number;
121
+ debug?: boolean;
122
+ children: React.ReactNode;
123
+ }
124
+ ```
125
+
126
+ ### DefaultLoginPage
127
+
128
+ Pre-built login page with Microsoft and AD authentication options.
129
+
130
+ ```tsx
131
+ import { DefaultLoginPage } from '@nibssplc/cams-sdk-react';
132
+
133
+ function App() {
134
+ return (
135
+ <UnifiedCAMSProvider mode="MSAL" {...config}>
136
+ <DefaultLoginPage />
137
+ </UnifiedCAMSProvider>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ### MFAGate
143
+
144
+ Component that enforces MFA completion before rendering children.
145
+
146
+ ```tsx
147
+ import { MFAGate } from '@nibssplc/cams-sdk-react';
148
+
149
+ function ProtectedContent() {
150
+ return (
151
+ <MFAGate>
152
+ <YourProtectedContent />
153
+ </MFAGate>
154
+ );
155
+ }
156
+ ```
157
+
158
+ ### ProtectedRoute
159
+
160
+ Route wrapper that requires authentication.
161
+
162
+ ```tsx
163
+ import { ProtectedRoute } from '@nibssplc/cams-sdk-react';
164
+
165
+ function App() {
166
+ return (
167
+ <ProtectedRoute>
168
+ <YourProtectedPage />
169
+ </ProtectedRoute>
170
+ );
171
+ }
172
+ ```
173
+
174
+ ## Hooks
175
+
176
+ ### useCAMSContext
177
+
178
+ Access authentication state and methods.
179
+
180
+ ```tsx
181
+ import { useCAMSContext } from '@nibssplc/cams-sdk-react';
182
+
183
+ function MyComponent() {
184
+ const {
185
+ isAuthenticated,
186
+ isLoading,
187
+ userProfile,
188
+ login,
189
+ logout,
190
+ error,
191
+ authMode
192
+ } = useCAMSContext();
193
+
194
+ return (
195
+ <div>
196
+ {isAuthenticated && <p>Hello, {userProfile?.name}</p>}
197
+ </div>
198
+ );
199
+ }
200
+ ```
201
+
202
+ **Return Values:**
203
+
204
+ | Property | Type | Description |
205
+ |----------|------|-------------|
206
+ | `isAuthenticated` | boolean | Authentication status |
207
+ | `isLoading` | boolean | Loading state |
208
+ | `userProfile` | Profile \| null | User profile data |
209
+ | `login` | function | Trigger login flow |
210
+ | `logout` | function | Logout user |
211
+ | `error` | Error \| null | Authentication error |
212
+ | `authMode` | 'REGULAR' \| 'MSAL' | Current auth mode |
213
+ | `requiresMFA` | boolean | MFA required (MSAL only) |
214
+
215
+ ### useCAMSAuth
216
+
217
+ Hook for REGULAR mode authentication.
218
+
219
+ ```tsx
220
+ import { useCAMSAuth } from '@nibssplc/cams-sdk-react';
221
+
222
+ const auth = useCAMSAuth({
223
+ appCode: 'your-app-guid',
224
+ camsUrl: 'https://your-cams-url.com',
225
+ messageOrigin: 'https://your-cams-url.com',
226
+ windowWidth: 500,
227
+ windowHeight: 600
228
+ });
229
+ ```
230
+
231
+ ### useCAMSMSALAuth
232
+
233
+ Hook for MSAL mode authentication.
234
+
235
+ ```tsx
236
+ import { useCAMSMSALAuth } from '@nibssplc/cams-sdk-react';
237
+
238
+ const auth = useCAMSMSALAuth({
239
+ appCode: 'your-app-guid',
240
+ MFAEndpoint: 'https://your-mfa-endpoint.com'
241
+ });
242
+ ```
243
+
244
+ ## Next.js Integration
245
+
246
+ ```tsx
247
+ // app/providers.tsx
248
+ 'use client';
249
+
250
+ import { UnifiedCAMSProvider } from '@nibssplc/cams-sdk-react';
251
+
252
+ export function Providers({ children }: { children: React.ReactNode }) {
253
+ return (
254
+ <UnifiedCAMSProvider mode="MSAL" {...config}>
255
+ {children}
256
+ </UnifiedCAMSProvider>
257
+ );
258
+ }
259
+
260
+ // app/layout.tsx
261
+ import { Providers } from './providers';
262
+
263
+ export default function RootLayout({ children }) {
264
+ return (
265
+ <html>
266
+ <body>
267
+ <Providers>{children}</Providers>
268
+ </body>
269
+ </html>
270
+ );
271
+ }
272
+ ```
273
+
274
+ ## Styling
275
+
276
+ Components use Tailwind CSS. Ensure Tailwind is configured in your project:
277
+
278
+ ```bash
279
+ npm install -D tailwindcss
280
+ npx tailwindcss init
281
+ ```
282
+
283
+ ## Examples
284
+
285
+ See the [examples](../../examples) directory for complete implementations:
286
+ - `integrated-mfa-example.tsx` - MSAL mode with MFA
287
+ - `popup-auth-example.tsx` - Regular popup authentication
288
+
289
+ ## License
290
+
291
+ MIT
292
+
293
+ ## Author
294
+
295
+ NIBSS PLC, Caleb Boluwade
@@ -0,0 +1,7 @@
1
+ interface ADLoginModalProps {
2
+ open: boolean;
3
+ onOpenChange: (open: boolean) => void;
4
+ onLogin: (username: string, password: string, mfaCode: string) => Promise<void>;
5
+ }
6
+ export declare const ADLoginModal: ({ open, onOpenChange, onLogin }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -3,5 +3,5 @@ interface MFAOptionsProps {
3
3
  onAuthFailed?: () => void;
4
4
  MFAEndpoint?: string;
5
5
  }
6
- declare const MFAOptions: ({ onComplete, onAuthFailed, MFAEndpoint }?: MFAOptionsProps) => import("react/jsx-runtime").JSX.Element;
6
+ declare const MFAOptions: ({ onComplete, onAuthFailed, MFAEndpoint, }?: MFAOptionsProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export default MFAOptions;
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
3
+ }
4
+ declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
5
+ export { Input };
@@ -7,6 +7,7 @@ export interface UseCAMSAuthOptions {
7
7
  onTokenExpired?: () => void;
8
8
  autoClose?: boolean;
9
9
  idleTimeout?: number;
10
+ loginExpiry?: number;
10
11
  }
11
12
  export interface UseCAMSAuthReturn {
12
13
  login: (config: CAMSConfig) => Promise<void>;
@@ -18,5 +19,6 @@ export interface UseCAMSAuthReturn {
18
19
  profile: Profile | null;
19
20
  appCode: string;
20
21
  storageKey: string;
22
+ loginExpiry: number;
21
23
  }
22
24
  export declare function useCAMSAuth(options?: UseCAMSAuthOptions): UseCAMSAuthReturn;