@nauth-toolkit/client 0.1.45 → 0.1.48
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/dist/angular/index.cjs +327 -189
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.mts +263 -106
- package/dist/angular/index.d.ts +263 -106
- package/dist/angular/index.mjs +325 -187
- package/dist/angular/index.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/angular/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ var NAUTH_CLIENT_CONFIG = new InjectionToken("NAUTH_CLIENT_CONFIG");
|
|
|
19
19
|
|
|
20
20
|
// src/angular/auth.service.ts
|
|
21
21
|
import { Inject, Injectable as Injectable2, Optional, inject as inject2 } from "@angular/core";
|
|
22
|
-
import { BehaviorSubject,
|
|
22
|
+
import { BehaviorSubject, Subject } from "rxjs";
|
|
23
23
|
import { filter } from "rxjs/operators";
|
|
24
24
|
|
|
25
25
|
// src/angular/http-adapter.ts
|
|
@@ -1435,41 +1435,73 @@ var AuthService = class {
|
|
|
1435
1435
|
return this.challengeSubject.value;
|
|
1436
1436
|
}
|
|
1437
1437
|
// ============================================================================
|
|
1438
|
-
// Core Auth Methods
|
|
1438
|
+
// Core Auth Methods
|
|
1439
1439
|
// ============================================================================
|
|
1440
1440
|
/**
|
|
1441
1441
|
* Login with identifier and password.
|
|
1442
|
+
*
|
|
1443
|
+
* @param identifier - User email or username
|
|
1444
|
+
* @param password - User password
|
|
1445
|
+
* @returns Promise with auth response or challenge
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* ```typescript
|
|
1449
|
+
* const response = await this.auth.login('user@example.com', 'password');
|
|
1450
|
+
* if (response.challengeName) {
|
|
1451
|
+
* // Handle challenge
|
|
1452
|
+
* } else {
|
|
1453
|
+
* // Login successful
|
|
1454
|
+
* }
|
|
1455
|
+
* ```
|
|
1442
1456
|
*/
|
|
1443
|
-
login(identifier, password) {
|
|
1444
|
-
|
|
1457
|
+
async login(identifier, password) {
|
|
1458
|
+
const res = await this.client.login(identifier, password);
|
|
1459
|
+
return this.updateChallengeState(res);
|
|
1445
1460
|
}
|
|
1446
1461
|
/**
|
|
1447
1462
|
* Signup with credentials.
|
|
1463
|
+
*
|
|
1464
|
+
* @param payload - Signup request payload
|
|
1465
|
+
* @returns Promise with auth response or challenge
|
|
1466
|
+
*
|
|
1467
|
+
* @example
|
|
1468
|
+
* ```typescript
|
|
1469
|
+
* const response = await this.auth.signup({
|
|
1470
|
+
* email: 'new@example.com',
|
|
1471
|
+
* password: 'SecurePass123!',
|
|
1472
|
+
* firstName: 'John',
|
|
1473
|
+
* });
|
|
1474
|
+
* ```
|
|
1448
1475
|
*/
|
|
1449
|
-
signup(payload) {
|
|
1450
|
-
|
|
1476
|
+
async signup(payload) {
|
|
1477
|
+
const res = await this.client.signup(payload);
|
|
1478
|
+
return this.updateChallengeState(res);
|
|
1451
1479
|
}
|
|
1452
1480
|
/**
|
|
1453
1481
|
* Logout current session.
|
|
1482
|
+
*
|
|
1483
|
+
* @param forgetDevice - If true, removes device trust
|
|
1484
|
+
*
|
|
1485
|
+
* @example
|
|
1486
|
+
* ```typescript
|
|
1487
|
+
* await this.auth.logout();
|
|
1488
|
+
* ```
|
|
1454
1489
|
*/
|
|
1455
|
-
logout(forgetDevice) {
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
}
|
|
1471
|
-
})
|
|
1472
|
-
);
|
|
1490
|
+
async logout(forgetDevice) {
|
|
1491
|
+
await this.client.logout(forgetDevice);
|
|
1492
|
+
this.challengeSubject.next(null);
|
|
1493
|
+
this.currentUserSubject.next(null);
|
|
1494
|
+
this.isAuthenticatedSubject.next(false);
|
|
1495
|
+
if (this.config.tokenDelivery === "cookies" && typeof document !== "undefined") {
|
|
1496
|
+
const csrfCookieName = this.config.csrf?.cookieName ?? "nauth_csrf_token";
|
|
1497
|
+
try {
|
|
1498
|
+
const url = new URL(this.config.baseUrl);
|
|
1499
|
+
document.cookie = `${csrfCookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=${url.hostname}`;
|
|
1500
|
+
document.cookie = `${csrfCookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
|
|
1501
|
+
} catch {
|
|
1502
|
+
document.cookie = `${csrfCookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1473
1505
|
}
|
|
1474
1506
|
/**
|
|
1475
1507
|
* Logout all sessions.
|
|
@@ -1478,38 +1510,32 @@ var AuthService = class {
|
|
|
1478
1510
|
* Optionally revokes all trusted devices if forgetDevices is true.
|
|
1479
1511
|
*
|
|
1480
1512
|
* @param forgetDevices - If true, also revokes all trusted devices (default: false)
|
|
1481
|
-
* @returns
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
this.isAuthenticatedSubject.next(false);
|
|
1489
|
-
return res;
|
|
1490
|
-
})
|
|
1491
|
-
);
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Refresh tokens.
|
|
1513
|
+
* @returns Promise with number of sessions revoked
|
|
1514
|
+
*
|
|
1515
|
+
* @example
|
|
1516
|
+
* ```typescript
|
|
1517
|
+
* const result = await this.auth.logoutAll();
|
|
1518
|
+
* console.log(`Revoked ${result.revokedCount} sessions`);
|
|
1519
|
+
* ```
|
|
1495
1520
|
*/
|
|
1496
|
-
|
|
1497
|
-
|
|
1521
|
+
async logoutAll(forgetDevices) {
|
|
1522
|
+
const res = await this.client.logoutAll(forgetDevices);
|
|
1523
|
+
this.challengeSubject.next(null);
|
|
1524
|
+
this.currentUserSubject.next(null);
|
|
1525
|
+
this.isAuthenticatedSubject.next(false);
|
|
1526
|
+
return res;
|
|
1498
1527
|
}
|
|
1499
1528
|
/**
|
|
1500
|
-
* Refresh tokens
|
|
1501
|
-
*
|
|
1502
|
-
* Returns a promise instead of an Observable, matching the core NAuthClient API.
|
|
1503
|
-
* Useful for async/await patterns in guards and interceptors.
|
|
1529
|
+
* Refresh tokens.
|
|
1504
1530
|
*
|
|
1505
|
-
* @returns Promise
|
|
1531
|
+
* @returns Promise with new tokens
|
|
1506
1532
|
*
|
|
1507
1533
|
* @example
|
|
1508
1534
|
* ```typescript
|
|
1509
|
-
* const tokens = await auth.
|
|
1535
|
+
* const tokens = await this.auth.refresh();
|
|
1510
1536
|
* ```
|
|
1511
1537
|
*/
|
|
1512
|
-
|
|
1538
|
+
async refresh() {
|
|
1513
1539
|
return this.client.refreshTokens();
|
|
1514
1540
|
}
|
|
1515
1541
|
// ============================================================================
|
|
@@ -1517,119 +1543,134 @@ var AuthService = class {
|
|
|
1517
1543
|
// ============================================================================
|
|
1518
1544
|
/**
|
|
1519
1545
|
* Request a password reset code (forgot password).
|
|
1546
|
+
*
|
|
1547
|
+
* @param identifier - User email, username, or phone
|
|
1548
|
+
* @returns Promise with password reset response
|
|
1549
|
+
*
|
|
1550
|
+
* @example
|
|
1551
|
+
* ```typescript
|
|
1552
|
+
* await this.auth.forgotPassword('user@example.com');
|
|
1553
|
+
* ```
|
|
1520
1554
|
*/
|
|
1521
|
-
forgotPassword(identifier) {
|
|
1522
|
-
return
|
|
1555
|
+
async forgotPassword(identifier) {
|
|
1556
|
+
return this.client.forgotPassword(identifier);
|
|
1523
1557
|
}
|
|
1524
1558
|
/**
|
|
1525
1559
|
* Confirm a password reset code and set a new password.
|
|
1560
|
+
*
|
|
1561
|
+
* @param identifier - User email, username, or phone
|
|
1562
|
+
* @param code - One-time reset code
|
|
1563
|
+
* @param newPassword - New password
|
|
1564
|
+
* @returns Promise with confirmation response
|
|
1565
|
+
*
|
|
1566
|
+
* @example
|
|
1567
|
+
* ```typescript
|
|
1568
|
+
* await this.auth.confirmForgotPassword('user@example.com', '123456', 'NewPass123!');
|
|
1569
|
+
* ```
|
|
1526
1570
|
*/
|
|
1527
|
-
confirmForgotPassword(identifier, code, newPassword) {
|
|
1528
|
-
return
|
|
1571
|
+
async confirmForgotPassword(identifier, code, newPassword) {
|
|
1572
|
+
return this.client.confirmForgotPassword(identifier, code, newPassword);
|
|
1529
1573
|
}
|
|
1530
1574
|
/**
|
|
1531
1575
|
* Change user password (requires current password).
|
|
1532
1576
|
*
|
|
1533
1577
|
* @param oldPassword - Current password
|
|
1534
1578
|
* @param newPassword - New password (must meet requirements)
|
|
1535
|
-
* @returns
|
|
1579
|
+
* @returns Promise that resolves when password is changed
|
|
1536
1580
|
*
|
|
1537
1581
|
* @example
|
|
1538
1582
|
* ```typescript
|
|
1539
|
-
* this.auth.changePassword('oldPassword123', 'newSecurePassword456!')
|
|
1540
|
-
* next: () => console.log('Password changed successfully'),
|
|
1541
|
-
* error: (err) => console.error('Failed to change password:', err)
|
|
1542
|
-
* });
|
|
1583
|
+
* await this.auth.changePassword('oldPassword123', 'newSecurePassword456!');
|
|
1543
1584
|
* ```
|
|
1544
1585
|
*/
|
|
1545
|
-
changePassword(oldPassword, newPassword) {
|
|
1546
|
-
return
|
|
1586
|
+
async changePassword(oldPassword, newPassword) {
|
|
1587
|
+
return this.client.changePassword(oldPassword, newPassword);
|
|
1547
1588
|
}
|
|
1548
1589
|
/**
|
|
1549
1590
|
* Request password change (must change on next login).
|
|
1550
1591
|
*
|
|
1551
|
-
* @returns
|
|
1552
|
-
*/
|
|
1553
|
-
requestPasswordChange() {
|
|
1554
|
-
return from(this.client.requestPasswordChange());
|
|
1555
|
-
}
|
|
1556
|
-
// ============================================================================
|
|
1557
|
-
// Profile Management
|
|
1558
|
-
// ============================================================================
|
|
1559
|
-
/**
|
|
1560
|
-
* Get current user profile.
|
|
1561
|
-
*
|
|
1562
|
-
* @returns Observable of current user profile
|
|
1592
|
+
* @returns Promise that resolves when request is sent
|
|
1563
1593
|
*
|
|
1564
1594
|
* @example
|
|
1565
1595
|
* ```typescript
|
|
1566
|
-
* this.auth.
|
|
1567
|
-
* console.log('User profile:', user);
|
|
1568
|
-
* });
|
|
1596
|
+
* await this.auth.requestPasswordChange();
|
|
1569
1597
|
* ```
|
|
1570
1598
|
*/
|
|
1571
|
-
|
|
1572
|
-
return
|
|
1573
|
-
this.client.getProfile().then((user) => {
|
|
1574
|
-
this.currentUserSubject.next(user);
|
|
1575
|
-
return user;
|
|
1576
|
-
})
|
|
1577
|
-
);
|
|
1599
|
+
async requestPasswordChange() {
|
|
1600
|
+
return this.client.requestPasswordChange();
|
|
1578
1601
|
}
|
|
1602
|
+
// ============================================================================
|
|
1603
|
+
// Profile Management
|
|
1604
|
+
// ============================================================================
|
|
1579
1605
|
/**
|
|
1580
|
-
* Get current user profile
|
|
1581
|
-
*
|
|
1582
|
-
* Returns a promise instead of an Observable, matching the core NAuthClient API.
|
|
1583
|
-
* Useful for async/await patterns in guards and interceptors.
|
|
1606
|
+
* Get current user profile.
|
|
1584
1607
|
*
|
|
1585
1608
|
* @returns Promise of current user profile
|
|
1586
1609
|
*
|
|
1587
1610
|
* @example
|
|
1588
1611
|
* ```typescript
|
|
1589
|
-
* const user = await auth.
|
|
1612
|
+
* const user = await this.auth.getProfile();
|
|
1613
|
+
* console.log('User profile:', user);
|
|
1590
1614
|
* ```
|
|
1591
1615
|
*/
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
});
|
|
1616
|
+
async getProfile() {
|
|
1617
|
+
const user = await this.client.getProfile();
|
|
1618
|
+
this.currentUserSubject.next(user);
|
|
1619
|
+
return user;
|
|
1597
1620
|
}
|
|
1598
1621
|
/**
|
|
1599
1622
|
* Update user profile.
|
|
1600
1623
|
*
|
|
1601
1624
|
* @param updates - Profile fields to update
|
|
1602
|
-
* @returns
|
|
1625
|
+
* @returns Promise of updated user profile
|
|
1603
1626
|
*
|
|
1604
1627
|
* @example
|
|
1605
1628
|
* ```typescript
|
|
1606
|
-
* this.auth.updateProfile({ firstName: 'John', lastName: 'Doe' })
|
|
1607
|
-
*
|
|
1608
|
-
* });
|
|
1629
|
+
* const user = await this.auth.updateProfile({ firstName: 'John', lastName: 'Doe' });
|
|
1630
|
+
* console.log('Profile updated:', user);
|
|
1609
1631
|
* ```
|
|
1610
1632
|
*/
|
|
1611
|
-
updateProfile(updates) {
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
return user;
|
|
1616
|
-
})
|
|
1617
|
-
);
|
|
1633
|
+
async updateProfile(updates) {
|
|
1634
|
+
const user = await this.client.updateProfile(updates);
|
|
1635
|
+
this.currentUserSubject.next(user);
|
|
1636
|
+
return user;
|
|
1618
1637
|
}
|
|
1619
1638
|
// ============================================================================
|
|
1620
1639
|
// Challenge Flow Methods (Essential for any auth flow)
|
|
1621
1640
|
// ============================================================================
|
|
1622
1641
|
/**
|
|
1623
1642
|
* Respond to a challenge (VERIFY_EMAIL, VERIFY_PHONE, MFA_REQUIRED, etc.).
|
|
1643
|
+
*
|
|
1644
|
+
* @param response - Challenge response data
|
|
1645
|
+
* @returns Promise with auth response or next challenge
|
|
1646
|
+
*
|
|
1647
|
+
* @example
|
|
1648
|
+
* ```typescript
|
|
1649
|
+
* const result = await this.auth.respondToChallenge({
|
|
1650
|
+
* session: challengeSession,
|
|
1651
|
+
* type: 'VERIFY_EMAIL',
|
|
1652
|
+
* code: '123456',
|
|
1653
|
+
* });
|
|
1654
|
+
* ```
|
|
1624
1655
|
*/
|
|
1625
|
-
respondToChallenge(response) {
|
|
1626
|
-
|
|
1656
|
+
async respondToChallenge(response) {
|
|
1657
|
+
const res = await this.client.respondToChallenge(response);
|
|
1658
|
+
return this.updateChallengeState(res);
|
|
1627
1659
|
}
|
|
1628
1660
|
/**
|
|
1629
1661
|
* Resend challenge code.
|
|
1662
|
+
*
|
|
1663
|
+
* @param session - Challenge session token
|
|
1664
|
+
* @returns Promise with destination information
|
|
1665
|
+
*
|
|
1666
|
+
* @example
|
|
1667
|
+
* ```typescript
|
|
1668
|
+
* const result = await this.auth.resendCode(session);
|
|
1669
|
+
* console.log('Code sent to:', result.destination);
|
|
1670
|
+
* ```
|
|
1630
1671
|
*/
|
|
1631
|
-
resendCode(session) {
|
|
1632
|
-
return
|
|
1672
|
+
async resendCode(session) {
|
|
1673
|
+
return this.client.resendCode(session);
|
|
1633
1674
|
}
|
|
1634
1675
|
/**
|
|
1635
1676
|
* Get MFA setup data (for MFA_SETUP_REQUIRED challenge).
|
|
@@ -1642,30 +1683,45 @@ var AuthService = class {
|
|
|
1642
1683
|
*
|
|
1643
1684
|
* @param session - Challenge session token
|
|
1644
1685
|
* @param method - MFA method to set up
|
|
1645
|
-
* @returns
|
|
1686
|
+
* @returns Promise of setup data response
|
|
1687
|
+
*
|
|
1688
|
+
* @example
|
|
1689
|
+
* ```typescript
|
|
1690
|
+
* const setupData = await this.auth.getSetupData(session, 'totp');
|
|
1691
|
+
* console.log('QR Code:', setupData.setupData.qrCode);
|
|
1692
|
+
* ```
|
|
1646
1693
|
*/
|
|
1647
|
-
getSetupData(session, method) {
|
|
1648
|
-
return
|
|
1694
|
+
async getSetupData(session, method) {
|
|
1695
|
+
return this.client.getSetupData(session, method);
|
|
1649
1696
|
}
|
|
1650
1697
|
/**
|
|
1651
1698
|
* Get MFA challenge data (for MFA_REQUIRED challenge - e.g., passkey options).
|
|
1652
1699
|
*
|
|
1653
1700
|
* @param session - Challenge session token
|
|
1654
1701
|
* @param method - Challenge method
|
|
1655
|
-
* @returns
|
|
1702
|
+
* @returns Promise of challenge data response
|
|
1703
|
+
*
|
|
1704
|
+
* @example
|
|
1705
|
+
* ```typescript
|
|
1706
|
+
* const challengeData = await this.auth.getChallengeData(session, 'passkey');
|
|
1707
|
+
* ```
|
|
1656
1708
|
*/
|
|
1657
|
-
getChallengeData(session, method) {
|
|
1658
|
-
return
|
|
1709
|
+
async getChallengeData(session, method) {
|
|
1710
|
+
return this.client.getChallengeData(session, method);
|
|
1659
1711
|
}
|
|
1660
1712
|
/**
|
|
1661
1713
|
* Clear stored challenge (when navigating away from challenge flow).
|
|
1714
|
+
*
|
|
1715
|
+
* @returns Promise that resolves when challenge is cleared
|
|
1716
|
+
*
|
|
1717
|
+
* @example
|
|
1718
|
+
* ```typescript
|
|
1719
|
+
* await this.auth.clearChallenge();
|
|
1720
|
+
* ```
|
|
1662
1721
|
*/
|
|
1663
|
-
clearChallenge() {
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
this.challengeSubject.next(null);
|
|
1667
|
-
})
|
|
1668
|
-
);
|
|
1722
|
+
async clearChallenge() {
|
|
1723
|
+
await this.client.clearStoredChallenge();
|
|
1724
|
+
this.challengeSubject.next(null);
|
|
1669
1725
|
}
|
|
1670
1726
|
// ============================================================================
|
|
1671
1727
|
// Social Authentication
|
|
@@ -1673,8 +1729,17 @@ var AuthService = class {
|
|
|
1673
1729
|
/**
|
|
1674
1730
|
* Initiate social OAuth login flow.
|
|
1675
1731
|
* Redirects the browser to backend `/auth/social/:provider/redirect`.
|
|
1732
|
+
*
|
|
1733
|
+
* @param provider - Social provider ('google', 'apple', 'facebook')
|
|
1734
|
+
* @param options - Optional redirect options
|
|
1735
|
+
* @returns Promise that resolves when redirect starts
|
|
1736
|
+
*
|
|
1737
|
+
* @example
|
|
1738
|
+
* ```typescript
|
|
1739
|
+
* await this.auth.loginWithSocial('google', { returnTo: '/auth/callback' });
|
|
1740
|
+
* ```
|
|
1676
1741
|
*/
|
|
1677
|
-
loginWithSocial(provider, options) {
|
|
1742
|
+
async loginWithSocial(provider, options) {
|
|
1678
1743
|
return this.client.loginWithSocial(provider, options);
|
|
1679
1744
|
}
|
|
1680
1745
|
/**
|
|
@@ -1684,44 +1749,48 @@ var AuthService = class {
|
|
|
1684
1749
|
* with `exchangeToken` instead of setting cookies.
|
|
1685
1750
|
*
|
|
1686
1751
|
* @param exchangeToken - One-time exchange token from the callback URL
|
|
1687
|
-
* @returns Observable of AuthResponse
|
|
1688
|
-
*/
|
|
1689
|
-
exchangeSocialRedirect(exchangeToken) {
|
|
1690
|
-
return from(this.client.exchangeSocialRedirect(exchangeToken).then((res) => this.updateChallengeState(res)));
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* Exchange an exchangeToken (from redirect callback URL) into an AuthResponse (promise-based).
|
|
1694
|
-
*
|
|
1695
|
-
* Returns a promise instead of an Observable, matching the core NAuthClient API.
|
|
1696
|
-
* Useful for async/await patterns in guards and interceptors.
|
|
1697
|
-
*
|
|
1698
|
-
* @param exchangeToken - One-time exchange token from the callback URL
|
|
1699
1752
|
* @returns Promise of AuthResponse
|
|
1700
1753
|
*
|
|
1701
1754
|
* @example
|
|
1702
1755
|
* ```typescript
|
|
1703
|
-
* const response = await auth.
|
|
1756
|
+
* const response = await this.auth.exchangeSocialRedirect(exchangeToken);
|
|
1704
1757
|
* ```
|
|
1705
1758
|
*/
|
|
1706
|
-
|
|
1707
|
-
|
|
1759
|
+
async exchangeSocialRedirect(exchangeToken) {
|
|
1760
|
+
const res = await this.client.exchangeSocialRedirect(exchangeToken);
|
|
1761
|
+
return this.updateChallengeState(res);
|
|
1708
1762
|
}
|
|
1709
1763
|
/**
|
|
1710
1764
|
* Verify native social token (mobile).
|
|
1711
1765
|
*
|
|
1712
1766
|
* @param request - Social verification request with provider and token
|
|
1713
|
-
* @returns
|
|
1767
|
+
* @returns Promise of AuthResponse
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```typescript
|
|
1771
|
+
* const result = await this.auth.verifyNativeSocial({
|
|
1772
|
+
* provider: 'google',
|
|
1773
|
+
* idToken: nativeIdToken,
|
|
1774
|
+
* });
|
|
1775
|
+
* ```
|
|
1714
1776
|
*/
|
|
1715
|
-
verifyNativeSocial(request) {
|
|
1716
|
-
|
|
1777
|
+
async verifyNativeSocial(request) {
|
|
1778
|
+
const res = await this.client.verifyNativeSocial(request);
|
|
1779
|
+
return this.updateChallengeState(res);
|
|
1717
1780
|
}
|
|
1718
1781
|
/**
|
|
1719
1782
|
* Get linked social accounts.
|
|
1720
1783
|
*
|
|
1721
|
-
* @returns
|
|
1784
|
+
* @returns Promise of linked accounts response
|
|
1785
|
+
*
|
|
1786
|
+
* @example
|
|
1787
|
+
* ```typescript
|
|
1788
|
+
* const accounts = await this.auth.getLinkedAccounts();
|
|
1789
|
+
* console.log('Linked providers:', accounts.providers);
|
|
1790
|
+
* ```
|
|
1722
1791
|
*/
|
|
1723
|
-
getLinkedAccounts() {
|
|
1724
|
-
return
|
|
1792
|
+
async getLinkedAccounts() {
|
|
1793
|
+
return this.client.getLinkedAccounts();
|
|
1725
1794
|
}
|
|
1726
1795
|
/**
|
|
1727
1796
|
* Link social account.
|
|
@@ -1729,19 +1798,29 @@ var AuthService = class {
|
|
|
1729
1798
|
* @param provider - Social provider to link
|
|
1730
1799
|
* @param code - OAuth authorization code
|
|
1731
1800
|
* @param state - OAuth state parameter
|
|
1732
|
-
* @returns
|
|
1801
|
+
* @returns Promise with success message
|
|
1802
|
+
*
|
|
1803
|
+
* @example
|
|
1804
|
+
* ```typescript
|
|
1805
|
+
* await this.auth.linkSocialAccount('google', code, state);
|
|
1806
|
+
* ```
|
|
1733
1807
|
*/
|
|
1734
|
-
linkSocialAccount(provider, code, state) {
|
|
1735
|
-
return
|
|
1808
|
+
async linkSocialAccount(provider, code, state) {
|
|
1809
|
+
return this.client.linkSocialAccount(provider, code, state);
|
|
1736
1810
|
}
|
|
1737
1811
|
/**
|
|
1738
1812
|
* Unlink social account.
|
|
1739
1813
|
*
|
|
1740
1814
|
* @param provider - Social provider to unlink
|
|
1741
|
-
* @returns
|
|
1815
|
+
* @returns Promise with success message
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```typescript
|
|
1819
|
+
* await this.auth.unlinkSocialAccount('google');
|
|
1820
|
+
* ```
|
|
1742
1821
|
*/
|
|
1743
|
-
unlinkSocialAccount(provider) {
|
|
1744
|
-
return
|
|
1822
|
+
async unlinkSocialAccount(provider) {
|
|
1823
|
+
return this.client.unlinkSocialAccount(provider);
|
|
1745
1824
|
}
|
|
1746
1825
|
// ============================================================================
|
|
1747
1826
|
// MFA Management
|
|
@@ -1749,27 +1828,43 @@ var AuthService = class {
|
|
|
1749
1828
|
/**
|
|
1750
1829
|
* Get MFA status for the current user.
|
|
1751
1830
|
*
|
|
1752
|
-
* @returns
|
|
1831
|
+
* @returns Promise of MFA status
|
|
1832
|
+
*
|
|
1833
|
+
* @example
|
|
1834
|
+
* ```typescript
|
|
1835
|
+
* const status = await this.auth.getMfaStatus();
|
|
1836
|
+
* console.log('MFA enabled:', status.enabled);
|
|
1837
|
+
* ```
|
|
1753
1838
|
*/
|
|
1754
|
-
getMfaStatus() {
|
|
1755
|
-
return
|
|
1839
|
+
async getMfaStatus() {
|
|
1840
|
+
return this.client.getMfaStatus();
|
|
1756
1841
|
}
|
|
1757
1842
|
/**
|
|
1758
1843
|
* Get MFA devices for the current user.
|
|
1759
1844
|
*
|
|
1760
|
-
* @returns
|
|
1845
|
+
* @returns Promise of MFA devices array
|
|
1846
|
+
*
|
|
1847
|
+
* @example
|
|
1848
|
+
* ```typescript
|
|
1849
|
+
* const devices = await this.auth.getMfaDevices();
|
|
1850
|
+
* ```
|
|
1761
1851
|
*/
|
|
1762
|
-
getMfaDevices() {
|
|
1763
|
-
return
|
|
1852
|
+
async getMfaDevices() {
|
|
1853
|
+
return this.client.getMfaDevices();
|
|
1764
1854
|
}
|
|
1765
1855
|
/**
|
|
1766
1856
|
* Setup MFA device (authenticated user).
|
|
1767
1857
|
*
|
|
1768
1858
|
* @param method - MFA method to set up
|
|
1769
|
-
* @returns
|
|
1859
|
+
* @returns Promise of setup data
|
|
1860
|
+
*
|
|
1861
|
+
* @example
|
|
1862
|
+
* ```typescript
|
|
1863
|
+
* const setupData = await this.auth.setupMfaDevice('totp');
|
|
1864
|
+
* ```
|
|
1770
1865
|
*/
|
|
1771
|
-
setupMfaDevice(method) {
|
|
1772
|
-
return
|
|
1866
|
+
async setupMfaDevice(method) {
|
|
1867
|
+
return this.client.setupMfaDevice(method);
|
|
1773
1868
|
}
|
|
1774
1869
|
/**
|
|
1775
1870
|
* Verify MFA setup (authenticated user).
|
|
@@ -1777,46 +1872,72 @@ var AuthService = class {
|
|
|
1777
1872
|
* @param method - MFA method
|
|
1778
1873
|
* @param setupData - Setup data from setupMfaDevice
|
|
1779
1874
|
* @param deviceName - Optional device name
|
|
1780
|
-
* @returns
|
|
1875
|
+
* @returns Promise with device ID
|
|
1876
|
+
*
|
|
1877
|
+
* @example
|
|
1878
|
+
* ```typescript
|
|
1879
|
+
* const result = await this.auth.verifyMfaSetup('totp', { code: '123456' }, 'My Phone');
|
|
1880
|
+
* ```
|
|
1781
1881
|
*/
|
|
1782
|
-
verifyMfaSetup(method, setupData, deviceName) {
|
|
1783
|
-
return
|
|
1882
|
+
async verifyMfaSetup(method, setupData, deviceName) {
|
|
1883
|
+
return this.client.verifyMfaSetup(method, setupData, deviceName);
|
|
1784
1884
|
}
|
|
1785
1885
|
/**
|
|
1786
1886
|
* Remove MFA device.
|
|
1787
1887
|
*
|
|
1788
1888
|
* @param method - MFA method to remove
|
|
1789
|
-
* @returns
|
|
1889
|
+
* @returns Promise with success message
|
|
1890
|
+
*
|
|
1891
|
+
* @example
|
|
1892
|
+
* ```typescript
|
|
1893
|
+
* await this.auth.removeMfaDevice('sms');
|
|
1894
|
+
* ```
|
|
1790
1895
|
*/
|
|
1791
|
-
removeMfaDevice(method) {
|
|
1792
|
-
return
|
|
1896
|
+
async removeMfaDevice(method) {
|
|
1897
|
+
return this.client.removeMfaDevice(method);
|
|
1793
1898
|
}
|
|
1794
1899
|
/**
|
|
1795
1900
|
* Set preferred MFA method.
|
|
1796
1901
|
*
|
|
1797
1902
|
* @param method - Device method to set as preferred ('totp', 'sms', 'email', or 'passkey')
|
|
1798
|
-
* @returns
|
|
1903
|
+
* @returns Promise with success message
|
|
1904
|
+
*
|
|
1905
|
+
* @example
|
|
1906
|
+
* ```typescript
|
|
1907
|
+
* await this.auth.setPreferredMfaMethod('totp');
|
|
1908
|
+
* ```
|
|
1799
1909
|
*/
|
|
1800
|
-
setPreferredMfaMethod(method) {
|
|
1801
|
-
return
|
|
1910
|
+
async setPreferredMfaMethod(method) {
|
|
1911
|
+
return this.client.setPreferredMfaMethod(method);
|
|
1802
1912
|
}
|
|
1803
1913
|
/**
|
|
1804
1914
|
* Generate backup codes.
|
|
1805
1915
|
*
|
|
1806
|
-
* @returns
|
|
1916
|
+
* @returns Promise of backup codes array
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```typescript
|
|
1920
|
+
* const codes = await this.auth.generateBackupCodes();
|
|
1921
|
+
* console.log('Backup codes:', codes);
|
|
1922
|
+
* ```
|
|
1807
1923
|
*/
|
|
1808
|
-
generateBackupCodes() {
|
|
1809
|
-
return
|
|
1924
|
+
async generateBackupCodes() {
|
|
1925
|
+
return this.client.generateBackupCodes();
|
|
1810
1926
|
}
|
|
1811
1927
|
/**
|
|
1812
1928
|
* Set MFA exemption (admin/test scenarios).
|
|
1813
1929
|
*
|
|
1814
1930
|
* @param exempt - Whether to exempt user from MFA
|
|
1815
1931
|
* @param reason - Optional reason for exemption
|
|
1816
|
-
* @returns
|
|
1932
|
+
* @returns Promise that resolves when exemption is set
|
|
1933
|
+
*
|
|
1934
|
+
* @example
|
|
1935
|
+
* ```typescript
|
|
1936
|
+
* await this.auth.setMfaExemption(true, 'Test account');
|
|
1937
|
+
* ```
|
|
1817
1938
|
*/
|
|
1818
|
-
setMfaExemption(exempt, reason) {
|
|
1819
|
-
return
|
|
1939
|
+
async setMfaExemption(exempt, reason) {
|
|
1940
|
+
return this.client.setMfaExemption(exempt, reason);
|
|
1820
1941
|
}
|
|
1821
1942
|
// ============================================================================
|
|
1822
1943
|
// Device Trust
|
|
@@ -1824,18 +1945,32 @@ var AuthService = class {
|
|
|
1824
1945
|
/**
|
|
1825
1946
|
* Trust current device.
|
|
1826
1947
|
*
|
|
1827
|
-
* @returns
|
|
1948
|
+
* @returns Promise with device token
|
|
1949
|
+
*
|
|
1950
|
+
* @example
|
|
1951
|
+
* ```typescript
|
|
1952
|
+
* const result = await this.auth.trustDevice();
|
|
1953
|
+
* console.log('Device trusted:', result.deviceToken);
|
|
1954
|
+
* ```
|
|
1828
1955
|
*/
|
|
1829
|
-
trustDevice() {
|
|
1830
|
-
return
|
|
1956
|
+
async trustDevice() {
|
|
1957
|
+
return this.client.trustDevice();
|
|
1831
1958
|
}
|
|
1832
1959
|
/**
|
|
1833
1960
|
* Check if the current device is trusted.
|
|
1834
1961
|
*
|
|
1835
|
-
* @returns
|
|
1962
|
+
* @returns Promise with trusted status
|
|
1963
|
+
*
|
|
1964
|
+
* @example
|
|
1965
|
+
* ```typescript
|
|
1966
|
+
* const result = await this.auth.isTrustedDevice();
|
|
1967
|
+
* if (result.trusted) {
|
|
1968
|
+
* console.log('This device is trusted');
|
|
1969
|
+
* }
|
|
1970
|
+
* ```
|
|
1836
1971
|
*/
|
|
1837
|
-
isTrustedDevice() {
|
|
1838
|
-
return
|
|
1972
|
+
async isTrustedDevice() {
|
|
1973
|
+
return this.client.isTrustedDevice();
|
|
1839
1974
|
}
|
|
1840
1975
|
// ============================================================================
|
|
1841
1976
|
// Audit History
|
|
@@ -1844,17 +1979,20 @@ var AuthService = class {
|
|
|
1844
1979
|
* Get paginated audit history for the current user.
|
|
1845
1980
|
*
|
|
1846
1981
|
* @param params - Query parameters for filtering and pagination
|
|
1847
|
-
* @returns
|
|
1982
|
+
* @returns Promise of audit history response
|
|
1848
1983
|
*
|
|
1849
1984
|
* @example
|
|
1850
1985
|
* ```typescript
|
|
1851
|
-
* this.auth.getAuditHistory({
|
|
1852
|
-
*
|
|
1986
|
+
* const history = await this.auth.getAuditHistory({
|
|
1987
|
+
* page: 1,
|
|
1988
|
+
* limit: 20,
|
|
1989
|
+
* eventType: 'LOGIN_SUCCESS'
|
|
1853
1990
|
* });
|
|
1991
|
+
* console.log('Audit history:', history);
|
|
1854
1992
|
* ```
|
|
1855
1993
|
*/
|
|
1856
|
-
getAuditHistory(params) {
|
|
1857
|
-
return
|
|
1994
|
+
async getAuditHistory(params) {
|
|
1995
|
+
return this.client.getAuditHistory(params);
|
|
1858
1996
|
}
|
|
1859
1997
|
// ============================================================================
|
|
1860
1998
|
// Escape Hatch
|
|
@@ -1862,7 +2000,7 @@ var AuthService = class {
|
|
|
1862
2000
|
/**
|
|
1863
2001
|
* Expose underlying NAuthClient for advanced scenarios.
|
|
1864
2002
|
*
|
|
1865
|
-
* @deprecated All core functionality is now exposed directly on AuthService as
|
|
2003
|
+
* @deprecated All core functionality is now exposed directly on AuthService as Promises.
|
|
1866
2004
|
* Use the direct methods on AuthService instead (e.g., `auth.changePassword()` instead of `auth.getClient().changePassword()`).
|
|
1867
2005
|
* This method is kept for backward compatibility only and may be removed in a future version.
|
|
1868
2006
|
*
|
|
@@ -1873,8 +2011,8 @@ var AuthService = class {
|
|
|
1873
2011
|
* // Deprecated - use direct methods instead
|
|
1874
2012
|
* const status = await this.auth.getClient().getMfaStatus();
|
|
1875
2013
|
*
|
|
1876
|
-
* // Preferred - use
|
|
1877
|
-
* this.auth.getMfaStatus()
|
|
2014
|
+
* // Preferred - use direct methods
|
|
2015
|
+
* const status = await this.auth.getMfaStatus();
|
|
1878
2016
|
* ```
|
|
1879
2017
|
*/
|
|
1880
2018
|
getClient() {
|
|
@@ -1927,7 +2065,7 @@ import { inject as inject3, PLATFORM_ID } from "@angular/core";
|
|
|
1927
2065
|
import { isPlatformBrowser } from "@angular/common";
|
|
1928
2066
|
import { HttpClient as HttpClient2, HttpErrorResponse as HttpErrorResponse2 } from "@angular/common/http";
|
|
1929
2067
|
import { Router } from "@angular/router";
|
|
1930
|
-
import { catchError, switchMap, throwError, filter as filter2, take, BehaviorSubject as BehaviorSubject2, from
|
|
2068
|
+
import { catchError, switchMap, throwError, filter as filter2, take, BehaviorSubject as BehaviorSubject2, from } from "rxjs";
|
|
1931
2069
|
var isRefreshing = false;
|
|
1932
2070
|
var refreshTokenSubject = new BehaviorSubject2(null);
|
|
1933
2071
|
var retriedRequests = /* @__PURE__ */ new WeakSet();
|
|
@@ -1985,7 +2123,7 @@ var authInterceptor = /* @__PURE__ */ __name((req, next) => {
|
|
|
1985
2123
|
if (config.debug) {
|
|
1986
2124
|
console.warn("[nauth-interceptor] Starting refresh...");
|
|
1987
2125
|
}
|
|
1988
|
-
const refresh$ = tokenDelivery === "cookies" ? http.post(refreshUrl, {}, { withCredentials: true }) :
|
|
2126
|
+
const refresh$ = tokenDelivery === "cookies" ? http.post(refreshUrl, {}, { withCredentials: true }) : from(authService.refresh());
|
|
1989
2127
|
return refresh$.pipe(
|
|
1990
2128
|
switchMap((response) => {
|
|
1991
2129
|
if (config.debug) {
|
|
@@ -2113,7 +2251,7 @@ var socialRedirectCallbackGuard = /* @__PURE__ */ __name(async () => {
|
|
|
2113
2251
|
}
|
|
2114
2252
|
if (!exchangeToken) {
|
|
2115
2253
|
try {
|
|
2116
|
-
await auth.
|
|
2254
|
+
await auth.getProfile();
|
|
2117
2255
|
} catch {
|
|
2118
2256
|
const errorUrl = config.redirects?.oauthError || "/login";
|
|
2119
2257
|
window.location.replace(errorUrl);
|
|
@@ -2123,7 +2261,7 @@ var socialRedirectCallbackGuard = /* @__PURE__ */ __name(async () => {
|
|
|
2123
2261
|
window.location.replace(successUrl2);
|
|
2124
2262
|
return false;
|
|
2125
2263
|
}
|
|
2126
|
-
const response = await auth.
|
|
2264
|
+
const response = await auth.exchangeSocialRedirect(exchangeToken);
|
|
2127
2265
|
if (response.challengeName) {
|
|
2128
2266
|
const challengeBase = config.redirects?.challengeBase || "/auth/challenge";
|
|
2129
2267
|
const challengeRoute = response.challengeName.toLowerCase().replace(/_/g, "-");
|