@autional/shared 0.1.0-rc.45 → 0.1.0-rc.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/package.json
CHANGED
|
@@ -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
|
+
});
|
package/src/auth/oauth-login.ts
CHANGED
|
@@ -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:
|
|
125
|
+
scope: OAUTH_LOGIN_SCOPES,
|
|
115
126
|
};
|
|
116
127
|
}
|
|
117
128
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// GENERATED FILE — DO NOT EDIT.
|
|
2
2
|
// Source: contracts/errors.semantics.json(@autional/shared 仓内镜像,源 = service-core base/error/testdata/errors.semantics.json)
|
|
3
3
|
// Regenerate: pnpm gen:errors · Verify: pnpm gen:errors:check
|
|
4
|
-
// rows:
|
|
4
|
+
// rows: 798 · source sha256: e82f038da18dc0935623718a7516ede07d741ed071275aad4ca1610db00a8d5d
|
|
5
5
|
//
|
|
6
6
|
// 单一真源链:service-core/base/error/semantics.go(Go)→ errors.semantics.json → 本文件。
|
|
7
7
|
// ⚠️ 禁止在本文件或页面里手抄错误码分支:请消费 ERROR_SEMANTICS / UNPROVISIONED_CODES。
|
|
@@ -374,11 +374,15 @@ export const ERROR_SEMANTICS: Readonly<Record<number, ErrorSemantics>> = {
|
|
|
374
374
|
61000408: { code: 61000408, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000408' },
|
|
375
375
|
61000409: { code: 61000409, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', name: 'MFA_CODE_ALREADY_USED', retryable: false, docsPath: '/errors/61000409' },
|
|
376
376
|
61000410: { code: 61000410, httpStatus: 429, class: 'limit', absence: '', uiObservation: 'rate_limited', name: 'MFA_ATTEMPTS_THROTTLED', retryable: true, docsPath: '/errors/61000410' },
|
|
377
|
+
61000411: { code: 61000411, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'forbidden', name: 'MFA_AUTHENTICATOR_DISABLED', retryable: false, docsPath: '/errors/61000411' },
|
|
377
378
|
61000501: { code: 61000501, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000501' },
|
|
378
379
|
61000502: { code: 61000502, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000502' },
|
|
379
380
|
61000601: { code: 61000601, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000601' },
|
|
380
381
|
61000701: { code: 61000701, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000701' },
|
|
381
382
|
61000702: { code: 61000702, httpStatus: 500, class: 'internal', absence: '', uiObservation: 'unexpected', retryable: false, docsPath: '/errors/61000702' },
|
|
383
|
+
61000703: { code: 61000703, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000703' },
|
|
384
|
+
61000704: { code: 61000704, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000704' },
|
|
385
|
+
61000705: { code: 61000705, httpStatus: 503, class: 'unavailable', absence: '', uiObservation: 'transient', retryable: true, docsPath: '/errors/61000705' },
|
|
382
386
|
61000801: { code: 61000801, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000801' },
|
|
383
387
|
61000802: { code: 61000802, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000802' },
|
|
384
388
|
61000803: { code: 61000803, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000803' },
|
|
@@ -671,6 +675,8 @@ export const ERROR_SEMANTICS: Readonly<Record<number, ErrorSemantics>> = {
|
|
|
671
675
|
61100021: { code: 61100021, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61100021' },
|
|
672
676
|
61100022: { code: 61100022, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61100022' },
|
|
673
677
|
61100023: { code: 61100023, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61100023' },
|
|
678
|
+
61100024: { code: 61100024, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61100024' },
|
|
679
|
+
61100025: { code: 61100025, httpStatus: 409, class: 'conflict', absence: '', uiObservation: 'conflict', retryable: false, docsPath: '/errors/61100025' },
|
|
674
680
|
61110002: { code: 61110002, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61110002' },
|
|
675
681
|
61110003: { code: 61110003, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'forbidden', retryable: false, docsPath: '/errors/61110003' },
|
|
676
682
|
61110004: { code: 61110004, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61110004' },
|
|
@@ -853,8 +859,8 @@ export const UNPROVISIONED_CODES: ReadonlySet<number> = new Set([]);
|
|
|
853
859
|
export const EMPTY_STATE_CODES: ReadonlySet<number> = new Set([]);
|
|
854
860
|
|
|
855
861
|
export const ERROR_SEMANTICS_META = {
|
|
856
|
-
rowCount:
|
|
857
|
-
sourceSha256: '
|
|
862
|
+
rowCount: 798,
|
|
863
|
+
sourceSha256: 'e82f038da18dc0935623718a7516ede07d741ed071275aad4ca1610db00a8d5d',
|
|
858
864
|
} as const;
|
|
859
865
|
|
|
860
866
|
/** 具名错误码常量(契约 name → code)。页面只消费常量,不写数字字面量。 */
|
|
@@ -865,6 +871,7 @@ export const ERROR_CODES = {
|
|
|
865
871
|
MFA_CHALLENGE_ATTEMPTS_EXCEEDED: 61000405,
|
|
866
872
|
MFA_CODE_ALREADY_USED: 61000409,
|
|
867
873
|
MFA_ATTEMPTS_THROTTLED: 61000410,
|
|
874
|
+
MFA_AUTHENTICATOR_DISABLED: 61000411,
|
|
868
875
|
} as const;
|
|
869
876
|
|
|
870
877
|
export type ErrorCodeName = keyof typeof ERROR_CODES;
|