@autional/shared 0.1.0-rc.46 → 0.1.0-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autional/shared",
3
- "version": "0.1.0-rc.46",
3
+ "version": "0.1.0-rc.48",
4
4
  "description": "Autional shared layer — API client, auth, types, hooks, utils",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./src/index.ts",
@@ -0,0 +1,27 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { OAUTH_LOGIN_SCOPES } from '../oauth-login';
3
+
4
+ /**
5
+ * 回归锁:登录申请的 scope 必须覆盖平台读接口强制的要求。
6
+ *
7
+ * 2026-11-06 事故:服务端给 18 个服务加了 RequireScopes("read"),而客户端仍申请
8
+ * openid profile email offline_access ⇒ 登录成功但读接口 403(ops 控制台现场)。
9
+ */
10
+ describe('OAUTH_LOGIN_SCOPES', () => {
11
+ const scopes = OAUTH_LOGIN_SCOPES.split(' ').filter(Boolean);
12
+
13
+ it('包含平台读接口强制的 read', () => {
14
+ expect(scopes).toContain('read');
15
+ });
16
+
17
+ it('保留 OIDC / 刷新令牌必需项', () => {
18
+ for (const s of ['openid', 'profile', 'email', 'offline_access']) {
19
+ expect(scopes).toContain(s);
20
+ }
21
+ });
22
+
23
+ it('无空项、无重复', () => {
24
+ expect(OAUTH_LOGIN_SCOPES.trim()).toBe(OAUTH_LOGIN_SCOPES);
25
+ expect(new Set(scopes).size).toBe(scopes.length);
26
+ });
27
+ });
@@ -32,6 +32,17 @@ const SK = {
32
32
  CID: 'oauth_client_id',
33
33
  };
34
34
 
35
+ /**
36
+ * 第一方门户登录申请的 scope —— **单一真源**。
37
+ *
38
+ * `read` 自 2026-11-06 起是必需项:平台读接口(rbac / identity / profile 等 18 个服务
39
+ * 与网关 BFF)统一 `RequireScopes("read")`,令牌不带 `read` 会直接 403。
40
+ * 所有第一方客户端在 `oauth_clients.scopes` 里都已登记 `read`,只是必须**申请**才会进令牌。
41
+ *
42
+ * 改这里之前先确认:服务端新增的 enforce scope 必须 ⊆ 本字符串(否则登录能成、接口 403)。
43
+ */
44
+ export const OAUTH_LOGIN_SCOPES = 'openid profile email offline_access read';
45
+
35
46
  export interface OAuthInitiateOptions {
36
47
  /** 「停留」取消本次跳转时回调(AUTH-03,调用方据此恢复 UI);内部已先清预置物 |
37
48
  * 与待重试定时器(AUTH-08),再次交互可全新发起。 */
@@ -111,7 +122,7 @@ function getConfig() {
111
122
  authorizeUrl: `${base}/oauth/api/v1/oauth/authorize`,
112
123
  redirectUri:
113
124
  callbackPath === '/' ? `${origin}/oauth/callback` : `${origin}${callbackPath}/oauth/callback`,
114
- scope: 'openid profile email offline_access',
125
+ scope: OAUTH_LOGIN_SCOPES,
115
126
  };
116
127
  }
117
128
 
@@ -92,6 +92,7 @@ const PORTAL_DEFAULTS: Record<string, PortalEntry> = {
92
92
  trust: { host: 'trust', base: '' },
93
93
  platform: { host: 'platform', base: '' },
94
94
  brand: { host: 'brand', base: '' },
95
+ secret: { host: 'secret', base: '' },
95
96
  };
96
97
 
97
98
  let portalConfig: Record<string, PortalEntry> | null = null;
@@ -318,6 +319,7 @@ function getAllowedRedirectOrigins(): string[] {
318
319
  'trust',
319
320
  'platform',
320
321
  'brand',
322
+ 'secret',
321
323
  ];
322
324
  return portalIds
323
325
  .map((id) => {
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
4
4
  import { renderHook, waitFor, cleanup } from '@testing-library/react';
5
5
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
6
- import { usePortalCatalog, PLATFORM_TENANT_ID } from '../usePortalCatalog';
6
+ import { usePortalCatalog, isPortalVisible, PLATFORM_TENANT_ID } from '../usePortalCatalog';
7
7
  import { useAuthStore } from '../../auth/store';
8
8
  import { apiClient } from '../../api/client';
9
9
 
@@ -299,3 +299,17 @@ describe('usePortalCatalog', () => {
299
299
  expect(result.current.portals.map((p) => p.code)).toEqual(['admin', 'platform']);
300
300
  });
301
301
  });
302
+
303
+ describe('isPortalVisible', () => {
304
+ it('secret 与 admin/security 同属管理面:member 不可见、管理面角色可见', () => {
305
+ expect(isPortalVisible('secret', { role: 'member', isPlatformMember: false })).toBe(false);
306
+ expect(isPortalVisible('secret', { role: null, isPlatformMember: false })).toBe(false);
307
+ expect(isPortalVisible('secret', { role: 'security_admin', isPlatformMember: false })).toBe(true);
308
+ expect(isPortalVisible('secret', { role: 'admin', isPlatformMember: false })).toBe(true);
309
+ });
310
+
311
+ it('其余门户不受限(叠加原则)', () => {
312
+ expect(isPortalVisible('brand', { role: null, isPlatformMember: false })).toBe(true);
313
+ expect(isPortalVisible('status', { role: 'member', isPlatformMember: false })).toBe(true);
314
+ });
315
+ });
@@ -21,7 +21,7 @@ export const ADMIN_PLANE_ROLES: readonly string[] = [
21
21
  /**
22
22
  * 门户可见性 = 入口门禁的镜像(谁能登录谁才看见):
23
23
  * - platform:仅平台租户成员
24
- * - admin / security:仅管理面角色
24
+ * - admin / security / secret:仅管理面角色
25
25
  * - 其余 code:不限制(叠加原则,未知门户不误伤)
26
26
  */
27
27
  export function isPortalVisible(
@@ -29,7 +29,7 @@ export function isPortalVisible(
29
29
  ctx: { role: string | null; isPlatformMember: boolean },
30
30
  ): boolean {
31
31
  if (code === 'platform') return ctx.isPlatformMember;
32
- if (code === 'admin' || code === 'security') {
32
+ if (code === 'admin' || code === 'security' || code === 'secret') {
33
33
  return ctx.role !== null && ADMIN_PLANE_ROLES.includes(ctx.role);
34
34
  }
35
35
  return true;