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