@nauth-toolkit/client 0.1.18 → 0.1.22
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 +381 -166
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.mts +331 -127
- package/dist/angular/index.d.ts +331 -127
- package/dist/angular/index.mjs +380 -165
- package/dist/angular/index.mjs.map +1 -1
- package/dist/index.cjs +60 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +65 -72
- package/dist/index.d.ts +65 -72
- package/dist/index.mjs +60 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/angular/index.mjs
CHANGED
|
@@ -193,12 +193,12 @@ var defaultEndpoints = {
|
|
|
193
193
|
mfaPreferred: "/mfa/preferred-method",
|
|
194
194
|
mfaBackupCodes: "/mfa/backup-codes/generate",
|
|
195
195
|
mfaExemption: "/mfa/exemption",
|
|
196
|
-
socialAuthUrl: "/social/auth-url",
|
|
197
|
-
socialCallback: "/social/callback",
|
|
198
196
|
socialLinked: "/social/linked",
|
|
199
197
|
socialLink: "/social/link",
|
|
200
198
|
socialUnlink: "/social/unlink",
|
|
201
199
|
socialVerify: "/social/:provider/verify",
|
|
200
|
+
socialRedirectStart: "/social/:provider/redirect",
|
|
201
|
+
socialExchange: "/social/exchange",
|
|
202
202
|
trustDevice: "/trust-device",
|
|
203
203
|
isTrustedDevice: "/is-trusted-device",
|
|
204
204
|
auditHistory: "/audit/history",
|
|
@@ -350,6 +350,9 @@ var _BrowserStorage = class _BrowserStorage {
|
|
|
350
350
|
async removeItem(key) {
|
|
351
351
|
this.storage.removeItem(key);
|
|
352
352
|
}
|
|
353
|
+
async clear() {
|
|
354
|
+
this.storage.clear();
|
|
355
|
+
}
|
|
353
356
|
};
|
|
354
357
|
__name(_BrowserStorage, "BrowserStorage");
|
|
355
358
|
var BrowserStorage = _BrowserStorage;
|
|
@@ -368,6 +371,9 @@ var _InMemoryStorage = class _InMemoryStorage {
|
|
|
368
371
|
async removeItem(key) {
|
|
369
372
|
this.store.delete(key);
|
|
370
373
|
}
|
|
374
|
+
async clear() {
|
|
375
|
+
this.store.clear();
|
|
376
|
+
}
|
|
371
377
|
};
|
|
372
378
|
__name(_InMemoryStorage, "InMemoryStorage");
|
|
373
379
|
var InMemoryStorage = _InMemoryStorage;
|
|
@@ -492,9 +498,9 @@ var _FetchAdapter = class _FetchAdapter {
|
|
|
492
498
|
});
|
|
493
499
|
if (!response.ok) {
|
|
494
500
|
const errorData = typeof data === "object" && data !== null ? data : {};
|
|
495
|
-
const code = typeof errorData["code"] === "string" ? errorData
|
|
496
|
-
const message = typeof errorData["message"] === "string" ? errorData
|
|
497
|
-
const timestamp = typeof errorData["timestamp"] === "string" ? errorData
|
|
501
|
+
const code = typeof errorData["code"] === "string" ? errorData["code"] : "INTERNAL_ERROR" /* INTERNAL_ERROR */;
|
|
502
|
+
const message = typeof errorData["message"] === "string" ? errorData["message"] : `Request failed with status ${status}`;
|
|
503
|
+
const timestamp = typeof errorData["timestamp"] === "string" ? errorData["timestamp"] : void 0;
|
|
498
504
|
const details = errorData["details"];
|
|
499
505
|
throw new NAuthClientError(code, message, {
|
|
500
506
|
statusCode: status,
|
|
@@ -808,7 +814,9 @@ var _NAuthClient = class _NAuthClient {
|
|
|
808
814
|
*/
|
|
809
815
|
async confirmForgotPassword(identifier, code, newPassword) {
|
|
810
816
|
const payload = { identifier, code, newPassword };
|
|
811
|
-
|
|
817
|
+
const result = await this.post(this.config.endpoints.confirmForgotPassword, payload);
|
|
818
|
+
await this.clearAuthState(false);
|
|
819
|
+
return result;
|
|
812
820
|
}
|
|
813
821
|
/**
|
|
814
822
|
* Request password change (must change on next login).
|
|
@@ -918,126 +926,57 @@ var _NAuthClient = class _NAuthClient {
|
|
|
918
926
|
// Social Authentication
|
|
919
927
|
// ============================================================================
|
|
920
928
|
/**
|
|
921
|
-
* Start social OAuth flow
|
|
929
|
+
* Start redirect-first social OAuth flow (web).
|
|
930
|
+
*
|
|
931
|
+
* This performs a browser navigation to:
|
|
932
|
+
* `GET {baseUrl}/social/:provider/redirect?returnTo=...&appState=...`
|
|
922
933
|
*
|
|
923
|
-
*
|
|
924
|
-
*
|
|
934
|
+
* The backend:
|
|
935
|
+
* - generates and stores CSRF state (cluster-safe)
|
|
936
|
+
* - redirects the user to the provider
|
|
937
|
+
* - completes OAuth on callback and sets cookies (or issues an exchange token)
|
|
938
|
+
* - redirects back to `returnTo` with `appState` (and `exchangeToken` for json/hybrid)
|
|
925
939
|
*
|
|
926
940
|
* @param provider - OAuth provider ('google', 'apple', 'facebook')
|
|
927
|
-
* @param options - Optional
|
|
941
|
+
* @param options - Optional redirect options
|
|
928
942
|
*
|
|
929
943
|
* @example
|
|
930
944
|
* ```typescript
|
|
931
|
-
*
|
|
932
|
-
* await client.loginWithSocial('google');
|
|
933
|
-
*
|
|
934
|
-
* // With custom redirect URI
|
|
935
|
-
* await client.loginWithSocial('apple', {
|
|
936
|
-
* redirectUri: 'https://example.com/auth/callback'
|
|
937
|
-
* });
|
|
945
|
+
* await client.loginWithSocial('google', { returnTo: '/auth/callback', appState: '12345' });
|
|
938
946
|
* ```
|
|
939
947
|
*/
|
|
940
|
-
async loginWithSocial(provider,
|
|
948
|
+
async loginWithSocial(provider, options) {
|
|
941
949
|
this.eventEmitter.emit({ type: "oauth:started", data: { provider }, timestamp: Date.now() });
|
|
942
|
-
const { url } = await this.getSocialAuthUrl({ provider });
|
|
943
950
|
if (hasWindow()) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
* Returns null if not an OAuth callback (no provider/code params).
|
|
952
|
-
*
|
|
953
|
-
* The SDK validates the state token, completes authentication via backend,
|
|
954
|
-
* and emits appropriate events.
|
|
955
|
-
*
|
|
956
|
-
* @param urlOrParams - Optional URL string or URLSearchParams (auto-detects from window.location if not provided)
|
|
957
|
-
* @returns AuthResponse if OAuth callback detected, null otherwise
|
|
958
|
-
*
|
|
959
|
-
* @example
|
|
960
|
-
* ```typescript
|
|
961
|
-
* // Auto-detect on app init
|
|
962
|
-
* const response = await client.handleOAuthCallback();
|
|
963
|
-
* if (response) {
|
|
964
|
-
* if (response.challengeName) {
|
|
965
|
-
* router.navigate(['/challenge', response.challengeName]);
|
|
966
|
-
* } else {
|
|
967
|
-
* router.navigate(['/']); // Navigate to your app's home route
|
|
968
|
-
* }
|
|
969
|
-
* }
|
|
970
|
-
*
|
|
971
|
-
* // In callback route
|
|
972
|
-
* const response = await client.handleOAuthCallback(window.location.search);
|
|
973
|
-
* ```
|
|
974
|
-
*/
|
|
975
|
-
async handleOAuthCallback(urlOrParams) {
|
|
976
|
-
let params;
|
|
977
|
-
if (urlOrParams instanceof URLSearchParams) {
|
|
978
|
-
params = urlOrParams;
|
|
979
|
-
} else if (typeof urlOrParams === "string") {
|
|
980
|
-
params = new URLSearchParams(urlOrParams);
|
|
981
|
-
} else if (hasWindow()) {
|
|
982
|
-
params = new URLSearchParams(window.location.search);
|
|
983
|
-
} else {
|
|
984
|
-
return null;
|
|
985
|
-
}
|
|
986
|
-
const provider = params.get("provider");
|
|
987
|
-
const code = params.get("code");
|
|
988
|
-
const state = params.get("state");
|
|
989
|
-
const error = params.get("error");
|
|
990
|
-
if (!provider || !code && !error) {
|
|
991
|
-
return null;
|
|
992
|
-
}
|
|
993
|
-
this.eventEmitter.emit({ type: "oauth:callback", data: { provider }, timestamp: Date.now() });
|
|
994
|
-
try {
|
|
995
|
-
if (error) {
|
|
996
|
-
const authError = new NAuthClientError(
|
|
997
|
-
"SOCIAL_TOKEN_INVALID" /* SOCIAL_TOKEN_INVALID */,
|
|
998
|
-
params.get("error_description") || error,
|
|
999
|
-
{ details: { error, provider } }
|
|
1000
|
-
);
|
|
1001
|
-
this.eventEmitter.emit({ type: "oauth:error", data: authError, timestamp: Date.now() });
|
|
1002
|
-
throw authError;
|
|
951
|
+
const startPath = this.config.endpoints.socialRedirectStart.replace(":provider", provider);
|
|
952
|
+
const base = this.config.baseUrl.replace(/\/$/, "");
|
|
953
|
+
const startUrl = new URL(`${base}${startPath}`);
|
|
954
|
+
const returnTo = options?.returnTo ?? this.config.redirects?.success ?? "/";
|
|
955
|
+
startUrl.searchParams.set("returnTo", returnTo);
|
|
956
|
+
if (options?.action === "link") {
|
|
957
|
+
startUrl.searchParams.set("action", "link");
|
|
1003
958
|
}
|
|
1004
|
-
if (
|
|
1005
|
-
|
|
959
|
+
if (typeof options?.appState === "string" && options.appState.trim() !== "") {
|
|
960
|
+
startUrl.searchParams.set("appState", options.appState);
|
|
1006
961
|
}
|
|
1007
|
-
|
|
1008
|
-
provider,
|
|
1009
|
-
code,
|
|
1010
|
-
state
|
|
1011
|
-
});
|
|
1012
|
-
if (response.challengeName) {
|
|
1013
|
-
this.eventEmitter.emit({ type: "auth:challenge", data: response, timestamp: Date.now() });
|
|
1014
|
-
} else {
|
|
1015
|
-
this.eventEmitter.emit({ type: "auth:success", data: response, timestamp: Date.now() });
|
|
1016
|
-
}
|
|
1017
|
-
this.eventEmitter.emit({ type: "oauth:completed", data: response, timestamp: Date.now() });
|
|
1018
|
-
return response;
|
|
1019
|
-
} catch (error2) {
|
|
1020
|
-
const authError = error2 instanceof NAuthClientError ? error2 : new NAuthClientError(
|
|
1021
|
-
"SOCIAL_TOKEN_INVALID" /* SOCIAL_TOKEN_INVALID */,
|
|
1022
|
-
error2.message || "OAuth callback failed"
|
|
1023
|
-
);
|
|
1024
|
-
this.eventEmitter.emit({ type: "oauth:error", data: authError, timestamp: Date.now() });
|
|
1025
|
-
throw authError;
|
|
962
|
+
window.location.href = startUrl.toString();
|
|
1026
963
|
}
|
|
1027
964
|
}
|
|
1028
965
|
/**
|
|
1029
|
-
*
|
|
966
|
+
* Exchange an `exchangeToken` (from redirect callback URL) into an AuthResponse.
|
|
1030
967
|
*
|
|
1031
|
-
*
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* Handle social callback.
|
|
968
|
+
* Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
|
|
969
|
+
* with `exchangeToken` instead of setting cookies.
|
|
970
|
+
*
|
|
971
|
+
* @param exchangeToken - One-time exchange token from the callback URL
|
|
972
|
+
* @returns AuthResponse
|
|
1038
973
|
*/
|
|
1039
|
-
async
|
|
1040
|
-
const
|
|
974
|
+
async exchangeSocialRedirect(exchangeToken) {
|
|
975
|
+
const token = exchangeToken?.trim();
|
|
976
|
+
if (!token) {
|
|
977
|
+
throw new NAuthClientError("CHALLENGE_INVALID" /* CHALLENGE_INVALID */, "Missing exchangeToken");
|
|
978
|
+
}
|
|
979
|
+
const result = await this.post(this.config.endpoints.socialExchange, { exchangeToken: token });
|
|
1041
980
|
await this.handleAuthResponse(result);
|
|
1042
981
|
return result;
|
|
1043
982
|
}
|
|
@@ -1226,7 +1165,9 @@ var _NAuthClient = class _NAuthClient {
|
|
|
1226
1165
|
await this.setDeviceToken(response.deviceToken);
|
|
1227
1166
|
}
|
|
1228
1167
|
if (response.user) {
|
|
1229
|
-
|
|
1168
|
+
const user = response.user;
|
|
1169
|
+
user.sessionAuthMethod = response.authMethod ?? null;
|
|
1170
|
+
await this.setUser(user);
|
|
1230
1171
|
}
|
|
1231
1172
|
await this.clearChallenge();
|
|
1232
1173
|
}
|
|
@@ -1298,6 +1239,15 @@ var _NAuthClient = class _NAuthClient {
|
|
|
1298
1239
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
1299
1240
|
}
|
|
1300
1241
|
}
|
|
1242
|
+
if (this.config.tokenDelivery === "json") {
|
|
1243
|
+
try {
|
|
1244
|
+
const deviceToken = await this.config.storage.getItem(this.config.deviceTrust.storageKey);
|
|
1245
|
+
if (deviceToken) {
|
|
1246
|
+
headers[this.config.deviceTrust.headerName] = deviceToken;
|
|
1247
|
+
}
|
|
1248
|
+
} catch {
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1301
1251
|
if (this.config.tokenDelivery === "cookies" && hasWindow()) {
|
|
1302
1252
|
const csrfToken = this.getCsrfToken();
|
|
1303
1253
|
if (csrfToken) {
|
|
@@ -1546,6 +1496,22 @@ var AuthService = class {
|
|
|
1546
1496
|
refresh() {
|
|
1547
1497
|
return from(this.client.refreshTokens());
|
|
1548
1498
|
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Refresh tokens (promise-based).
|
|
1501
|
+
*
|
|
1502
|
+
* Returns a promise instead of an Observable, matching the core NAuthClient API.
|
|
1503
|
+
* Useful for async/await patterns in guards and interceptors.
|
|
1504
|
+
*
|
|
1505
|
+
* @returns Promise of TokenResponse
|
|
1506
|
+
*
|
|
1507
|
+
* @example
|
|
1508
|
+
* ```typescript
|
|
1509
|
+
* const tokens = await auth.refreshTokensPromise();
|
|
1510
|
+
* ```
|
|
1511
|
+
*/
|
|
1512
|
+
refreshTokensPromise() {
|
|
1513
|
+
return this.client.refreshTokens();
|
|
1514
|
+
}
|
|
1549
1515
|
// ============================================================================
|
|
1550
1516
|
// Account Recovery (Forgot Password)
|
|
1551
1517
|
// ============================================================================
|
|
@@ -1561,6 +1527,95 @@ var AuthService = class {
|
|
|
1561
1527
|
confirmForgotPassword(identifier, code, newPassword) {
|
|
1562
1528
|
return from(this.client.confirmForgotPassword(identifier, code, newPassword));
|
|
1563
1529
|
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Change user password (requires current password).
|
|
1532
|
+
*
|
|
1533
|
+
* @param oldPassword - Current password
|
|
1534
|
+
* @param newPassword - New password (must meet requirements)
|
|
1535
|
+
* @returns Observable that completes when password is changed
|
|
1536
|
+
*
|
|
1537
|
+
* @example
|
|
1538
|
+
* ```typescript
|
|
1539
|
+
* this.auth.changePassword('oldPassword123', 'newSecurePassword456!').subscribe({
|
|
1540
|
+
* next: () => console.log('Password changed successfully'),
|
|
1541
|
+
* error: (err) => console.error('Failed to change password:', err)
|
|
1542
|
+
* });
|
|
1543
|
+
* ```
|
|
1544
|
+
*/
|
|
1545
|
+
changePassword(oldPassword, newPassword) {
|
|
1546
|
+
return from(this.client.changePassword(oldPassword, newPassword));
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Request password change (must change on next login).
|
|
1550
|
+
*
|
|
1551
|
+
* @returns Observable that completes when request is sent
|
|
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
|
|
1563
|
+
*
|
|
1564
|
+
* @example
|
|
1565
|
+
* ```typescript
|
|
1566
|
+
* this.auth.getProfile().subscribe(user => {
|
|
1567
|
+
* console.log('User profile:', user);
|
|
1568
|
+
* });
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
getProfile() {
|
|
1572
|
+
return from(
|
|
1573
|
+
this.client.getProfile().then((user) => {
|
|
1574
|
+
this.currentUserSubject.next(user);
|
|
1575
|
+
return user;
|
|
1576
|
+
})
|
|
1577
|
+
);
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Get current user profile (promise-based).
|
|
1581
|
+
*
|
|
1582
|
+
* Returns a promise instead of an Observable, matching the core NAuthClient API.
|
|
1583
|
+
* Useful for async/await patterns in guards and interceptors.
|
|
1584
|
+
*
|
|
1585
|
+
* @returns Promise of current user profile
|
|
1586
|
+
*
|
|
1587
|
+
* @example
|
|
1588
|
+
* ```typescript
|
|
1589
|
+
* const user = await auth.getProfilePromise();
|
|
1590
|
+
* ```
|
|
1591
|
+
*/
|
|
1592
|
+
getProfilePromise() {
|
|
1593
|
+
return this.client.getProfile().then((user) => {
|
|
1594
|
+
this.currentUserSubject.next(user);
|
|
1595
|
+
return user;
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Update user profile.
|
|
1600
|
+
*
|
|
1601
|
+
* @param updates - Profile fields to update
|
|
1602
|
+
* @returns Observable of updated user profile
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* ```typescript
|
|
1606
|
+
* this.auth.updateProfile({ firstName: 'John', lastName: 'Doe' }).subscribe(user => {
|
|
1607
|
+
* console.log('Profile updated:', user);
|
|
1608
|
+
* });
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
updateProfile(updates) {
|
|
1612
|
+
return from(
|
|
1613
|
+
this.client.updateProfile(updates).then((user) => {
|
|
1614
|
+
this.currentUserSubject.next(user);
|
|
1615
|
+
return user;
|
|
1616
|
+
})
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1564
1619
|
// ============================================================================
|
|
1565
1620
|
// Challenge Flow Methods (Essential for any auth flow)
|
|
1566
1621
|
// ============================================================================
|
|
@@ -1617,26 +1672,189 @@ var AuthService = class {
|
|
|
1617
1672
|
// ============================================================================
|
|
1618
1673
|
/**
|
|
1619
1674
|
* Initiate social OAuth login flow.
|
|
1620
|
-
* Redirects to
|
|
1675
|
+
* Redirects the browser to backend `/auth/social/:provider/redirect`.
|
|
1621
1676
|
*/
|
|
1622
1677
|
loginWithSocial(provider, options) {
|
|
1623
1678
|
return this.client.loginWithSocial(provider, options);
|
|
1624
1679
|
}
|
|
1625
1680
|
/**
|
|
1626
|
-
*
|
|
1681
|
+
* Exchange an exchangeToken (from redirect callback URL) into an AuthResponse.
|
|
1682
|
+
*
|
|
1683
|
+
* Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
|
|
1684
|
+
* with `exchangeToken` instead of setting cookies.
|
|
1685
|
+
*
|
|
1686
|
+
* @param exchangeToken - One-time exchange token from the callback URL
|
|
1687
|
+
* @returns Observable of AuthResponse
|
|
1627
1688
|
*/
|
|
1628
|
-
|
|
1629
|
-
return from(
|
|
1630
|
-
this.client.getSocialAuthUrl({ provider, redirectUri })
|
|
1631
|
-
);
|
|
1689
|
+
exchangeSocialRedirect(exchangeToken) {
|
|
1690
|
+
return from(this.client.exchangeSocialRedirect(exchangeToken).then((res) => this.updateChallengeState(res)));
|
|
1632
1691
|
}
|
|
1633
1692
|
/**
|
|
1634
|
-
*
|
|
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
|
+
* @returns Promise of AuthResponse
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```typescript
|
|
1703
|
+
* const response = await auth.exchangeSocialRedirectPromise(exchangeToken);
|
|
1704
|
+
* ```
|
|
1635
1705
|
*/
|
|
1636
|
-
|
|
1637
|
-
return
|
|
1638
|
-
|
|
1639
|
-
|
|
1706
|
+
exchangeSocialRedirectPromise(exchangeToken) {
|
|
1707
|
+
return this.client.exchangeSocialRedirect(exchangeToken).then((res) => this.updateChallengeState(res));
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Verify native social token (mobile).
|
|
1711
|
+
*
|
|
1712
|
+
* @param request - Social verification request with provider and token
|
|
1713
|
+
* @returns Observable of AuthResponse
|
|
1714
|
+
*/
|
|
1715
|
+
verifyNativeSocial(request) {
|
|
1716
|
+
return from(this.client.verifyNativeSocial(request).then((res) => this.updateChallengeState(res)));
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Get linked social accounts.
|
|
1720
|
+
*
|
|
1721
|
+
* @returns Observable of linked accounts response
|
|
1722
|
+
*/
|
|
1723
|
+
getLinkedAccounts() {
|
|
1724
|
+
return from(this.client.getLinkedAccounts());
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Link social account.
|
|
1728
|
+
*
|
|
1729
|
+
* @param provider - Social provider to link
|
|
1730
|
+
* @param code - OAuth authorization code
|
|
1731
|
+
* @param state - OAuth state parameter
|
|
1732
|
+
* @returns Observable with success message
|
|
1733
|
+
*/
|
|
1734
|
+
linkSocialAccount(provider, code, state) {
|
|
1735
|
+
return from(this.client.linkSocialAccount(provider, code, state));
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Unlink social account.
|
|
1739
|
+
*
|
|
1740
|
+
* @param provider - Social provider to unlink
|
|
1741
|
+
* @returns Observable with success message
|
|
1742
|
+
*/
|
|
1743
|
+
unlinkSocialAccount(provider) {
|
|
1744
|
+
return from(this.client.unlinkSocialAccount(provider));
|
|
1745
|
+
}
|
|
1746
|
+
// ============================================================================
|
|
1747
|
+
// MFA Management
|
|
1748
|
+
// ============================================================================
|
|
1749
|
+
/**
|
|
1750
|
+
* Get MFA status for the current user.
|
|
1751
|
+
*
|
|
1752
|
+
* @returns Observable of MFA status
|
|
1753
|
+
*/
|
|
1754
|
+
getMfaStatus() {
|
|
1755
|
+
return from(this.client.getMfaStatus());
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Get MFA devices for the current user.
|
|
1759
|
+
*
|
|
1760
|
+
* @returns Observable of MFA devices array
|
|
1761
|
+
*/
|
|
1762
|
+
getMfaDevices() {
|
|
1763
|
+
return from(this.client.getMfaDevices());
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Setup MFA device (authenticated user).
|
|
1767
|
+
*
|
|
1768
|
+
* @param method - MFA method to set up
|
|
1769
|
+
* @returns Observable of setup data
|
|
1770
|
+
*/
|
|
1771
|
+
setupMfaDevice(method) {
|
|
1772
|
+
return from(this.client.setupMfaDevice(method));
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Verify MFA setup (authenticated user).
|
|
1776
|
+
*
|
|
1777
|
+
* @param method - MFA method
|
|
1778
|
+
* @param setupData - Setup data from setupMfaDevice
|
|
1779
|
+
* @param deviceName - Optional device name
|
|
1780
|
+
* @returns Observable with device ID
|
|
1781
|
+
*/
|
|
1782
|
+
verifyMfaSetup(method, setupData, deviceName) {
|
|
1783
|
+
return from(this.client.verifyMfaSetup(method, setupData, deviceName));
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Remove MFA device.
|
|
1787
|
+
*
|
|
1788
|
+
* @param method - MFA method to remove
|
|
1789
|
+
* @returns Observable with success message
|
|
1790
|
+
*/
|
|
1791
|
+
removeMfaDevice(method) {
|
|
1792
|
+
return from(this.client.removeMfaDevice(method));
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Set preferred MFA method.
|
|
1796
|
+
*
|
|
1797
|
+
* @param method - Device method to set as preferred ('totp', 'sms', 'email', or 'passkey')
|
|
1798
|
+
* @returns Observable with success message
|
|
1799
|
+
*/
|
|
1800
|
+
setPreferredMfaMethod(method) {
|
|
1801
|
+
return from(this.client.setPreferredMfaMethod(method));
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Generate backup codes.
|
|
1805
|
+
*
|
|
1806
|
+
* @returns Observable of backup codes array
|
|
1807
|
+
*/
|
|
1808
|
+
generateBackupCodes() {
|
|
1809
|
+
return from(this.client.generateBackupCodes());
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Set MFA exemption (admin/test scenarios).
|
|
1813
|
+
*
|
|
1814
|
+
* @param exempt - Whether to exempt user from MFA
|
|
1815
|
+
* @param reason - Optional reason for exemption
|
|
1816
|
+
* @returns Observable that completes when exemption is set
|
|
1817
|
+
*/
|
|
1818
|
+
setMfaExemption(exempt, reason) {
|
|
1819
|
+
return from(this.client.setMfaExemption(exempt, reason));
|
|
1820
|
+
}
|
|
1821
|
+
// ============================================================================
|
|
1822
|
+
// Device Trust
|
|
1823
|
+
// ============================================================================
|
|
1824
|
+
/**
|
|
1825
|
+
* Trust current device.
|
|
1826
|
+
*
|
|
1827
|
+
* @returns Observable with device token
|
|
1828
|
+
*/
|
|
1829
|
+
trustDevice() {
|
|
1830
|
+
return from(this.client.trustDevice());
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Check if the current device is trusted.
|
|
1834
|
+
*
|
|
1835
|
+
* @returns Observable with trusted status
|
|
1836
|
+
*/
|
|
1837
|
+
isTrustedDevice() {
|
|
1838
|
+
return from(this.client.isTrustedDevice());
|
|
1839
|
+
}
|
|
1840
|
+
// ============================================================================
|
|
1841
|
+
// Audit History
|
|
1842
|
+
// ============================================================================
|
|
1843
|
+
/**
|
|
1844
|
+
* Get paginated audit history for the current user.
|
|
1845
|
+
*
|
|
1846
|
+
* @param params - Query parameters for filtering and pagination
|
|
1847
|
+
* @returns Observable of audit history response
|
|
1848
|
+
*
|
|
1849
|
+
* @example
|
|
1850
|
+
* ```typescript
|
|
1851
|
+
* this.auth.getAuditHistory({ page: 1, limit: 20, eventType: 'LOGIN_SUCCESS' }).subscribe(history => {
|
|
1852
|
+
* console.log('Audit history:', history);
|
|
1853
|
+
* });
|
|
1854
|
+
* ```
|
|
1855
|
+
*/
|
|
1856
|
+
getAuditHistory(params) {
|
|
1857
|
+
return from(this.client.getAuditHistory(params));
|
|
1640
1858
|
}
|
|
1641
1859
|
// ============================================================================
|
|
1642
1860
|
// Escape Hatch
|
|
@@ -1644,20 +1862,19 @@ var AuthService = class {
|
|
|
1644
1862
|
/**
|
|
1645
1863
|
* Expose underlying NAuthClient for advanced scenarios.
|
|
1646
1864
|
*
|
|
1647
|
-
*
|
|
1648
|
-
*
|
|
1649
|
-
*
|
|
1650
|
-
*
|
|
1651
|
-
*
|
|
1652
|
-
* - Device trust (trustDevice)
|
|
1865
|
+
* @deprecated All core functionality is now exposed directly on AuthService as Observables.
|
|
1866
|
+
* Use the direct methods on AuthService instead (e.g., `auth.changePassword()` instead of `auth.getClient().changePassword()`).
|
|
1867
|
+
* This method is kept for backward compatibility only and may be removed in a future version.
|
|
1868
|
+
*
|
|
1869
|
+
* @returns The underlying NAuthClient instance
|
|
1653
1870
|
*
|
|
1654
1871
|
* @example
|
|
1655
1872
|
* ```typescript
|
|
1656
|
-
* //
|
|
1873
|
+
* // Deprecated - use direct methods instead
|
|
1657
1874
|
* const status = await this.auth.getClient().getMfaStatus();
|
|
1658
1875
|
*
|
|
1659
|
-
* //
|
|
1660
|
-
*
|
|
1876
|
+
* // Preferred - use Observable-based methods
|
|
1877
|
+
* this.auth.getMfaStatus().subscribe(status => ...);
|
|
1661
1878
|
* ```
|
|
1662
1879
|
*/
|
|
1663
1880
|
getClient() {
|
|
@@ -1736,12 +1953,11 @@ var authInterceptor = /* @__PURE__ */ __name((req, next) => {
|
|
|
1736
1953
|
const refreshPath = endpoints.refresh ?? "/refresh";
|
|
1737
1954
|
const loginPath = endpoints.login ?? "/login";
|
|
1738
1955
|
const signupPath = endpoints.signup ?? "/signup";
|
|
1739
|
-
const
|
|
1740
|
-
const socialCallbackPath = endpoints.socialCallback ?? "/social/callback";
|
|
1956
|
+
const socialExchangePath = endpoints.socialExchange ?? "/social/exchange";
|
|
1741
1957
|
const refreshUrl = `${baseUrl}${refreshPath}`;
|
|
1742
1958
|
const isAuthApiRequest = req.url.includes(baseUrl);
|
|
1743
1959
|
const isRefreshEndpoint = req.url.includes(refreshPath);
|
|
1744
|
-
const isPublicEndpoint = req.url.includes(loginPath) || req.url.includes(signupPath) || req.url.includes(
|
|
1960
|
+
const isPublicEndpoint = req.url.includes(loginPath) || req.url.includes(signupPath) || req.url.includes(socialExchangePath);
|
|
1745
1961
|
let authReq = req;
|
|
1746
1962
|
if (tokenDelivery === "cookies") {
|
|
1747
1963
|
authReq = authReq.clone({ withCredentials: true });
|
|
@@ -1769,7 +1985,7 @@ var authInterceptor = /* @__PURE__ */ __name((req, next) => {
|
|
|
1769
1985
|
if (config.debug) {
|
|
1770
1986
|
console.warn("[nauth-interceptor] Starting refresh...");
|
|
1771
1987
|
}
|
|
1772
|
-
const refresh$ = tokenDelivery === "cookies" ? http.post(refreshUrl, {}, { withCredentials: true }) : from2(authService.
|
|
1988
|
+
const refresh$ = tokenDelivery === "cookies" ? http.post(refreshUrl, {}, { withCredentials: true }) : from2(authService.refreshTokensPromise());
|
|
1773
1989
|
return refresh$.pipe(
|
|
1774
1990
|
switchMap((response) => {
|
|
1775
1991
|
if (config.debug) {
|
|
@@ -1876,10 +2092,10 @@ var _AuthGuard = class _AuthGuard {
|
|
|
1876
2092
|
__name(_AuthGuard, "AuthGuard");
|
|
1877
2093
|
var AuthGuard = _AuthGuard;
|
|
1878
2094
|
|
|
1879
|
-
// src/angular/
|
|
2095
|
+
// src/angular/social-redirect-callback.guard.ts
|
|
1880
2096
|
import { inject as inject5, PLATFORM_ID as PLATFORM_ID2 } from "@angular/core";
|
|
1881
2097
|
import { isPlatformBrowser as isPlatformBrowser2 } from "@angular/common";
|
|
1882
|
-
var
|
|
2098
|
+
var socialRedirectCallbackGuard = /* @__PURE__ */ __name(async () => {
|
|
1883
2099
|
const auth = inject5(AuthService);
|
|
1884
2100
|
const config = inject5(NAUTH_CLIENT_CONFIG);
|
|
1885
2101
|
const platformId = inject5(PLATFORM_ID2);
|
|
@@ -1887,38 +2103,37 @@ var oauthCallbackGuard = /* @__PURE__ */ __name(async () => {
|
|
|
1887
2103
|
if (!isBrowser) {
|
|
1888
2104
|
return false;
|
|
1889
2105
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
window.location.replace(homeUrl);
|
|
1895
|
-
return false;
|
|
1896
|
-
}
|
|
1897
|
-
if (response.challengeName) {
|
|
1898
|
-
const challengeBase = config.redirects?.challengeBase || "/auth/challenge";
|
|
1899
|
-
const challengeRoute = response.challengeName.toLowerCase().replace(/_/g, "-");
|
|
1900
|
-
const challengePath = `${challengeBase}/${challengeRoute}`;
|
|
1901
|
-
if (config.debug) {
|
|
1902
|
-
console.warn("[oauth-callback-guard] Redirecting to challenge:", challengePath);
|
|
1903
|
-
}
|
|
1904
|
-
window.location.replace(challengePath);
|
|
1905
|
-
} else {
|
|
1906
|
-
const successUrl = config.redirects?.success || "/";
|
|
1907
|
-
if (config.debug) {
|
|
1908
|
-
console.warn("[oauth-callback-guard] Redirecting to success URL:", successUrl);
|
|
1909
|
-
}
|
|
1910
|
-
window.location.replace(successUrl);
|
|
1911
|
-
}
|
|
1912
|
-
} catch (error) {
|
|
1913
|
-
console.error("[oauth-callback-guard] OAuth callback failed:", error);
|
|
2106
|
+
const params = new URLSearchParams(window.location.search);
|
|
2107
|
+
const error = params.get("error");
|
|
2108
|
+
const exchangeToken = params.get("exchangeToken");
|
|
2109
|
+
if (error) {
|
|
1914
2110
|
const errorUrl = config.redirects?.oauthError || "/login";
|
|
1915
|
-
if (config.debug) {
|
|
1916
|
-
console.warn("[oauth-callback-guard] Redirecting to error URL:", errorUrl);
|
|
1917
|
-
}
|
|
1918
2111
|
window.location.replace(errorUrl);
|
|
2112
|
+
return false;
|
|
2113
|
+
}
|
|
2114
|
+
if (!exchangeToken) {
|
|
2115
|
+
try {
|
|
2116
|
+
await auth.getProfilePromise();
|
|
2117
|
+
} catch {
|
|
2118
|
+
const errorUrl = config.redirects?.oauthError || "/login";
|
|
2119
|
+
window.location.replace(errorUrl);
|
|
2120
|
+
return false;
|
|
2121
|
+
}
|
|
2122
|
+
const successUrl2 = config.redirects?.success || "/";
|
|
2123
|
+
window.location.replace(successUrl2);
|
|
2124
|
+
return false;
|
|
2125
|
+
}
|
|
2126
|
+
const response = await auth.exchangeSocialRedirectPromise(exchangeToken);
|
|
2127
|
+
if (response.challengeName) {
|
|
2128
|
+
const challengeBase = config.redirects?.challengeBase || "/auth/challenge";
|
|
2129
|
+
const challengeRoute = response.challengeName.toLowerCase().replace(/_/g, "-");
|
|
2130
|
+
window.location.replace(`${challengeBase}/${challengeRoute}`);
|
|
2131
|
+
return false;
|
|
1919
2132
|
}
|
|
2133
|
+
const successUrl = config.redirects?.success || "/";
|
|
2134
|
+
window.location.replace(successUrl);
|
|
1920
2135
|
return false;
|
|
1921
|
-
}, "
|
|
2136
|
+
}, "socialRedirectCallbackGuard");
|
|
1922
2137
|
|
|
1923
2138
|
// src/angular/auth.module.ts
|
|
1924
2139
|
import { NgModule } from "@angular/core";
|
|
@@ -1952,6 +2167,6 @@ export {
|
|
|
1952
2167
|
NAuthModule,
|
|
1953
2168
|
authGuard,
|
|
1954
2169
|
authInterceptor,
|
|
1955
|
-
|
|
2170
|
+
socialRedirectCallbackGuard
|
|
1956
2171
|
};
|
|
1957
2172
|
//# sourceMappingURL=index.mjs.map
|