@nauth-toolkit/client-angular 0.1.56 → 0.1.58
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/esm2022/lib/auth.guard.mjs +83 -0
- package/esm2022/lib/auth.interceptor.mjs +158 -0
- package/esm2022/lib/social-redirect-callback.guard.mjs +81 -0
- package/esm2022/nauth-toolkit-client-angular.mjs +5 -0
- package/esm2022/ngmodule/auth.interceptor.class.mjs +109 -0
- package/esm2022/ngmodule/auth.service.mjs +777 -0
- package/esm2022/ngmodule/http-adapter.mjs +127 -0
- package/esm2022/ngmodule/nauth.module.mjs +65 -0
- package/esm2022/ngmodule/tokens.mjs +6 -0
- package/esm2022/public-api.mjs +19 -0
- package/esm2022/src/standalone/nauth-toolkit-client-angular-src-standalone.mjs +5 -0
- package/esm2022/src/standalone/public-api.mjs +12 -0
- package/esm2022/standalone/auth.guard.mjs +83 -0
- package/esm2022/standalone/auth.interceptor.mjs +158 -0
- package/esm2022/standalone/auth.service.mjs +777 -0
- package/esm2022/standalone/http-adapter.mjs +127 -0
- package/esm2022/standalone/nauth-toolkit-client-angular-standalone.mjs +5 -0
- package/esm2022/standalone/public-api.mjs +16 -0
- package/esm2022/standalone/social-redirect-callback.guard.mjs +81 -0
- package/esm2022/standalone/tokens.mjs +6 -0
- package/fesm2022/nauth-toolkit-client-angular-src-standalone.mjs +17 -0
- package/fesm2022/nauth-toolkit-client-angular-src-standalone.mjs.map +1 -0
- package/fesm2022/nauth-toolkit-client-angular-standalone.mjs +1229 -0
- package/fesm2022/nauth-toolkit-client-angular-standalone.mjs.map +1 -0
- package/fesm2022/nauth-toolkit-client-angular.mjs +1390 -0
- package/fesm2022/nauth-toolkit-client-angular.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/{src/lib/auth.guard.ts → lib/auth.guard.d.ts} +15 -37
- package/lib/auth.interceptor.d.ts +15 -0
- package/lib/social-redirect-callback.guard.d.ts +25 -0
- package/ngmodule/auth.interceptor.class.d.ts +34 -0
- package/ngmodule/auth.service.d.ts +580 -0
- package/ngmodule/http-adapter.d.ts +53 -0
- package/ngmodule/nauth.module.d.ts +31 -0
- package/{src/ngmodule/tokens.ts → ngmodule/tokens.d.ts} +1 -2
- package/package.json +30 -20
- package/{src/public-api.ts → public-api.d.ts} +0 -6
- package/src/standalone/index.d.ts +5 -0
- package/src/standalone/{public-api.ts → public-api.d.ts} +0 -2
- package/standalone/{auth.guard.ts → auth.guard.d.ts} +15 -37
- package/standalone/auth.interceptor.d.ts +15 -0
- package/standalone/auth.service.d.ts +580 -0
- package/standalone/http-adapter.d.ts +53 -0
- package/standalone/index.d.ts +5 -0
- package/standalone/{public-api.ts → public-api.d.ts} +1 -6
- package/standalone/social-redirect-callback.guard.d.ts +25 -0
- package/standalone/{tokens.ts → tokens.d.ts} +1 -2
- package/ng-package.json +0 -12
- package/src/lib/auth.interceptor.ts +0 -194
- package/src/lib/social-redirect-callback.guard.ts +0 -87
- package/src/ngmodule/auth.interceptor.class.ts +0 -124
- package/src/ngmodule/auth.service.ts +0 -865
- package/src/ngmodule/http-adapter.ts +0 -79
- package/src/ngmodule/nauth.module.ts +0 -59
- package/src/package.json +0 -11
- package/src/standalone/ng-package.json +0 -7
- package/src/standalone/package.json +0 -8
- package/standalone/auth.interceptor.ts +0 -194
- package/standalone/auth.service.ts +0 -865
- package/standalone/http-adapter.ts +0 -79
- package/standalone/ng-package.json +0 -7
- package/standalone/package.json +0 -8
- package/standalone/social-redirect-callback.guard.ts +0 -87
- package/tsconfig.json +0 -10
- package/tsconfig.lib.json +0 -28
- package/tsconfig.lib.prod.json +0 -10
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { AngularHttpAdapter } from './http-adapter';
|
|
3
|
+
import { NAuthClient, NAuthClientConfig, ChallengeResponse, AuthResponse, TokenResponse, AuthUser, ConfirmForgotPasswordResponse, ForgotPasswordResponse, UpdateProfileRequest, GetChallengeDataResponse, GetSetupDataResponse, MFAStatus, MFADevice, AuthEvent, SocialProvider, SocialLoginOptions, LinkedAccountsResponse, SocialVerifyRequest, AuditHistoryResponse } from '@nauth-toolkit/client';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* Angular wrapper around NAuthClient that provides promise-based auth methods and reactive state.
|
|
7
|
+
*
|
|
8
|
+
* This service provides:
|
|
9
|
+
* - Reactive state (currentUser$, isAuthenticated$, challenge$)
|
|
10
|
+
* - All core auth methods as Promises (login, signup, logout, refresh)
|
|
11
|
+
* - Profile management (getProfile, updateProfile, changePassword)
|
|
12
|
+
* - Challenge flow methods (respondToChallenge, resendCode)
|
|
13
|
+
* - MFA management (getMfaStatus, setupMfaDevice, etc.)
|
|
14
|
+
* - Social authentication and account linking
|
|
15
|
+
* - Device trust management
|
|
16
|
+
* - Audit history
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* constructor(private auth: AuthService) {}
|
|
21
|
+
*
|
|
22
|
+
* // Reactive state
|
|
23
|
+
* this.auth.currentUser$.subscribe(user => ...);
|
|
24
|
+
* this.auth.isAuthenticated$.subscribe(isAuth => ...);
|
|
25
|
+
*
|
|
26
|
+
* // Auth operations with async/await
|
|
27
|
+
* const response = await this.auth.login(email, password);
|
|
28
|
+
*
|
|
29
|
+
* // Profile management
|
|
30
|
+
* await this.auth.changePassword(oldPassword, newPassword);
|
|
31
|
+
* const user = await this.auth.updateProfile({ firstName: 'John' });
|
|
32
|
+
*
|
|
33
|
+
* // MFA operations
|
|
34
|
+
* const status = await this.auth.getMfaStatus();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class AuthService {
|
|
38
|
+
private readonly client;
|
|
39
|
+
private readonly config;
|
|
40
|
+
private readonly currentUserSubject;
|
|
41
|
+
private readonly isAuthenticatedSubject;
|
|
42
|
+
private readonly challengeSubject;
|
|
43
|
+
private readonly authEventsSubject;
|
|
44
|
+
private initialized;
|
|
45
|
+
/**
|
|
46
|
+
* @param config - Injected client configuration (required)
|
|
47
|
+
* @param httpAdapter - Angular HTTP adapter for making requests (required)
|
|
48
|
+
*/
|
|
49
|
+
constructor(config: NAuthClientConfig, httpAdapter: AngularHttpAdapter);
|
|
50
|
+
/**
|
|
51
|
+
* Current user observable.
|
|
52
|
+
*/
|
|
53
|
+
get currentUser$(): Observable<AuthUser | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Authenticated state observable.
|
|
56
|
+
*/
|
|
57
|
+
get isAuthenticated$(): Observable<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Current challenge observable (for reactive challenge navigation).
|
|
60
|
+
*/
|
|
61
|
+
get challenge$(): Observable<AuthResponse | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Authentication events stream.
|
|
64
|
+
* Emits all auth lifecycle events for custom logic, analytics, or UI updates.
|
|
65
|
+
*/
|
|
66
|
+
get authEvents$(): Observable<AuthEvent>;
|
|
67
|
+
/**
|
|
68
|
+
* Successful authentication events stream.
|
|
69
|
+
* Emits when user successfully authenticates (login, signup, social auth).
|
|
70
|
+
*/
|
|
71
|
+
get authSuccess$(): Observable<AuthEvent>;
|
|
72
|
+
/**
|
|
73
|
+
* Authentication error events stream.
|
|
74
|
+
* Emits when authentication fails (login error, OAuth error, etc.).
|
|
75
|
+
*/
|
|
76
|
+
get authError$(): Observable<AuthEvent>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if authenticated (sync, uses cached state).
|
|
79
|
+
*/
|
|
80
|
+
isAuthenticated(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get current user (sync, uses cached state).
|
|
83
|
+
*/
|
|
84
|
+
getCurrentUser(): AuthUser | null;
|
|
85
|
+
/**
|
|
86
|
+
* Get current challenge (sync).
|
|
87
|
+
*/
|
|
88
|
+
getCurrentChallenge(): AuthResponse | null;
|
|
89
|
+
/**
|
|
90
|
+
* Login with identifier and password.
|
|
91
|
+
*
|
|
92
|
+
* @param identifier - User email or username
|
|
93
|
+
* @param password - User password
|
|
94
|
+
* @returns Promise with auth response or challenge
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const response = await this.auth.login('user@example.com', 'password');
|
|
99
|
+
* if (response.challengeName) {
|
|
100
|
+
* // Handle challenge
|
|
101
|
+
* } else {
|
|
102
|
+
* // Login successful
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
login(identifier: string, password: string): Promise<AuthResponse>;
|
|
107
|
+
/**
|
|
108
|
+
* Signup with credentials.
|
|
109
|
+
*
|
|
110
|
+
* @param payload - Signup request payload
|
|
111
|
+
* @returns Promise with auth response or challenge
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const response = await this.auth.signup({
|
|
116
|
+
* email: 'new@example.com',
|
|
117
|
+
* password: 'SecurePass123!',
|
|
118
|
+
* firstName: 'John',
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
signup(payload: Parameters<NAuthClient['signup']>[0]): Promise<AuthResponse>;
|
|
123
|
+
/**
|
|
124
|
+
* Logout current session.
|
|
125
|
+
*
|
|
126
|
+
* @param forgetDevice - If true, removes device trust
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* await this.auth.logout();
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
logout(forgetDevice?: boolean): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Logout all sessions.
|
|
136
|
+
*
|
|
137
|
+
* Revokes all active sessions for the current user across all devices.
|
|
138
|
+
* Optionally revokes all trusted devices if forgetDevices is true.
|
|
139
|
+
*
|
|
140
|
+
* @param forgetDevices - If true, also revokes all trusted devices (default: false)
|
|
141
|
+
* @returns Promise with number of sessions revoked
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const result = await this.auth.logoutAll();
|
|
146
|
+
* console.log(`Revoked ${result.revokedCount} sessions`);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
logoutAll(forgetDevices?: boolean): Promise<{
|
|
150
|
+
revokedCount: number;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Refresh tokens.
|
|
154
|
+
*
|
|
155
|
+
* @returns Promise with new tokens
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const tokens = await this.auth.refresh();
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
refresh(): Promise<TokenResponse>;
|
|
163
|
+
/**
|
|
164
|
+
* Request a password reset code (forgot password).
|
|
165
|
+
*
|
|
166
|
+
* @param identifier - User email, username, or phone
|
|
167
|
+
* @returns Promise with password reset response
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* await this.auth.forgotPassword('user@example.com');
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
forgotPassword(identifier: string): Promise<ForgotPasswordResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Confirm a password reset code and set a new password.
|
|
177
|
+
*
|
|
178
|
+
* @param identifier - User email, username, or phone
|
|
179
|
+
* @param code - One-time reset code
|
|
180
|
+
* @param newPassword - New password
|
|
181
|
+
* @returns Promise with confirmation response
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* await this.auth.confirmForgotPassword('user@example.com', '123456', 'NewPass123!');
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Change user password (requires current password).
|
|
191
|
+
*
|
|
192
|
+
* @param oldPassword - Current password
|
|
193
|
+
* @param newPassword - New password (must meet requirements)
|
|
194
|
+
* @returns Promise that resolves when password is changed
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* await this.auth.changePassword('oldPassword123', 'newSecurePassword456!');
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
changePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Request password change (must change on next login).
|
|
204
|
+
*
|
|
205
|
+
* @returns Promise that resolves when request is sent
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* await this.auth.requestPasswordChange();
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
requestPasswordChange(): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Get current user profile.
|
|
215
|
+
*
|
|
216
|
+
* @returns Promise of current user profile
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const user = await this.auth.getProfile();
|
|
221
|
+
* console.log('User profile:', user);
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
getProfile(): Promise<AuthUser>;
|
|
225
|
+
/**
|
|
226
|
+
* Update user profile.
|
|
227
|
+
*
|
|
228
|
+
* @param updates - Profile fields to update
|
|
229
|
+
* @returns Promise of updated user profile
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const user = await this.auth.updateProfile({ firstName: 'John', lastName: 'Doe' });
|
|
234
|
+
* console.log('Profile updated:', user);
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
updateProfile(updates: UpdateProfileRequest): Promise<AuthUser>;
|
|
238
|
+
/**
|
|
239
|
+
* Respond to a challenge (VERIFY_EMAIL, VERIFY_PHONE, MFA_REQUIRED, etc.).
|
|
240
|
+
*
|
|
241
|
+
* @param response - Challenge response data
|
|
242
|
+
* @returns Promise with auth response or next challenge
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const result = await this.auth.respondToChallenge({
|
|
247
|
+
* session: challengeSession,
|
|
248
|
+
* type: 'VERIFY_EMAIL',
|
|
249
|
+
* code: '123456',
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
respondToChallenge(response: ChallengeResponse): Promise<AuthResponse>;
|
|
254
|
+
/**
|
|
255
|
+
* Resend challenge code.
|
|
256
|
+
*
|
|
257
|
+
* @param session - Challenge session token
|
|
258
|
+
* @returns Promise with destination information
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const result = await this.auth.resendCode(session);
|
|
263
|
+
* console.log('Code sent to:', result.destination);
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
resendCode(session: string): Promise<{
|
|
267
|
+
destination: string;
|
|
268
|
+
}>;
|
|
269
|
+
/**
|
|
270
|
+
* Get MFA setup data (for MFA_SETUP_REQUIRED challenge).
|
|
271
|
+
*
|
|
272
|
+
* Returns method-specific setup information:
|
|
273
|
+
* - TOTP: { secret, qrCode, manualEntryKey }
|
|
274
|
+
* - SMS: { maskedPhone }
|
|
275
|
+
* - Email: { maskedEmail }
|
|
276
|
+
* - Passkey: WebAuthn registration options
|
|
277
|
+
*
|
|
278
|
+
* @param session - Challenge session token
|
|
279
|
+
* @param method - MFA method to set up
|
|
280
|
+
* @returns Promise of setup data response
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* const setupData = await this.auth.getSetupData(session, 'totp');
|
|
285
|
+
* console.log('QR Code:', setupData.setupData.qrCode);
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
getSetupData(session: string, method: string): Promise<GetSetupDataResponse>;
|
|
289
|
+
/**
|
|
290
|
+
* Get MFA challenge data (for MFA_REQUIRED challenge - e.g., passkey options).
|
|
291
|
+
*
|
|
292
|
+
* @param session - Challenge session token
|
|
293
|
+
* @param method - Challenge method
|
|
294
|
+
* @returns Promise of challenge data response
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const challengeData = await this.auth.getChallengeData(session, 'passkey');
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
getChallengeData(session: string, method: string): Promise<GetChallengeDataResponse>;
|
|
302
|
+
/**
|
|
303
|
+
* Clear stored challenge (when navigating away from challenge flow).
|
|
304
|
+
*
|
|
305
|
+
* @returns Promise that resolves when challenge is cleared
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* await this.auth.clearChallenge();
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
clearChallenge(): Promise<void>;
|
|
313
|
+
/**
|
|
314
|
+
* Initiate social OAuth login flow.
|
|
315
|
+
* Redirects the browser to backend `/auth/social/:provider/redirect`.
|
|
316
|
+
*
|
|
317
|
+
* @param provider - Social provider ('google', 'apple', 'facebook')
|
|
318
|
+
* @param options - Optional redirect options
|
|
319
|
+
* @returns Promise that resolves when redirect starts
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* await this.auth.loginWithSocial('google', { returnTo: '/auth/callback' });
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
loginWithSocial(provider: SocialProvider, options?: SocialLoginOptions): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Exchange an exchangeToken (from redirect callback URL) into an AuthResponse.
|
|
329
|
+
*
|
|
330
|
+
* Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
|
|
331
|
+
* with `exchangeToken` instead of setting cookies.
|
|
332
|
+
*
|
|
333
|
+
* @param exchangeToken - One-time exchange token from the callback URL
|
|
334
|
+
* @returns Promise of AuthResponse
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const response = await this.auth.exchangeSocialRedirect(exchangeToken);
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
exchangeSocialRedirect(exchangeToken: string): Promise<AuthResponse>;
|
|
342
|
+
/**
|
|
343
|
+
* Verify native social token (mobile).
|
|
344
|
+
*
|
|
345
|
+
* @param request - Social verification request with provider and token
|
|
346
|
+
* @returns Promise of AuthResponse
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* const result = await this.auth.verifyNativeSocial({
|
|
351
|
+
* provider: 'google',
|
|
352
|
+
* idToken: nativeIdToken,
|
|
353
|
+
* });
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
verifyNativeSocial(request: SocialVerifyRequest): Promise<AuthResponse>;
|
|
357
|
+
/**
|
|
358
|
+
* Get linked social accounts.
|
|
359
|
+
*
|
|
360
|
+
* @returns Promise of linked accounts response
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const accounts = await this.auth.getLinkedAccounts();
|
|
365
|
+
* console.log('Linked providers:', accounts.providers);
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
getLinkedAccounts(): Promise<LinkedAccountsResponse>;
|
|
369
|
+
/**
|
|
370
|
+
* Link social account.
|
|
371
|
+
*
|
|
372
|
+
* @param provider - Social provider to link
|
|
373
|
+
* @param code - OAuth authorization code
|
|
374
|
+
* @param state - OAuth state parameter
|
|
375
|
+
* @returns Promise with success message
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* await this.auth.linkSocialAccount('google', code, state);
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
linkSocialAccount(provider: string, code: string, state: string): Promise<{
|
|
383
|
+
message: string;
|
|
384
|
+
}>;
|
|
385
|
+
/**
|
|
386
|
+
* Unlink social account.
|
|
387
|
+
*
|
|
388
|
+
* @param provider - Social provider to unlink
|
|
389
|
+
* @returns Promise with success message
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* await this.auth.unlinkSocialAccount('google');
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
unlinkSocialAccount(provider: string): Promise<{
|
|
397
|
+
message: string;
|
|
398
|
+
}>;
|
|
399
|
+
/**
|
|
400
|
+
* Get MFA status for the current user.
|
|
401
|
+
*
|
|
402
|
+
* @returns Promise of MFA status
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const status = await this.auth.getMfaStatus();
|
|
407
|
+
* console.log('MFA enabled:', status.enabled);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
getMfaStatus(): Promise<MFAStatus>;
|
|
411
|
+
/**
|
|
412
|
+
* Get MFA devices for the current user.
|
|
413
|
+
*
|
|
414
|
+
* @returns Promise of MFA devices array
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const devices = await this.auth.getMfaDevices();
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
getMfaDevices(): Promise<MFADevice[]>;
|
|
422
|
+
/**
|
|
423
|
+
* Setup MFA device (authenticated user).
|
|
424
|
+
*
|
|
425
|
+
* @param method - MFA method to set up
|
|
426
|
+
* @returns Promise of setup data
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* const setupData = await this.auth.setupMfaDevice('totp');
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
setupMfaDevice(method: string): Promise<unknown>;
|
|
434
|
+
/**
|
|
435
|
+
* Verify MFA setup (authenticated user).
|
|
436
|
+
*
|
|
437
|
+
* @param method - MFA method
|
|
438
|
+
* @param setupData - Setup data from setupMfaDevice
|
|
439
|
+
* @param deviceName - Optional device name
|
|
440
|
+
* @returns Promise with device ID
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* const result = await this.auth.verifyMfaSetup('totp', { code: '123456' }, 'My Phone');
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
|
|
448
|
+
deviceId: number;
|
|
449
|
+
}>;
|
|
450
|
+
/**
|
|
451
|
+
* Remove MFA device.
|
|
452
|
+
*
|
|
453
|
+
* @param method - MFA method to remove
|
|
454
|
+
* @returns Promise with success message
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```typescript
|
|
458
|
+
* await this.auth.removeMfaDevice('sms');
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
removeMfaDevice(method: string): Promise<{
|
|
462
|
+
message: string;
|
|
463
|
+
}>;
|
|
464
|
+
/**
|
|
465
|
+
* Set preferred MFA method.
|
|
466
|
+
*
|
|
467
|
+
* @param method - Device method to set as preferred ('totp', 'sms', 'email', or 'passkey')
|
|
468
|
+
* @returns Promise with success message
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```typescript
|
|
472
|
+
* await this.auth.setPreferredMfaMethod('totp');
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
setPreferredMfaMethod(method: 'totp' | 'sms' | 'email' | 'passkey'): Promise<{
|
|
476
|
+
message: string;
|
|
477
|
+
}>;
|
|
478
|
+
/**
|
|
479
|
+
* Generate backup codes.
|
|
480
|
+
*
|
|
481
|
+
* @returns Promise of backup codes array
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* const codes = await this.auth.generateBackupCodes();
|
|
486
|
+
* console.log('Backup codes:', codes);
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
generateBackupCodes(): Promise<string[]>;
|
|
490
|
+
/**
|
|
491
|
+
* Set MFA exemption (admin/test scenarios).
|
|
492
|
+
*
|
|
493
|
+
* @param exempt - Whether to exempt user from MFA
|
|
494
|
+
* @param reason - Optional reason for exemption
|
|
495
|
+
* @returns Promise that resolves when exemption is set
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```typescript
|
|
499
|
+
* await this.auth.setMfaExemption(true, 'Test account');
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
setMfaExemption(exempt: boolean, reason?: string): Promise<void>;
|
|
503
|
+
/**
|
|
504
|
+
* Trust current device.
|
|
505
|
+
*
|
|
506
|
+
* @returns Promise with device token
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```typescript
|
|
510
|
+
* const result = await this.auth.trustDevice();
|
|
511
|
+
* console.log('Device trusted:', result.deviceToken);
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
trustDevice(): Promise<{
|
|
515
|
+
deviceToken: string;
|
|
516
|
+
}>;
|
|
517
|
+
/**
|
|
518
|
+
* Check if the current device is trusted.
|
|
519
|
+
*
|
|
520
|
+
* @returns Promise with trusted status
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const result = await this.auth.isTrustedDevice();
|
|
525
|
+
* if (result.trusted) {
|
|
526
|
+
* console.log('This device is trusted');
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
isTrustedDevice(): Promise<{
|
|
531
|
+
trusted: boolean;
|
|
532
|
+
}>;
|
|
533
|
+
/**
|
|
534
|
+
* Get paginated audit history for the current user.
|
|
535
|
+
*
|
|
536
|
+
* @param params - Query parameters for filtering and pagination
|
|
537
|
+
* @returns Promise of audit history response
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* const history = await this.auth.getAuditHistory({
|
|
542
|
+
* page: 1,
|
|
543
|
+
* limit: 20,
|
|
544
|
+
* eventType: 'LOGIN_SUCCESS'
|
|
545
|
+
* });
|
|
546
|
+
* console.log('Audit history:', history);
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
getAuditHistory(params?: Record<string, string | number | boolean>): Promise<AuditHistoryResponse>;
|
|
550
|
+
/**
|
|
551
|
+
* Expose underlying NAuthClient for advanced scenarios.
|
|
552
|
+
*
|
|
553
|
+
* @deprecated All core functionality is now exposed directly on AuthService as Promises.
|
|
554
|
+
* Use the direct methods on AuthService instead (e.g., `auth.changePassword()` instead of `auth.getClient().changePassword()`).
|
|
555
|
+
* This method is kept for backward compatibility only and may be removed in a future version.
|
|
556
|
+
*
|
|
557
|
+
* @returns The underlying NAuthClient instance
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```typescript
|
|
561
|
+
* // Deprecated - use direct methods instead
|
|
562
|
+
* const status = await this.auth.getClient().getMfaStatus();
|
|
563
|
+
*
|
|
564
|
+
* // Preferred - use direct methods
|
|
565
|
+
* const status = await this.auth.getMfaStatus();
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
getClient(): NAuthClient;
|
|
569
|
+
/**
|
|
570
|
+
* Initialize by hydrating state from storage.
|
|
571
|
+
* Called automatically on construction.
|
|
572
|
+
*/
|
|
573
|
+
private initialize;
|
|
574
|
+
/**
|
|
575
|
+
* Update challenge state after auth response.
|
|
576
|
+
*/
|
|
577
|
+
private updateChallengeState;
|
|
578
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
|
|
579
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
|
|
580
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { HttpAdapter, HttpRequest, HttpResponse } from '@nauth-toolkit/client';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* HTTP adapter for Angular using HttpClient.
|
|
6
|
+
*
|
|
7
|
+
* This adapter:
|
|
8
|
+
* - Uses Angular's HttpClient for all requests
|
|
9
|
+
* - Works with Angular's HTTP interceptors (including authInterceptor)
|
|
10
|
+
* - Auto-provided via Angular DI (providedIn: 'root')
|
|
11
|
+
* - Converts HttpClient responses to HttpResponse format
|
|
12
|
+
* - Converts HttpErrorResponse to NAuthClientError
|
|
13
|
+
*
|
|
14
|
+
* Users don't need to configure this manually - it's automatically
|
|
15
|
+
* injected when using AuthService in Angular apps.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Automatic usage (no manual setup needed)
|
|
20
|
+
* // AuthService automatically injects AngularHttpAdapter
|
|
21
|
+
* constructor(private auth: AuthService) {}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class AngularHttpAdapter implements HttpAdapter {
|
|
25
|
+
private readonly http;
|
|
26
|
+
constructor(http: HttpClient);
|
|
27
|
+
/**
|
|
28
|
+
* Safely parse a JSON response body.
|
|
29
|
+
*
|
|
30
|
+
* Angular's fetch backend (`withFetch()`) will throw a raw `SyntaxError` if
|
|
31
|
+
* `responseType: 'json'` is used and the backend returns HTML (common for
|
|
32
|
+
* proxies, 502 pages, SSR fallbacks, or misrouted requests).
|
|
33
|
+
*
|
|
34
|
+
* To avoid crashing consumer apps, we always request as text and then parse
|
|
35
|
+
* JSON only when the response actually looks like JSON.
|
|
36
|
+
*
|
|
37
|
+
* @param bodyText - Raw response body as text
|
|
38
|
+
* @param contentType - Content-Type header value (if available)
|
|
39
|
+
* @returns Parsed JSON value (unknown)
|
|
40
|
+
* @throws {SyntaxError} When body is non-empty but not valid JSON
|
|
41
|
+
*/
|
|
42
|
+
private parseJsonBody;
|
|
43
|
+
/**
|
|
44
|
+
* Execute HTTP request using Angular's HttpClient.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Request configuration
|
|
47
|
+
* @returns Response with parsed data
|
|
48
|
+
* @throws NAuthClientError if request fails
|
|
49
|
+
*/
|
|
50
|
+
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
51
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AngularHttpAdapter, never>;
|
|
52
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AngularHttpAdapter>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ModuleWithProviders } from '@angular/core';
|
|
2
|
+
import { NAuthClientConfig } from '@nauth-toolkit/client';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
import * as i1 from "@angular/common/http";
|
|
5
|
+
/**
|
|
6
|
+
* NgModule for nauth-toolkit Angular integration.
|
|
7
|
+
*
|
|
8
|
+
* Use this for NgModule-based apps (Angular 17+ with NgModule or legacy apps).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // app.module.ts
|
|
13
|
+
* import { NAuthModule } from '@nauth-toolkit/client-angular';
|
|
14
|
+
*
|
|
15
|
+
* @NgModule({
|
|
16
|
+
* imports: [
|
|
17
|
+
* NAuthModule.forRoot({
|
|
18
|
+
* baseUrl: 'http://localhost:3000/auth',
|
|
19
|
+
* tokenDelivery: 'cookies',
|
|
20
|
+
* }),
|
|
21
|
+
* ],
|
|
22
|
+
* })
|
|
23
|
+
* export class AppModule {}
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class NAuthModule {
|
|
27
|
+
static forRoot(config: NAuthClientConfig): ModuleWithProviders<NAuthModule>;
|
|
28
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NAuthModule, never>;
|
|
29
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<NAuthModule, never, [typeof i1.HttpClientModule], [typeof i1.HttpClientModule]>;
|
|
30
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<NAuthModule>;
|
|
31
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { InjectionToken } from '@angular/core';
|
|
2
2
|
import { NAuthClientConfig } from '@nauth-toolkit/client';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Injection token for providing NAuthClientConfig in Angular apps.
|
|
6
5
|
*/
|
|
7
|
-
export const NAUTH_CLIENT_CONFIG
|
|
6
|
+
export declare const NAUTH_CLIENT_CONFIG: InjectionToken<NAuthClientConfig>;
|