@autional/shared 0.1.0-rc.40 → 0.1.0-rc.42
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/package.json
CHANGED
|
@@ -43,6 +43,11 @@ function expiredJwt(): string {
|
|
|
43
43
|
return `eyJhbGciOiJIUzI1NiJ9.${payload}.sig`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
function liveJwt(): string {
|
|
47
|
+
const payload = btoa(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 3600 }));
|
|
48
|
+
return `eyJhbGciOiJIUzI1NiJ9.${payload}.sig`;
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
describe('U352: 预刷新成功后注入链完整性', () => {
|
|
47
52
|
beforeEach(() => {
|
|
48
53
|
captured = [];
|
|
@@ -87,3 +92,37 @@ describe('U352: 预刷新成功后注入链完整性', () => {
|
|
|
87
92
|
expect(captured[0].headers['X-Tenant-ID']).toBe('tenant-abc');
|
|
88
93
|
});
|
|
89
94
|
});
|
|
95
|
+
|
|
96
|
+
// 地址栏唯一权威(Wave 2):无 token 的公开认证入口不得被 localStorage 残留租户污染。
|
|
97
|
+
describe('无 token 不注入 X-Tenant-ID', () => {
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
captured = [];
|
|
100
|
+
installCaptureAdapter();
|
|
101
|
+
useAuthStore.getState().clearAuth();
|
|
102
|
+
useAuthStore.getState().setCurrentTenant('tenant-stale');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
afterEach(() => {
|
|
106
|
+
apiClient.defaults.adapter = originalAdapter as any;
|
|
107
|
+
vi.restoreAllMocks();
|
|
108
|
+
useAuthStore.getState().clearAuth();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('无 token:残留租户不注入 header', async () => {
|
|
112
|
+
await apiClient.get('/probe/public');
|
|
113
|
+
expect(captured[0].headers['X-Tenant-ID']).toBeUndefined();
|
|
114
|
+
expect(captured[0].headers['Authorization']).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('调用方显式 X-Tenant-ID 原样保留(不注入也不清除)', async () => {
|
|
118
|
+
await apiClient.get('/probe/public', { headers: { 'X-Tenant-ID': 'explicit-tenant' } });
|
|
119
|
+
expect(captured[0].headers['X-Tenant-ID']).toBe('explicit-tenant');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('有 token:仍注入当前租户(内部调用链回归)', async () => {
|
|
123
|
+
useAuthStore.getState().setAuth(liveJwt(), 'rt-live', { id: 'u-1', username: 'demo' } as any);
|
|
124
|
+
await apiClient.get('/probe/authed');
|
|
125
|
+
expect(captured[0].headers['X-Tenant-ID']).toBe('tenant-stale');
|
|
126
|
+
expect(String(captured[0].headers['Authorization'])).toMatch(/^Bearer /);
|
|
127
|
+
});
|
|
128
|
+
});
|
package/src/api/client.ts
CHANGED
|
@@ -35,8 +35,11 @@ function setupInterceptors(instance: AxiosInstance) {
|
|
|
35
35
|
config.headers.Authorization = `Bearer ${bearer}`;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// 无 token 的公开认证入口(登录/OAuth/QR/恢复)以地址栏租户为唯一权威:
|
|
39
|
+
// 此时 localStorage 里的 currentTenantId 可能是上次会话残留,注入会覆盖显式租户。
|
|
40
|
+
// 有 token 才注入(内部调用链沿用它);调用方显式设置的 X-Tenant-ID 不受影响。
|
|
38
41
|
const tenantId = AuthService.getCurrentTenantId();
|
|
39
|
-
if (tenantId) {
|
|
42
|
+
if (bearer && tenantId) {
|
|
40
43
|
config.headers['X-Tenant-ID'] = tenantId;
|
|
41
44
|
}
|
|
42
45
|
|
package/src/generated/api.ts
CHANGED
|
@@ -5664,8 +5664,10 @@ export async function authOauthAccounts() {
|
|
|
5664
5664
|
* 获取OAuth提供商列表
|
|
5665
5665
|
* 获取系统支持的所有OAuth登录提供者列表
|
|
5666
5666
|
*/
|
|
5667
|
-
export async function authOauthProviders(
|
|
5668
|
-
|
|
5667
|
+
export async function authOauthProviders(params?: {
|
|
5668
|
+
tenantId?: string; // 显式租户(地址栏/slug 优先于 localStorage 残留)
|
|
5669
|
+
}) {
|
|
5670
|
+
const res = await api.get(`/identity/api/v1/auth/oauth/providers`, { params });
|
|
5669
5671
|
return res.data;
|
|
5670
5672
|
}
|
|
5671
5673
|
|
|
@@ -5770,8 +5772,8 @@ export async function authQrLoginConfirmPost(data: QrLoginConfirmRequest) {
|
|
|
5770
5772
|
* 发起二维码登录
|
|
5771
5773
|
* 生成一个新的二维码登录会话,返回会话令牌和数字匹配码供用户扫描
|
|
5772
5774
|
*/
|
|
5773
|
-
export async function authQrLoginInitiatePost() {
|
|
5774
|
-
const res = await api.post(`/identity/api/v1/auth/qr-login/initiate
|
|
5775
|
+
export async function authQrLoginInitiatePost(data?: QrLoginInitiateRequest) {
|
|
5776
|
+
const res = await api.post(`/identity/api/v1/auth/qr-login/initiate`, data);
|
|
5775
5777
|
return res.data;
|
|
5776
5778
|
}
|
|
5777
5779
|
|
package/src/generated/types.ts
CHANGED
|
@@ -4726,6 +4726,7 @@ export interface CheckRoleRequest {
|
|
|
4726
4726
|
/** 检查用户名可用性请求 */
|
|
4727
4727
|
export interface CheckUsernameRequest {
|
|
4728
4728
|
username: string; // Username | @example john_doe
|
|
4729
|
+
tenantId?: string; // 目标租户(地址栏租户优先)
|
|
4729
4730
|
}
|
|
4730
4731
|
|
|
4731
4732
|
/** 检查用户名可用性结果 */
|
|
@@ -4759,6 +4760,7 @@ export interface CompleteAccountRecoveryRequest {
|
|
|
4759
4760
|
newPassword: string; // 新密码
|
|
4760
4761
|
passwordTransmission?: string; // plain|hash|symmetric|asymmetric
|
|
4761
4762
|
recoveryToken: string; // 恢复令牌
|
|
4763
|
+
tenantId?: string; // 显式租户(非空时必须与恢复令牌租户一致)
|
|
4762
4764
|
}
|
|
4763
4765
|
|
|
4764
4766
|
export interface CompleteAccountRecoveryResponse {
|
|
@@ -5655,6 +5657,10 @@ export interface QrLoginConfirmRequest {
|
|
|
5655
5657
|
token: string;
|
|
5656
5658
|
}
|
|
5657
5659
|
|
|
5660
|
+
export interface QrLoginInitiateRequest {
|
|
5661
|
+
tenantId?: string; // 显式租户(地址栏/slug 优先)
|
|
5662
|
+
}
|
|
5663
|
+
|
|
5658
5664
|
export interface QrLoginInitiateResponse {
|
|
5659
5665
|
expiresIn?: number;
|
|
5660
5666
|
numberMatching?: string;
|
|
@@ -5691,6 +5697,7 @@ export interface ReapplyRegistrationRequest {
|
|
|
5691
5697
|
email: string; // Email
|
|
5692
5698
|
invitationCode?: string; // 邀请码
|
|
5693
5699
|
reason?: string; // 申请理由
|
|
5700
|
+
tenantId?: string; // 目标租户(地址栏租户优先)
|
|
5694
5701
|
}
|
|
5695
5702
|
|
|
5696
5703
|
export interface ReapplyRegistrationResponse {
|
|
@@ -5829,6 +5836,7 @@ export interface RegisterResponse {
|
|
|
5829
5836
|
export interface RequestAccountRecoveryRequest {
|
|
5830
5837
|
identity: string; // 已知的身份标识 | @example john@example.com
|
|
5831
5838
|
method: "backup_email" | "security_qa" | "trusted_device" | "sms"; // 恢复方法
|
|
5839
|
+
tenantId?: string; // 显式租户(地址栏/slug 优先)
|
|
5832
5840
|
}
|
|
5833
5841
|
|
|
5834
5842
|
export interface RequestAccountRecoveryResponseWrapper {
|
|
@@ -6281,6 +6289,7 @@ export interface VerificationTrackingQueryResponse {
|
|
|
6281
6289
|
export interface VerifyAccountRecoveryRequest {
|
|
6282
6290
|
code: string; // 验证码
|
|
6283
6291
|
recoveryToken: string; // 恢复令牌
|
|
6292
|
+
tenantId?: string; // 显式租户(非空时必须与恢复令牌租户一致)
|
|
6284
6293
|
}
|
|
6285
6294
|
|
|
6286
6295
|
/** 验证邮箱/手机号变更 */
|