kauth-sdk-node 0.0.16 → 0.0.1752042724-dev.0
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/authenticator/authenticator.d.ts +14 -4
- package/dist/authenticator/authenticator.js +51 -5
- package/dist/authenticator/base.d.ts +35 -0
- package/dist/authenticator/base.js +20 -1
- package/dist/authenticator/google.js +14 -0
- package/dist/authenticator/index.d.ts +3 -3
- package/dist/authenticator/index.js +6 -0
- package/dist/authenticator/manager.d.ts +8 -0
- package/dist/authenticator/manager.js +64 -8
- package/dist/authenticator/miniprogram.d.ts +15 -0
- package/dist/authenticator/miniprogram.js +20 -0
- package/dist/authenticator/mozi.js +14 -0
- package/dist/authenticator/provider.d.ts +18 -5
- package/dist/authenticator/provider.js +55 -5
- package/dist/authorizer/index.d.ts +1 -0
- package/dist/authorizer/index.js +5 -0
- package/dist/authorizer/permission.d.ts +9 -0
- package/dist/authorizer/permission.js +51 -0
- package/dist/common/config/config.d.ts +31 -4
- package/dist/common/constant/http.d.ts +46 -0
- package/dist/common/constant/http.js +48 -1
- package/dist/common/http/kauth.d.ts +62 -14
- package/dist/common/http/kauth.js +199 -8
- package/dist/common/http/kflow.d.ts +14 -6
- package/dist/common/http/kflow.js +35 -4
- package/dist/common/http/request/kauth.d.ts +141 -0
- package/dist/common/http/request/kauth.js +5 -0
- package/dist/common/http/request/kflow.d.ts +22 -3
- package/dist/common/http/response/kauth.d.ts +56 -2
- package/dist/common/http/response/kauth.js +1 -1
- package/dist/common/http/tool/marmot.d.ts +26 -15
- package/dist/common/http/tool/marmot.js +92 -28
- package/dist/common/util/converter/permission.d.ts +12 -0
- package/dist/common/util/converter/permission.js +36 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +31 -0
- package/package.json +31 -12
- package/CHANGELOG.md +0 -40
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ParsedUrlQueryInput } from 'querystring';
|
|
2
|
+
import { MarmotOptions, MarmotPagination } from '../tool/marmot';
|
|
3
|
+
export declare const NotFilteredByAnyRoles: any;
|
|
4
|
+
export declare const FilteredByGlobalRoles: any;
|
|
5
|
+
export interface KauthAuthenticateRequest extends ParsedUrlQueryInput, MarmotOptions {
|
|
6
|
+
code: string;
|
|
7
|
+
redirect_uri: string;
|
|
8
|
+
}
|
|
9
|
+
export interface KauthBindRequest extends ParsedUrlQueryInput, MarmotOptions {
|
|
10
|
+
user_id: number;
|
|
11
|
+
code: string;
|
|
12
|
+
redirect_uri: string;
|
|
13
|
+
}
|
|
14
|
+
export interface KauthCreatePermissionRequest extends MarmotOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
extend_value: string;
|
|
17
|
+
}
|
|
18
|
+
export interface KauthBindRoleByPermissionRequest extends MarmotOptions {
|
|
19
|
+
role_id: number;
|
|
20
|
+
permission_id: number;
|
|
21
|
+
}
|
|
22
|
+
export interface KauthUnbindRoleByPermissionRequest extends MarmotOptions {
|
|
23
|
+
role_id: number;
|
|
24
|
+
permission_id: number;
|
|
25
|
+
}
|
|
26
|
+
export interface KauthCreateRoleRequest extends MarmotOptions {
|
|
27
|
+
name: string;
|
|
28
|
+
extend_value: string;
|
|
29
|
+
}
|
|
30
|
+
export interface KauthBindUserByRoleRequest extends MarmotOptions {
|
|
31
|
+
user_id: number;
|
|
32
|
+
role_id: number;
|
|
33
|
+
}
|
|
34
|
+
export interface KauthUnbindUserByRoleRequest extends MarmotOptions {
|
|
35
|
+
user_id: number;
|
|
36
|
+
role_id: number;
|
|
37
|
+
}
|
|
38
|
+
export interface KauthCreateRolesByPermissionsAndUsersRequest extends MarmotOptions {
|
|
39
|
+
roles: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
extend_value: string;
|
|
42
|
+
permissions: Array<{
|
|
43
|
+
name: string;
|
|
44
|
+
type?: number;
|
|
45
|
+
extend_value: string;
|
|
46
|
+
}>;
|
|
47
|
+
users?: Array<{
|
|
48
|
+
id: number;
|
|
49
|
+
}>;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
export interface KauthBindUserByRolesRequest extends MarmotOptions {
|
|
53
|
+
id: number;
|
|
54
|
+
roles: Array<{
|
|
55
|
+
id: number;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
export interface KauthBindUserByRoleNamesAndExtendValueRequest extends MarmotOptions {
|
|
59
|
+
id: number;
|
|
60
|
+
roles: Array<{
|
|
61
|
+
id: number;
|
|
62
|
+
}>;
|
|
63
|
+
range: {
|
|
64
|
+
role_names: string[];
|
|
65
|
+
role_extend_value: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface KauthBindUserByRolesAndExtendValueRequest extends MarmotOptions {
|
|
69
|
+
id: number;
|
|
70
|
+
status?: number;
|
|
71
|
+
roles: Array<{
|
|
72
|
+
id: number;
|
|
73
|
+
}>;
|
|
74
|
+
role_extend_value: string;
|
|
75
|
+
}
|
|
76
|
+
export interface KauthBindUsersByRoleNameAndExtendValueRequest extends MarmotOptions {
|
|
77
|
+
users: Array<{
|
|
78
|
+
id: number;
|
|
79
|
+
}>;
|
|
80
|
+
role_name: string;
|
|
81
|
+
role_extend_value: string;
|
|
82
|
+
}
|
|
83
|
+
export interface KauthBindRoleByPermissionsRequest extends MarmotOptions {
|
|
84
|
+
id: number;
|
|
85
|
+
permissions: Array<{
|
|
86
|
+
id: number;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
export interface KauthUpdateRolesWithPermissionsRequest extends MarmotOptions {
|
|
90
|
+
roles: Array<{
|
|
91
|
+
name: string;
|
|
92
|
+
extend_value: string;
|
|
93
|
+
permissions: Array<{
|
|
94
|
+
name: string;
|
|
95
|
+
type?: number;
|
|
96
|
+
extend_value: string;
|
|
97
|
+
}>;
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
100
|
+
export interface KauthBindRoleWithUsersRequest extends MarmotOptions {
|
|
101
|
+
id: number;
|
|
102
|
+
users: Array<{
|
|
103
|
+
id: number;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
export interface KauthSearchUsersWithUserAccountsAndRoleRequest extends MarmotOptions {
|
|
107
|
+
name?: string;
|
|
108
|
+
role_name?: string;
|
|
109
|
+
role_extend_value: typeof NotFilteredByAnyRoles | typeof FilteredByGlobalRoles | string;
|
|
110
|
+
pagination: Partial<MarmotPagination>;
|
|
111
|
+
}
|
|
112
|
+
export interface KauthCreatePreAuthorizationRequest extends MarmotOptions {
|
|
113
|
+
authorizerId: number;
|
|
114
|
+
roleType: string;
|
|
115
|
+
roleName: string;
|
|
116
|
+
roleExtendValue: string;
|
|
117
|
+
callback: string;
|
|
118
|
+
authorizeeTargets?: Array<{
|
|
119
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
120
|
+
target: string;
|
|
121
|
+
}>;
|
|
122
|
+
expiredAt?: Date;
|
|
123
|
+
count?: number;
|
|
124
|
+
oldTimeUserAllowed?: boolean;
|
|
125
|
+
}
|
|
126
|
+
export interface RefreshPreAuthorizatioRequest extends MarmotOptions {
|
|
127
|
+
id: number;
|
|
128
|
+
description?: string;
|
|
129
|
+
}
|
|
130
|
+
export interface GetPreAuthorizationRequest extends MarmotOptions {
|
|
131
|
+
roleType: string;
|
|
132
|
+
roleName: string;
|
|
133
|
+
roleExtendValue?: string;
|
|
134
|
+
token?: string;
|
|
135
|
+
}
|
|
136
|
+
export interface ProcessPreAuthorizatioRequest extends MarmotOptions {
|
|
137
|
+
token: string;
|
|
138
|
+
userId: number;
|
|
139
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
140
|
+
target: string;
|
|
141
|
+
}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import { MarmotOptions } from
|
|
1
|
+
import { MarmotOptions } from '../tool/marmot';
|
|
2
|
+
export interface KflowCreateGraphProcessRequest extends MarmotOptions {
|
|
3
|
+
key: string;
|
|
4
|
+
map: any;
|
|
5
|
+
features: any;
|
|
6
|
+
traceConsumers?: any;
|
|
7
|
+
}
|
|
8
|
+
export interface KflowCompleteGraphServiceTaskRequest extends MarmotOptions {
|
|
9
|
+
taskId: string;
|
|
10
|
+
instanceId: string;
|
|
11
|
+
map: Object;
|
|
12
|
+
}
|
|
13
|
+
export interface KflowGetGraphStateMachineSnapshotRequest extends MarmotOptions {
|
|
14
|
+
instanceId: string;
|
|
15
|
+
}
|
|
2
16
|
export interface KflowCreateProcessRequest extends MarmotOptions {
|
|
3
17
|
key: string;
|
|
4
18
|
map: any;
|
|
5
19
|
}
|
|
6
20
|
export interface KflowCompleteTaskServiceRequest extends MarmotOptions {
|
|
7
21
|
instanceId: string;
|
|
8
|
-
assignee
|
|
9
|
-
candidateGroup
|
|
22
|
+
assignee?: string;
|
|
23
|
+
candidateGroup?: string;
|
|
10
24
|
map: Object;
|
|
11
25
|
}
|
|
26
|
+
export type ProcinstUserActionType = 'startProcessInstance' | 'nextApprovers' | 'completeTaskService';
|
|
27
|
+
export interface KflowGetProcinstUserRequest extends MarmotOptions {
|
|
28
|
+
action: ProcinstUserActionType;
|
|
29
|
+
instanceId?: string;
|
|
30
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PrimaryPrincipal } from '../../../authenticator/base';
|
|
2
|
+
import { MarmotPagination } from '../tool/marmot';
|
|
1
3
|
export declare enum KauthPrincipalStatus {
|
|
2
4
|
Normal = 0,
|
|
3
5
|
Locked = 1
|
|
@@ -49,11 +51,63 @@ export interface KauthGoogleAuthenticationInformation {
|
|
|
49
51
|
principal: KauthGooglePrincipal;
|
|
50
52
|
credential: KauthGoogleCredential;
|
|
51
53
|
}
|
|
54
|
+
export interface KauthMiniprogramPrincipal {
|
|
55
|
+
trustLoginId: string;
|
|
56
|
+
customerId: string;
|
|
57
|
+
email: string;
|
|
58
|
+
nickName: string;
|
|
59
|
+
}
|
|
60
|
+
export interface KauthMiniprogramCredential {
|
|
61
|
+
accessToken: string;
|
|
62
|
+
}
|
|
63
|
+
export interface KauthMiniprogramAuthenticationInformation {
|
|
64
|
+
primaryPrincipal: PrimaryPrincipal;
|
|
65
|
+
principal: KauthMiniprogramPrincipal;
|
|
66
|
+
credential: KauthMiniprogramCredential;
|
|
67
|
+
}
|
|
52
68
|
export interface KauthPermission {
|
|
53
69
|
id: number;
|
|
54
|
-
tenantId: number;
|
|
55
70
|
name: string;
|
|
56
71
|
type: number;
|
|
57
|
-
value: string;
|
|
58
72
|
extendValue: string;
|
|
59
73
|
}
|
|
74
|
+
export interface KauthRole {
|
|
75
|
+
id: number;
|
|
76
|
+
name: string;
|
|
77
|
+
extendValue: string;
|
|
78
|
+
}
|
|
79
|
+
export interface KauthUser {
|
|
80
|
+
id: number;
|
|
81
|
+
name: string;
|
|
82
|
+
avatar: string;
|
|
83
|
+
email: string;
|
|
84
|
+
status: number;
|
|
85
|
+
roles?: any[];
|
|
86
|
+
accounts?: any[];
|
|
87
|
+
}
|
|
88
|
+
export interface KauthPagable<T> {
|
|
89
|
+
data: T;
|
|
90
|
+
pagination: MarmotPagination;
|
|
91
|
+
}
|
|
92
|
+
export interface KauthPreAuthorization {
|
|
93
|
+
id: number;
|
|
94
|
+
tenantId: string;
|
|
95
|
+
token: string;
|
|
96
|
+
authorizerId: number;
|
|
97
|
+
authorizeeTargets?: Array<{
|
|
98
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
99
|
+
target: string;
|
|
100
|
+
}>;
|
|
101
|
+
resolvedAuthorizeeTargets: Array<{
|
|
102
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
103
|
+
id: number;
|
|
104
|
+
target: string;
|
|
105
|
+
}>;
|
|
106
|
+
expiredAt?: Date;
|
|
107
|
+
count?: number;
|
|
108
|
+
oldTimeUserAllowed?: boolean;
|
|
109
|
+
roleType: 'kauth' | string;
|
|
110
|
+
roleName: string;
|
|
111
|
+
roleExtendValue?: string;
|
|
112
|
+
callback: string;
|
|
113
|
+
}
|
|
@@ -5,4 +5,4 @@ var KauthPrincipalStatus;
|
|
|
5
5
|
(function (KauthPrincipalStatus) {
|
|
6
6
|
KauthPrincipalStatus[KauthPrincipalStatus["Normal"] = 0] = "Normal";
|
|
7
7
|
KauthPrincipalStatus[KauthPrincipalStatus["Locked"] = 1] = "Locked";
|
|
8
|
-
})(KauthPrincipalStatus
|
|
8
|
+
})(KauthPrincipalStatus || (exports.KauthPrincipalStatus = KauthPrincipalStatus = {}));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { AxiosResponse } from 'axios';
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
3
2
|
import { ParsedUrlQueryInput } from 'querystring';
|
|
4
3
|
declare enum BasicStatus {
|
|
5
4
|
OK = 0,
|
|
@@ -12,34 +11,46 @@ interface BasicReponse<T> {
|
|
|
12
11
|
body: T;
|
|
13
12
|
message: string;
|
|
14
13
|
}
|
|
14
|
+
export interface MarmotPagination {
|
|
15
|
+
size: number;
|
|
16
|
+
page: number;
|
|
17
|
+
offset: number;
|
|
18
|
+
total: number;
|
|
19
|
+
sort: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
dir: string;
|
|
22
|
+
fields: string[];
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
15
25
|
export interface MarmotOptions {
|
|
16
26
|
userId?: number;
|
|
17
27
|
timestamp?: number;
|
|
18
28
|
}
|
|
19
29
|
export declare class MarmotUtil {
|
|
20
30
|
private origin;
|
|
31
|
+
private tenantId?;
|
|
21
32
|
private accessKeyId?;
|
|
22
33
|
private accessKeySecret?;
|
|
23
34
|
private serviceName?;
|
|
24
35
|
private servicePort?;
|
|
25
36
|
private proxyMatched;
|
|
26
|
-
|
|
37
|
+
private userId?;
|
|
38
|
+
private traceId?;
|
|
39
|
+
private spanId?;
|
|
40
|
+
private traceConsumers?;
|
|
41
|
+
private authCookieName?;
|
|
42
|
+
constructor(origin: string, tenantId?: number, accessKeyId?: string, accessKeySecret?: string, serviceName?: string, servicePort?: string, authCookieName?: string);
|
|
43
|
+
setUserId(userId: string): void;
|
|
44
|
+
setTraceId(traceId: string): void;
|
|
45
|
+
setSpanId(spanId: string): void;
|
|
46
|
+
setTraceConsumers(traceConsumers: Record<string, string> | ((val: Record<string, string>) => Record<string, string>)): void;
|
|
27
47
|
get<RequestType extends ParsedUrlQueryInput | MarmotOptions, ResponseType>(path: string, params?: RequestType): Promise<ResponseType>;
|
|
28
|
-
post<RequestType extends MarmotOptions, ResponseType>(path: string, params?: RequestType): Promise<ResponseType>;
|
|
48
|
+
post<RequestType extends MarmotOptions, ResponseType>(path: string, params?: RequestType, config?: AxiosRequestConfig): Promise<ResponseType>;
|
|
29
49
|
del<RequestType extends MarmotOptions | ParsedUrlQueryInput, ResponseType>(path: string, params?: RequestType): Promise<ResponseType>;
|
|
30
50
|
resolveUri(path: string, params?: any): string;
|
|
31
|
-
resolveHeaders(method: string, uri: string,
|
|
32
|
-
'x-service-name': string;
|
|
33
|
-
'x-service-port': string;
|
|
34
|
-
'x-kauth-user-id': number;
|
|
35
|
-
authorization: string;
|
|
36
|
-
} | {
|
|
37
|
-
'x-kauth-user-id': number;
|
|
38
|
-
'x-service-name'?: undefined;
|
|
39
|
-
'x-service-port'?: undefined;
|
|
40
|
-
authorization?: undefined;
|
|
41
|
-
};
|
|
51
|
+
resolveHeaders(method: string, uri: string): Record<string, string | number>;
|
|
42
52
|
sign(method: string, path: string, accessKeySecret?: string): string;
|
|
43
53
|
format<T>(response: AxiosResponse<BasicReponse<any>>): Promise<T>;
|
|
54
|
+
private formatTraceConsumers;
|
|
44
55
|
}
|
|
45
56
|
export {};
|
|
@@ -18,35 +18,80 @@ var BasicStatus;
|
|
|
18
18
|
BasicStatus[BasicStatus["InternalServerError"] = 10500] = "InternalServerError";
|
|
19
19
|
})(BasicStatus || (BasicStatus = {}));
|
|
20
20
|
class MarmotUtil {
|
|
21
|
-
|
|
21
|
+
// 基础字段
|
|
22
|
+
origin;
|
|
23
|
+
tenantId;
|
|
24
|
+
accessKeyId;
|
|
25
|
+
accessKeySecret;
|
|
26
|
+
serviceName;
|
|
27
|
+
servicePort;
|
|
28
|
+
proxyMatched;
|
|
29
|
+
// 上下文字段
|
|
30
|
+
userId;
|
|
31
|
+
traceId;
|
|
32
|
+
spanId;
|
|
33
|
+
// 测试环境专用,链路追踪
|
|
34
|
+
traceConsumers;
|
|
35
|
+
// cookie name
|
|
36
|
+
authCookieName;
|
|
37
|
+
constructor(origin, tenantId, accessKeyId, accessKeySecret, serviceName, servicePort, authCookieName) {
|
|
22
38
|
this.origin = origin.replace(/\/+$/, '');
|
|
39
|
+
this.tenantId = tenantId;
|
|
23
40
|
this.accessKeyId = accessKeyId;
|
|
24
41
|
this.accessKeySecret = accessKeySecret;
|
|
25
42
|
this.serviceName = serviceName;
|
|
26
43
|
this.servicePort = servicePort;
|
|
27
44
|
this.proxyMatched = Boolean(accessKeyId && accessKeySecret && serviceName && servicePort);
|
|
45
|
+
this.authCookieName = authCookieName || 'authorization';
|
|
46
|
+
}
|
|
47
|
+
setUserId(userId) {
|
|
48
|
+
this.userId = userId;
|
|
49
|
+
}
|
|
50
|
+
setTraceId(traceId) {
|
|
51
|
+
this.traceId = traceId;
|
|
52
|
+
}
|
|
53
|
+
setSpanId(spanId) {
|
|
54
|
+
this.spanId = spanId;
|
|
55
|
+
}
|
|
56
|
+
setTraceConsumers(traceConsumers) {
|
|
57
|
+
if (typeof traceConsumers === 'function') {
|
|
58
|
+
this.traceConsumers = traceConsumers(this.traceConsumers || {});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.traceConsumers = traceConsumers;
|
|
62
|
+
}
|
|
28
63
|
}
|
|
29
64
|
async get(path, params) {
|
|
30
|
-
|
|
31
|
-
|
|
65
|
+
// 兼容老的写法
|
|
66
|
+
if (params && params.userId) {
|
|
67
|
+
this.setUserId(String(params.userId));
|
|
68
|
+
}
|
|
69
|
+
const uri = this.resolveUri(path, params);
|
|
32
70
|
const response = await axios_1.default.get(this.origin + uri, {
|
|
33
|
-
headers: this.resolveHeaders('GET', uri
|
|
71
|
+
headers: this.resolveHeaders('GET', uri),
|
|
34
72
|
});
|
|
35
73
|
return this.format(response);
|
|
36
74
|
}
|
|
37
|
-
async post(path, params) {
|
|
38
|
-
|
|
75
|
+
async post(path, params, config) {
|
|
76
|
+
// 兼容老的写法
|
|
77
|
+
if (params && params.userId) {
|
|
78
|
+
this.setUserId(String(params.userId));
|
|
79
|
+
}
|
|
39
80
|
const uri = this.resolveUri(path);
|
|
40
|
-
const response = await axios_1.default.post(this.origin + uri,
|
|
41
|
-
|
|
81
|
+
const response = await axios_1.default.post(this.origin + uri, params, {
|
|
82
|
+
...config,
|
|
83
|
+
headers: this.resolveHeaders('POST', uri),
|
|
42
84
|
});
|
|
43
85
|
return this.format(response);
|
|
44
86
|
}
|
|
45
87
|
async del(path, params) {
|
|
46
|
-
|
|
47
|
-
|
|
88
|
+
// 兼容老的写法
|
|
89
|
+
if (params && params.userId) {
|
|
90
|
+
this.setUserId(String(params.userId));
|
|
91
|
+
}
|
|
92
|
+
const uri = this.resolveUri(path, params);
|
|
48
93
|
const response = await axios_1.default.delete(this.origin + uri, {
|
|
49
|
-
headers: this.resolveHeaders('DELETE', uri
|
|
94
|
+
headers: this.resolveHeaders('DELETE', uri),
|
|
50
95
|
});
|
|
51
96
|
return this.format(response);
|
|
52
97
|
}
|
|
@@ -60,26 +105,37 @@ class MarmotUtil {
|
|
|
60
105
|
}
|
|
61
106
|
return `${path_1.default.normalize(path)}?${querystring_1.default.stringify(params)}`;
|
|
62
107
|
}
|
|
63
|
-
resolveHeaders(method, uri
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
108
|
+
resolveHeaders(method, uri) {
|
|
109
|
+
const headers = {};
|
|
110
|
+
if (this.userId) {
|
|
111
|
+
headers['x-kauth-user-id'] = this.userId;
|
|
112
|
+
}
|
|
113
|
+
if (this.traceId) {
|
|
114
|
+
headers['tracelog-traceid'] = this.traceId;
|
|
115
|
+
}
|
|
116
|
+
if (this.spanId) {
|
|
117
|
+
headers['tracelog-spanid'] = this.spanId;
|
|
72
118
|
}
|
|
73
|
-
|
|
74
|
-
'x-kauth-
|
|
75
|
-
}
|
|
119
|
+
if (this.traceConsumers) {
|
|
120
|
+
headers['x-kauth-trace-consumers'] = this.formatTraceConsumers(this.traceConsumers);
|
|
121
|
+
}
|
|
122
|
+
if (!this.proxyMatched) {
|
|
123
|
+
// 如果直连转发,需要传入 x-gw-tenant-id
|
|
124
|
+
if (this.tenantId) {
|
|
125
|
+
headers['x-gw-tenant-id'] = this.tenantId;
|
|
126
|
+
}
|
|
127
|
+
return headers;
|
|
128
|
+
}
|
|
129
|
+
// tenantId 包含在了 access-key-id 中
|
|
130
|
+
const signature = this.sign(method.toUpperCase(), uri, this.accessKeySecret);
|
|
131
|
+
headers['x-service-name'] = this.serviceName;
|
|
132
|
+
headers['x-service-port'] = this.servicePort;
|
|
133
|
+
headers[this.authCookieName] = `Marmot ${this.accessKeyId}:${signature}`;
|
|
134
|
+
return headers;
|
|
76
135
|
}
|
|
77
136
|
sign(method, path, accessKeySecret) {
|
|
78
137
|
const str = `method:${method.toUpperCase()},url:${path}`;
|
|
79
|
-
return crypto_1.default
|
|
80
|
-
.createHmac('sha256', accessKeySecret)
|
|
81
|
-
.update(Buffer.from(str, 'utf8'))
|
|
82
|
-
.digest('base64');
|
|
138
|
+
return crypto_1.default.createHmac('sha256', accessKeySecret).update(Buffer.from(str, 'utf8')).digest('base64');
|
|
83
139
|
}
|
|
84
140
|
async format(response) {
|
|
85
141
|
if (response.status != 200) {
|
|
@@ -89,9 +145,17 @@ class MarmotUtil {
|
|
|
89
145
|
if (json.status !== BasicStatus.OK) {
|
|
90
146
|
throw new Error(json.message);
|
|
91
147
|
}
|
|
92
|
-
return camelcase_keys_1.default(json.body, {
|
|
148
|
+
return (0, camelcase_keys_1.default)(json.body, {
|
|
93
149
|
deep: true,
|
|
94
150
|
});
|
|
95
151
|
}
|
|
152
|
+
formatTraceConsumers(traceConsumers) {
|
|
153
|
+
return Object.keys(traceConsumers)
|
|
154
|
+
.map((k) => {
|
|
155
|
+
const v = this.traceConsumers[k];
|
|
156
|
+
return `${k}:${v}`;
|
|
157
|
+
})
|
|
158
|
+
.join(',');
|
|
159
|
+
}
|
|
96
160
|
}
|
|
97
161
|
exports.MarmotUtil = MarmotUtil;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Permission {
|
|
2
|
+
name: string;
|
|
3
|
+
extendValue?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class PermissionConverter {
|
|
6
|
+
static permission2candidateGroup(permission: Permission | string): string;
|
|
7
|
+
static candidateGroup2permission(candidateGroup: string): Permission;
|
|
8
|
+
static isBase64PermissionLike(str: string): boolean;
|
|
9
|
+
static base64URLEncode(str: string): string;
|
|
10
|
+
static base64URLDecode(str: string): string;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionConverter = void 0;
|
|
4
|
+
class PermissionConverter {
|
|
5
|
+
static permission2candidateGroup(permission) {
|
|
6
|
+
if (typeof permission === 'string') {
|
|
7
|
+
return PermissionConverter.base64URLEncode(permission) + '.';
|
|
8
|
+
}
|
|
9
|
+
return (PermissionConverter.base64URLEncode(permission.name) +
|
|
10
|
+
'.' +
|
|
11
|
+
PermissionConverter.base64URLEncode(permission.extendValue));
|
|
12
|
+
}
|
|
13
|
+
static candidateGroup2permission(candidateGroup) {
|
|
14
|
+
if (PermissionConverter.isBase64PermissionLike(candidateGroup)) {
|
|
15
|
+
const parts = candidateGroup.split('.');
|
|
16
|
+
return {
|
|
17
|
+
name: PermissionConverter.base64URLDecode(parts[0]),
|
|
18
|
+
extendValue: PermissionConverter.base64URLDecode(parts[1]),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
name: candidateGroup,
|
|
23
|
+
extendValue: '',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static isBase64PermissionLike(str) {
|
|
27
|
+
return /^[^.]+\.[^.]*$/.test(str);
|
|
28
|
+
}
|
|
29
|
+
static base64URLEncode(str) {
|
|
30
|
+
return Buffer.from(str).toString('base64');
|
|
31
|
+
}
|
|
32
|
+
static base64URLDecode(str) {
|
|
33
|
+
return Buffer.from(str, 'base64').toString('utf8');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PermissionConverter = PermissionConverter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { KauthConfig } from './common/config/config';
|
|
2
2
|
export { KauthApi } from './common/http/kauth';
|
|
3
3
|
export { KflowApi } from './common/http/kflow';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export {
|
|
4
|
+
export * from './common/http/request/kauth';
|
|
5
|
+
export * from './common/http/request/kflow';
|
|
6
|
+
export { GoogleAuthenticator, MoziAuthenticator, MiniprogramAuthenticator, AuthenticationInformation, PrimaryPrincipal, JsonWebTokenSubjectProvider, JsonWebTokenAuthenticationProvider, UserAccountType, PreAuthorizationAllowed, } from './authenticator';
|
|
7
|
+
export { PermissionCore } from './authorizer';
|
|
8
|
+
export { MoziAuthenticationInformation, MoziPrincipal, MoziCredential } from './authenticator/mozi';
|
|
9
|
+
export { GoogleAuthenticationInformation, GooglePrincipal, GoogleCredential } from './authenticator/google';
|
|
10
|
+
export { MiniprogramAuthenticationInformation, MiniprogramPrincipal, MiniprogramCredential, } from './authenticator/miniprogram';
|
|
11
|
+
export { PermissionConverter } from './common/util/converter/permission';
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.PermissionConverter = exports.MiniprogramCredential = exports.MiniprogramPrincipal = exports.MiniprogramAuthenticationInformation = exports.GoogleCredential = exports.GooglePrincipal = exports.GoogleAuthenticationInformation = exports.MoziCredential = exports.MoziPrincipal = exports.MoziAuthenticationInformation = exports.PermissionCore = exports.UserAccountType = exports.JsonWebTokenAuthenticationProvider = exports.JsonWebTokenSubjectProvider = exports.PrimaryPrincipal = exports.MiniprogramAuthenticator = exports.MoziAuthenticator = exports.GoogleAuthenticator = exports.KflowApi = exports.KauthApi = void 0;
|
|
3
18
|
var kauth_1 = require("./common/http/kauth");
|
|
4
19
|
Object.defineProperty(exports, "KauthApi", { enumerable: true, get: function () { return kauth_1.KauthApi; } });
|
|
5
20
|
var kflow_1 = require("./common/http/kflow");
|
|
6
21
|
Object.defineProperty(exports, "KflowApi", { enumerable: true, get: function () { return kflow_1.KflowApi; } });
|
|
22
|
+
__exportStar(require("./common/http/request/kauth"), exports);
|
|
23
|
+
__exportStar(require("./common/http/request/kflow"), exports);
|
|
7
24
|
var authenticator_1 = require("./authenticator");
|
|
8
25
|
Object.defineProperty(exports, "GoogleAuthenticator", { enumerable: true, get: function () { return authenticator_1.GoogleAuthenticator; } });
|
|
9
26
|
Object.defineProperty(exports, "MoziAuthenticator", { enumerable: true, get: function () { return authenticator_1.MoziAuthenticator; } });
|
|
27
|
+
Object.defineProperty(exports, "MiniprogramAuthenticator", { enumerable: true, get: function () { return authenticator_1.MiniprogramAuthenticator; } });
|
|
28
|
+
Object.defineProperty(exports, "PrimaryPrincipal", { enumerable: true, get: function () { return authenticator_1.PrimaryPrincipal; } });
|
|
29
|
+
Object.defineProperty(exports, "JsonWebTokenSubjectProvider", { enumerable: true, get: function () { return authenticator_1.JsonWebTokenSubjectProvider; } });
|
|
10
30
|
Object.defineProperty(exports, "JsonWebTokenAuthenticationProvider", { enumerable: true, get: function () { return authenticator_1.JsonWebTokenAuthenticationProvider; } });
|
|
31
|
+
Object.defineProperty(exports, "UserAccountType", { enumerable: true, get: function () { return authenticator_1.UserAccountType; } });
|
|
32
|
+
var authorizer_1 = require("./authorizer");
|
|
33
|
+
Object.defineProperty(exports, "PermissionCore", { enumerable: true, get: function () { return authorizer_1.PermissionCore; } });
|
|
11
34
|
var mozi_1 = require("./authenticator/mozi");
|
|
12
35
|
Object.defineProperty(exports, "MoziAuthenticationInformation", { enumerable: true, get: function () { return mozi_1.MoziAuthenticationInformation; } });
|
|
13
36
|
Object.defineProperty(exports, "MoziPrincipal", { enumerable: true, get: function () { return mozi_1.MoziPrincipal; } });
|
|
37
|
+
Object.defineProperty(exports, "MoziCredential", { enumerable: true, get: function () { return mozi_1.MoziCredential; } });
|
|
14
38
|
var google_1 = require("./authenticator/google");
|
|
15
39
|
Object.defineProperty(exports, "GoogleAuthenticationInformation", { enumerable: true, get: function () { return google_1.GoogleAuthenticationInformation; } });
|
|
16
40
|
Object.defineProperty(exports, "GooglePrincipal", { enumerable: true, get: function () { return google_1.GooglePrincipal; } });
|
|
41
|
+
Object.defineProperty(exports, "GoogleCredential", { enumerable: true, get: function () { return google_1.GoogleCredential; } });
|
|
42
|
+
var miniprogram_1 = require("./authenticator/miniprogram");
|
|
43
|
+
Object.defineProperty(exports, "MiniprogramAuthenticationInformation", { enumerable: true, get: function () { return miniprogram_1.MiniprogramAuthenticationInformation; } });
|
|
44
|
+
Object.defineProperty(exports, "MiniprogramPrincipal", { enumerable: true, get: function () { return miniprogram_1.MiniprogramPrincipal; } });
|
|
45
|
+
Object.defineProperty(exports, "MiniprogramCredential", { enumerable: true, get: function () { return miniprogram_1.MiniprogramCredential; } });
|
|
46
|
+
var permission_1 = require("./common/util/converter/permission");
|
|
47
|
+
Object.defineProperty(exports, "PermissionConverter", { enumerable: true, get: function () { return permission_1.PermissionConverter; } });
|