kauth-sdk-node 2.0.11-alpha.0 → 2.0.12-alpha.1
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 +3 -3
- package/dist/authenticator/authenticator.js +9 -3
- package/dist/authenticator/base.d.ts +37 -0
- package/dist/authenticator/base.js +15 -1
- package/dist/authenticator/google.d.ts +2 -1
- package/dist/authenticator/index.d.ts +1 -1
- package/dist/authenticator/index.js +1 -0
- package/dist/authenticator/miniprogram.d.ts +2 -1
- package/dist/authenticator/mozi.d.ts +2 -1
- package/dist/common/config/config.d.ts +2 -0
- package/dist/common/constant/http.d.ts +5 -0
- package/dist/common/constant/http.js +6 -1
- package/dist/common/http/kauth.d.ts +11 -2
- package/dist/common/http/kauth.js +15 -0
- package/dist/common/http/request/kauth.d.ts +28 -0
- package/dist/common/http/response/kauth.d.ts +26 -1
- package/dist/common/http/tool/marmot.js +1 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -0
- package/package.json +5 -4
|
@@ -8,21 +8,21 @@ interface Authenticator {
|
|
|
8
8
|
export declare class GoogleAuthenticator implements Authenticator {
|
|
9
9
|
private kauthApi;
|
|
10
10
|
constructor(kauthApi: KauthApi);
|
|
11
|
-
authenticate(token: string, redirectUri: string): Promise<AuthenticationInformation>;
|
|
11
|
+
authenticate(token: string, redirectUri: string, preAuthorizationToken?: string): Promise<AuthenticationInformation>;
|
|
12
12
|
bind(userId: number, token: string, redirectUri: string): Promise<void>;
|
|
13
13
|
authorizeURL(callback: string, state: string, prompt?: string): Promise<string>;
|
|
14
14
|
}
|
|
15
15
|
export declare class MoziAuthenticator implements Authenticator {
|
|
16
16
|
private kauthApi;
|
|
17
17
|
constructor(kauthApi: KauthApi);
|
|
18
|
-
authenticate(token: string, redirectUri: string): Promise<AuthenticationInformation>;
|
|
18
|
+
authenticate(token: string, redirectUri: string, preAuthorizationToken?: string): Promise<AuthenticationInformation>;
|
|
19
19
|
bind(userId: number, token: string, redirectUri: string): Promise<void>;
|
|
20
20
|
authorizeURL(callback: string, state: string, prompt?: string): Promise<string>;
|
|
21
21
|
}
|
|
22
22
|
export declare class MiniprogramAuthenticator implements Authenticator {
|
|
23
23
|
private kauthApi;
|
|
24
24
|
constructor(kauthApi: KauthApi);
|
|
25
|
-
authenticate(token: string, redirectUri: string): Promise<AuthenticationInformation>;
|
|
25
|
+
authenticate(token: string, redirectUri: string, preAuthorizationToken?: string): Promise<AuthenticationInformation>;
|
|
26
26
|
bind(userId: number, token: string, redirectUri: string): Promise<void>;
|
|
27
27
|
authorizeURL(callback: string, state: string, prompt?: string): Promise<string>;
|
|
28
28
|
}
|
|
@@ -8,16 +8,18 @@ class GoogleAuthenticator {
|
|
|
8
8
|
constructor(kauthApi) {
|
|
9
9
|
this.kauthApi = kauthApi;
|
|
10
10
|
}
|
|
11
|
-
async authenticate(token, redirectUri) {
|
|
11
|
+
async authenticate(token, redirectUri, preAuthorizationToken) {
|
|
12
12
|
const request = {
|
|
13
13
|
code: token,
|
|
14
14
|
redirect_uri: redirectUri,
|
|
15
|
+
pre_authorization_token: preAuthorizationToken,
|
|
15
16
|
};
|
|
16
17
|
const result = await this.kauthApi.googleAuthenticate(request);
|
|
17
18
|
const authenticationInformation = new google_1.GoogleAuthenticationInformation();
|
|
18
19
|
authenticationInformation.primaryPrincipal = result.primaryPrincipal;
|
|
19
20
|
authenticationInformation.principal = result.principal;
|
|
20
21
|
authenticationInformation.credential = result.credential;
|
|
22
|
+
authenticationInformation.preAuthorizationAllowed = result.preAuthorizationAllowed;
|
|
21
23
|
return authenticationInformation;
|
|
22
24
|
}
|
|
23
25
|
async bind(userId, token, redirectUri) {
|
|
@@ -36,16 +38,18 @@ class MoziAuthenticator {
|
|
|
36
38
|
constructor(kauthApi) {
|
|
37
39
|
this.kauthApi = kauthApi;
|
|
38
40
|
}
|
|
39
|
-
async authenticate(token, redirectUri) {
|
|
41
|
+
async authenticate(token, redirectUri, preAuthorizationToken) {
|
|
40
42
|
const request = {
|
|
41
43
|
code: token,
|
|
42
44
|
redirect_uri: redirectUri,
|
|
45
|
+
pre_authorization_token: preAuthorizationToken,
|
|
43
46
|
};
|
|
44
47
|
const result = await this.kauthApi.moziAuthenticate(request);
|
|
45
48
|
const authenticationInformation = new mozi_1.MoziAuthenticationInformation();
|
|
46
49
|
authenticationInformation.primaryPrincipal = result.primaryPrincipal;
|
|
47
50
|
authenticationInformation.principal = result.principal;
|
|
48
51
|
authenticationInformation.credential = result.credential;
|
|
52
|
+
authenticationInformation.preAuthorizationAllowed = result.preAuthorizationAllowed;
|
|
49
53
|
return authenticationInformation;
|
|
50
54
|
}
|
|
51
55
|
async bind(userId, token, redirectUri) {
|
|
@@ -64,16 +68,18 @@ class MiniprogramAuthenticator {
|
|
|
64
68
|
constructor(kauthApi) {
|
|
65
69
|
this.kauthApi = kauthApi;
|
|
66
70
|
}
|
|
67
|
-
async authenticate(token, redirectUri) {
|
|
71
|
+
async authenticate(token, redirectUri, preAuthorizationToken) {
|
|
68
72
|
const request = {
|
|
69
73
|
code: token,
|
|
70
74
|
redirect_uri: redirectUri,
|
|
75
|
+
pre_authorization_token: preAuthorizationToken,
|
|
71
76
|
};
|
|
72
77
|
const result = await this.kauthApi.miniprogramAuthenticate(request);
|
|
73
78
|
const authenticationInformation = new miniprogram_1.MiniprogramAuthenticationInformation();
|
|
74
79
|
authenticationInformation.primaryPrincipal = result.primaryPrincipal;
|
|
75
80
|
authenticationInformation.principal = result.principal;
|
|
76
81
|
authenticationInformation.credential = result.credential;
|
|
82
|
+
authenticationInformation.preAuthorizationAllowed = result.preAuthorizationAllowed;
|
|
77
83
|
return authenticationInformation;
|
|
78
84
|
}
|
|
79
85
|
async bind(userId, token, redirectUri) {
|
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
export declare enum UserAccountType {
|
|
2
|
+
Mozi = "mozi",
|
|
3
|
+
Google = "google",
|
|
4
|
+
Miniprogram = "miniprogram"
|
|
5
|
+
}
|
|
6
|
+
export declare enum PreAuthorizationIsAllowedErrorCode {
|
|
7
|
+
UserNotFound = "userNotFound",
|
|
8
|
+
UserNotInWhitelist = "userNotInWhitelist",
|
|
9
|
+
TokenExpired = "tokenExpired",
|
|
10
|
+
TokenNotExisted = "tokenNotExisted",
|
|
11
|
+
TokenUsedUp = "tokenUsedUp"
|
|
12
|
+
}
|
|
13
|
+
export declare type PreAuthorizationAllowed = ({
|
|
14
|
+
allowed: true;
|
|
15
|
+
} & {
|
|
16
|
+
processed: boolean;
|
|
17
|
+
id: number;
|
|
18
|
+
userId: number;
|
|
19
|
+
type: UserAccountType;
|
|
20
|
+
target: string;
|
|
21
|
+
token: string;
|
|
22
|
+
roleType: 'kauth' | string;
|
|
23
|
+
roleName: string;
|
|
24
|
+
roleExtendValue: string;
|
|
25
|
+
resolvedAuthorizeeTargets: Array<{
|
|
26
|
+
type: UserAccountType;
|
|
27
|
+
target: string;
|
|
28
|
+
id: number;
|
|
29
|
+
}>;
|
|
30
|
+
callback: string;
|
|
31
|
+
}) | ({
|
|
32
|
+
allowed: false;
|
|
33
|
+
} & {
|
|
34
|
+
code: PreAuthorizationIsAllowedErrorCode;
|
|
35
|
+
reason: string;
|
|
36
|
+
});
|
|
1
37
|
export interface Principal {
|
|
2
38
|
}
|
|
3
39
|
export interface Credential {
|
|
@@ -6,6 +42,7 @@ export interface AuthenticationInformation {
|
|
|
6
42
|
primaryPrincipal: PrimaryPrincipal;
|
|
7
43
|
principal: Principal;
|
|
8
44
|
credential: Credential;
|
|
45
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
9
46
|
}
|
|
10
47
|
export declare class PrimaryPrincipal implements Principal {
|
|
11
48
|
id: number;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrimaryPrincipal = void 0;
|
|
3
|
+
exports.PrimaryPrincipal = exports.PreAuthorizationIsAllowedErrorCode = exports.UserAccountType = void 0;
|
|
4
|
+
var UserAccountType;
|
|
5
|
+
(function (UserAccountType) {
|
|
6
|
+
UserAccountType["Mozi"] = "mozi";
|
|
7
|
+
UserAccountType["Google"] = "google";
|
|
8
|
+
UserAccountType["Miniprogram"] = "miniprogram";
|
|
9
|
+
})(UserAccountType = exports.UserAccountType || (exports.UserAccountType = {}));
|
|
10
|
+
var PreAuthorizationIsAllowedErrorCode;
|
|
11
|
+
(function (PreAuthorizationIsAllowedErrorCode) {
|
|
12
|
+
PreAuthorizationIsAllowedErrorCode["UserNotFound"] = "userNotFound";
|
|
13
|
+
PreAuthorizationIsAllowedErrorCode["UserNotInWhitelist"] = "userNotInWhitelist";
|
|
14
|
+
PreAuthorizationIsAllowedErrorCode["TokenExpired"] = "tokenExpired";
|
|
15
|
+
PreAuthorizationIsAllowedErrorCode["TokenNotExisted"] = "tokenNotExisted";
|
|
16
|
+
PreAuthorizationIsAllowedErrorCode["TokenUsedUp"] = "tokenUsedUp";
|
|
17
|
+
})(PreAuthorizationIsAllowedErrorCode = exports.PreAuthorizationIsAllowedErrorCode || (exports.PreAuthorizationIsAllowedErrorCode = {}));
|
|
4
18
|
class PrimaryPrincipal {
|
|
5
19
|
}
|
|
6
20
|
exports.PrimaryPrincipal = PrimaryPrincipal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Principal, PrimaryPrincipal, Credential, AuthenticationInformation } from './base';
|
|
1
|
+
import { Principal, PrimaryPrincipal, Credential, AuthenticationInformation, PreAuthorizationAllowed } from './base';
|
|
2
2
|
export declare class GooglePrincipal implements Principal {
|
|
3
3
|
sub: string;
|
|
4
4
|
name: string;
|
|
@@ -18,4 +18,5 @@ export declare class GoogleAuthenticationInformation implements AuthenticationIn
|
|
|
18
18
|
primaryPrincipal: PrimaryPrincipal;
|
|
19
19
|
principal: GooglePrincipal;
|
|
20
20
|
credential: GoogleCredential;
|
|
21
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
21
22
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { GoogleAuthenticator, MoziAuthenticator, MiniprogramAuthenticator } from './authenticator';
|
|
2
|
-
export { AuthenticationInformation, PrimaryPrincipal } from './base';
|
|
2
|
+
export { AuthenticationInformation, PrimaryPrincipal, UserAccountType, PreAuthorizationAllowed } from './base';
|
|
3
3
|
export { JsonWebTokenSubjectProvider, JsonWebTokenAuthenticationProvider } from './provider';
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "MoziAuthenticator", { enumerable: true, get: fun
|
|
|
6
6
|
Object.defineProperty(exports, "MiniprogramAuthenticator", { enumerable: true, get: function () { return authenticator_1.MiniprogramAuthenticator; } });
|
|
7
7
|
var base_1 = require("./base");
|
|
8
8
|
Object.defineProperty(exports, "PrimaryPrincipal", { enumerable: true, get: function () { return base_1.PrimaryPrincipal; } });
|
|
9
|
+
Object.defineProperty(exports, "UserAccountType", { enumerable: true, get: function () { return base_1.UserAccountType; } });
|
|
9
10
|
var provider_1 = require("./provider");
|
|
10
11
|
Object.defineProperty(exports, "JsonWebTokenSubjectProvider", { enumerable: true, get: function () { return provider_1.JsonWebTokenSubjectProvider; } });
|
|
11
12
|
Object.defineProperty(exports, "JsonWebTokenAuthenticationProvider", { enumerable: true, get: function () { return provider_1.JsonWebTokenAuthenticationProvider; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Principal, PrimaryPrincipal, Credential, AuthenticationInformation } from './base';
|
|
1
|
+
import { Principal, PrimaryPrincipal, Credential, AuthenticationInformation, PreAuthorizationAllowed } from './base';
|
|
2
2
|
export declare class MiniprogramPrincipal implements Principal {
|
|
3
3
|
trustLoginId: string;
|
|
4
4
|
customerId: string;
|
|
@@ -12,4 +12,5 @@ export declare class MiniprogramAuthenticationInformation implements Authenticat
|
|
|
12
12
|
primaryPrincipal: PrimaryPrincipal;
|
|
13
13
|
principal: MiniprogramPrincipal;
|
|
14
14
|
credential: MiniprogramCredential;
|
|
15
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
15
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Principal, PrimaryPrincipal, Credential, AuthenticationInformation } from './base';
|
|
1
|
+
import { Principal, PrimaryPrincipal, Credential, AuthenticationInformation, PreAuthorizationAllowed } from './base';
|
|
2
2
|
export declare class MoziPrincipal implements Principal {
|
|
3
3
|
account: string;
|
|
4
4
|
employeeCode: string;
|
|
@@ -18,4 +18,5 @@ export declare class MoziAuthenticationInformation implements AuthenticationInfo
|
|
|
18
18
|
primaryPrincipal: PrimaryPrincipal;
|
|
19
19
|
principal: MoziPrincipal;
|
|
20
20
|
credential: MoziCredential;
|
|
21
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
21
22
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PreAuthorizationAllowed } from '../../authenticator/base';
|
|
1
2
|
import { AuthenticationInformation } from '../../authenticator';
|
|
2
3
|
export interface KauthConfig {
|
|
3
4
|
origin?: string;
|
|
@@ -23,6 +24,7 @@ export interface KauthConfig {
|
|
|
23
24
|
logoutRedirectUri?: string;
|
|
24
25
|
loginHandler?: (ctx: any, authInfo: AuthenticationInformation) => Promise<void>;
|
|
25
26
|
authHandler?: (ctx: any, sub: number) => Promise<void>;
|
|
27
|
+
preAuthorizationCallback?: string | ((ctx: any, preAuthorizationAllowed: PreAuthorizationAllowed) => Promise<string | undefined>);
|
|
26
28
|
mockHandler?: (ctx: any) => Promise<void>;
|
|
27
29
|
lruMaxAge?: number;
|
|
28
30
|
lruMax?: number;
|
|
@@ -37,6 +37,11 @@ export declare const BindUserByRolesAndExtendValueUri = "/api/backend/bindUserBy
|
|
|
37
37
|
export declare const BindUsersByRoleNameAndExtendValueUri = "/api/backend/bindUsersByRoleNameAndExtendValue";
|
|
38
38
|
export declare const BindRoleByPermissionsUri = "/api/backend/bindRoleByPermissions";
|
|
39
39
|
export declare const BindRoleWithUsersUri = "/api/backend/bindRoleWithUsers";
|
|
40
|
+
export declare const CreatePreAuthorizationUri = "/api/backend/createPreAuthorization";
|
|
41
|
+
export declare const GetPreAuthorizationUri = "/api/backend/getPreAuthorization";
|
|
42
|
+
export declare const RefreshPreAuthorizationUri = "/api/backend/refreshPreAuthorization";
|
|
43
|
+
export declare const ProcessPreAuthorizationUri = "/api/backend/processPreAuthorization";
|
|
44
|
+
export declare const CommitPreAuthorizationUri = "/api/backend/commitPreAuthorization";
|
|
40
45
|
export declare const ProcessUri = "/api/kflow/process";
|
|
41
46
|
export declare const ServiceTaskUri = "/api/kflow/serviceTask";
|
|
42
47
|
export declare const InstanceUri = "/api/kflow/stateMachine/instance/";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompleteGraphServiceTaskUri = exports.GetGraphStateMachineSnapshotUri = exports.StartGraphProcessUri = exports.GetProcinstUserUri = exports.InstanceUri = exports.ServiceTaskUri = exports.ProcessUri = exports.BindRoleWithUsersUri = exports.BindRoleByPermissionsUri = exports.BindUsersByRoleNameAndExtendValueUri = exports.BindUserByRolesAndExtendValueUri = exports.BindUserByRoleNamesAndExtendValueUri = exports.BindUserByRolesUri = exports.CreatePermissionUri = exports.ListPermissionsByUserIdUri = exports.ListPermissionsUri = exports.UpdateRolesWithPermissionsUri = exports.CreateRolesByUsersAndPermissionsUri = exports.CreateRoleUri = exports.ListRolesByNamesAndExtendValueUri = exports.ListRolesByUserIdUri = exports.ListRolesByExtendValueUri = exports.ListRolesUri = exports.GetRoleWithUsersUri = exports.ListUsersByPermissionNameAndExtendValueUri = exports.ListUsersByPermissionIdUri = exports.ListUsersByRoleNameAndExtendValueUri = exports.ListUsersByRoleIdUri = exports.ListUsersWithUserAccountsAndRolesByRoleExtendValueUri = exports.ListUsersWithUserAccountsAndRolesUri = exports.ListUsersUri = exports.SearchUsersWithUserAccountsAndRolesUri = exports.GetUserByIdUri = exports.UnbindUri = exports.MiniprogramAuthenticationInformationUri = exports.MiniprogramBindUri = exports.MiniprogramAuthenticateUri = exports.MiniprogramAuthorizeUri = exports.GoogleAuthenticationInformationUri = exports.GoogleBindUri = exports.GoogleAuthenticateUri = exports.GoogleAuthorizeUri = exports.MoziAuthenticationInformationUri = exports.MoziBindUri = exports.MoziAuthenticateUri = exports.MoziAuthorizeUri = void 0;
|
|
3
|
+
exports.CompleteGraphServiceTaskUri = exports.GetGraphStateMachineSnapshotUri = exports.StartGraphProcessUri = exports.GetProcinstUserUri = exports.InstanceUri = exports.ServiceTaskUri = exports.ProcessUri = exports.CommitPreAuthorizationUri = exports.ProcessPreAuthorizationUri = exports.RefreshPreAuthorizationUri = exports.GetPreAuthorizationUri = exports.CreatePreAuthorizationUri = exports.BindRoleWithUsersUri = exports.BindRoleByPermissionsUri = exports.BindUsersByRoleNameAndExtendValueUri = exports.BindUserByRolesAndExtendValueUri = exports.BindUserByRoleNamesAndExtendValueUri = exports.BindUserByRolesUri = exports.CreatePermissionUri = exports.ListPermissionsByUserIdUri = exports.ListPermissionsUri = exports.UpdateRolesWithPermissionsUri = exports.CreateRolesByUsersAndPermissionsUri = exports.CreateRoleUri = exports.ListRolesByNamesAndExtendValueUri = exports.ListRolesByUserIdUri = exports.ListRolesByExtendValueUri = exports.ListRolesUri = exports.GetRoleWithUsersUri = exports.ListUsersByPermissionNameAndExtendValueUri = exports.ListUsersByPermissionIdUri = exports.ListUsersByRoleNameAndExtendValueUri = exports.ListUsersByRoleIdUri = exports.ListUsersWithUserAccountsAndRolesByRoleExtendValueUri = exports.ListUsersWithUserAccountsAndRolesUri = exports.ListUsersUri = exports.SearchUsersWithUserAccountsAndRolesUri = exports.GetUserByIdUri = exports.UnbindUri = exports.MiniprogramAuthenticationInformationUri = exports.MiniprogramBindUri = exports.MiniprogramAuthenticateUri = exports.MiniprogramAuthorizeUri = exports.GoogleAuthenticationInformationUri = exports.GoogleBindUri = exports.GoogleAuthenticateUri = exports.GoogleAuthorizeUri = exports.MoziAuthenticationInformationUri = exports.MoziBindUri = exports.MoziAuthenticateUri = exports.MoziAuthorizeUri = void 0;
|
|
4
4
|
// kauth
|
|
5
5
|
exports.MoziAuthorizeUri = '/api/authenticator/mozi/authorizeUrl';
|
|
6
6
|
exports.MoziAuthenticateUri = '/api/authenticator/mozi/authenticate';
|
|
@@ -41,6 +41,11 @@ exports.BindUserByRolesAndExtendValueUri = '/api/backend/bindUserByRolesAndExten
|
|
|
41
41
|
exports.BindUsersByRoleNameAndExtendValueUri = '/api/backend/bindUsersByRoleNameAndExtendValue';
|
|
42
42
|
exports.BindRoleByPermissionsUri = '/api/backend/bindRoleByPermissions';
|
|
43
43
|
exports.BindRoleWithUsersUri = '/api/backend/bindRoleWithUsers';
|
|
44
|
+
exports.CreatePreAuthorizationUri = '/api/backend/createPreAuthorization';
|
|
45
|
+
exports.GetPreAuthorizationUri = '/api/backend/getPreAuthorization';
|
|
46
|
+
exports.RefreshPreAuthorizationUri = '/api/backend/refreshPreAuthorization';
|
|
47
|
+
exports.ProcessPreAuthorizationUri = '/api/backend/processPreAuthorization';
|
|
48
|
+
exports.CommitPreAuthorizationUri = '/api/backend/commitPreAuthorization';
|
|
44
49
|
// kflow
|
|
45
50
|
exports.ProcessUri = '/api/kflow/process';
|
|
46
51
|
exports.ServiceTaskUri = '/api/kflow/serviceTask';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KauthConfig } from '../config/config';
|
|
2
|
-
import { KauthAuthenticateRequest, KauthCreatePermissionRequest, KauthCreateRoleRequest, KauthCreateRolesByPermissionsAndUsersRequest, KauthBindUsersByRoleNameAndExtendValueRequest, KauthBindRequest, KauthBindRoleByPermissionsRequest, KauthBindUserByRolesRequest, KauthBindUserByRolesAndExtendValueRequest, KauthUpdateRolesWithPermissionsRequest, KauthBindRoleWithUsersRequest, KauthBindUserByRoleNamesAndExtendValueRequest, KauthSearchUsersWithUserAccountsAndRoleRequest } from './request/kauth';
|
|
3
|
-
import { KauthMoziAuthenticationInformation, KauthGoogleAuthenticationInformation, KauthPermission, KauthMiniprogramAuthenticationInformation, KauthRole, KauthUser, KauthPagable } from './response/kauth';
|
|
2
|
+
import { KauthAuthenticateRequest, KauthCreatePermissionRequest, KauthCreateRoleRequest, KauthCreateRolesByPermissionsAndUsersRequest, KauthBindUsersByRoleNameAndExtendValueRequest, KauthBindRequest, KauthBindRoleByPermissionsRequest, KauthBindUserByRolesRequest, KauthBindUserByRolesAndExtendValueRequest, KauthUpdateRolesWithPermissionsRequest, KauthBindRoleWithUsersRequest, KauthBindUserByRoleNamesAndExtendValueRequest, KauthSearchUsersWithUserAccountsAndRoleRequest, KauthCreatePreAuthorizationRequest, GetPreAuthorizationRequest, RefreshPreAuthorizatioRequest, ProcessPreAuthorizatioRequest } from './request/kauth';
|
|
3
|
+
import { KauthMoziAuthenticationInformation, KauthGoogleAuthenticationInformation, KauthPermission, KauthMiniprogramAuthenticationInformation, KauthRole, KauthUser, KauthPagable, KauthPreAuthorization } from './response/kauth';
|
|
4
|
+
import { PreAuthorizationAllowed } from '../../authenticator/base';
|
|
4
5
|
export declare class KauthApi {
|
|
5
6
|
private marmotUtil;
|
|
6
7
|
private cache;
|
|
@@ -51,4 +52,12 @@ export declare class KauthApi {
|
|
|
51
52
|
bindUsersByRoleNameAndExtendValue(data: KauthBindUsersByRoleNameAndExtendValueRequest): Promise<void>;
|
|
52
53
|
bindRoleByPermissions(data: KauthBindRoleByPermissionsRequest): Promise<void>;
|
|
53
54
|
bindRoleWithUsers(data: KauthBindRoleWithUsersRequest): Promise<void>;
|
|
55
|
+
createPreAuthorization(data: KauthCreatePreAuthorizationRequest): Promise<KauthPreAuthorization>;
|
|
56
|
+
getPreAuthorization(data: GetPreAuthorizationRequest): Promise<KauthPreAuthorization>;
|
|
57
|
+
refreshPreAuthorization(data: RefreshPreAuthorizatioRequest): Promise<{
|
|
58
|
+
id: number;
|
|
59
|
+
token: string;
|
|
60
|
+
}>;
|
|
61
|
+
processPreAuthorization(data: ProcessPreAuthorizatioRequest): Promise<PreAuthorizationAllowed>;
|
|
62
|
+
commitPreAuthorization(data: ProcessPreAuthorizatioRequest): Promise<PreAuthorizationAllowed>;
|
|
54
63
|
}
|
|
@@ -185,5 +185,20 @@ class KauthApi {
|
|
|
185
185
|
this.cache.del(user.id);
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
|
+
async createPreAuthorization(data) {
|
|
189
|
+
return this.marmotUtil.post(http_1.CreatePreAuthorizationUri, data);
|
|
190
|
+
}
|
|
191
|
+
async getPreAuthorization(data) {
|
|
192
|
+
return this.marmotUtil.get(http_1.GetPreAuthorizationUri, data);
|
|
193
|
+
}
|
|
194
|
+
async refreshPreAuthorization(data) {
|
|
195
|
+
return this.marmotUtil.post(http_1.RefreshPreAuthorizationUri, data);
|
|
196
|
+
}
|
|
197
|
+
async processPreAuthorization(data) {
|
|
198
|
+
return this.marmotUtil.post(http_1.ProcessPreAuthorizationUri, data);
|
|
199
|
+
}
|
|
200
|
+
async commitPreAuthorization(data) {
|
|
201
|
+
return this.marmotUtil.post(http_1.CommitPreAuthorizationUri, data);
|
|
202
|
+
}
|
|
188
203
|
}
|
|
189
204
|
exports.KauthApi = KauthApi;
|
|
@@ -95,3 +95,31 @@ export interface KauthSearchUsersWithUserAccountsAndRoleRequest extends MarmotOp
|
|
|
95
95
|
role_extend_value: typeof NotFilteredByAnyRoles | typeof FilteredByGlobalRoles | string;
|
|
96
96
|
pagination: Partial<MarmotPagination>;
|
|
97
97
|
}
|
|
98
|
+
export interface KauthCreatePreAuthorizationRequest extends MarmotOptions {
|
|
99
|
+
authorizerId: number;
|
|
100
|
+
roleType: string;
|
|
101
|
+
roleName: string;
|
|
102
|
+
roleExtendValue: string;
|
|
103
|
+
callback: string;
|
|
104
|
+
authorizeeTargets?: Array<{
|
|
105
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
106
|
+
target: string;
|
|
107
|
+
}>;
|
|
108
|
+
expiredAt?: Date;
|
|
109
|
+
count?: number;
|
|
110
|
+
oldTimeUserAllowed?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface RefreshPreAuthorizatioRequest extends MarmotOptions {
|
|
113
|
+
id: number;
|
|
114
|
+
}
|
|
115
|
+
export interface GetPreAuthorizationRequest extends MarmotOptions {
|
|
116
|
+
roleType: string;
|
|
117
|
+
roleName: string;
|
|
118
|
+
roleExtendValue?: string;
|
|
119
|
+
}
|
|
120
|
+
export interface ProcessPreAuthorizatioRequest extends MarmotOptions {
|
|
121
|
+
token: string;
|
|
122
|
+
userId: number;
|
|
123
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
124
|
+
target: string;
|
|
125
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrimaryPrincipal } from '../../../authenticator/base';
|
|
1
|
+
import { PreAuthorizationAllowed, PrimaryPrincipal } from '../../../authenticator/base';
|
|
2
2
|
import { MarmotPagination } from '../tool/marmot';
|
|
3
3
|
export declare enum KauthPrincipalStatus {
|
|
4
4
|
Normal = 0,
|
|
@@ -30,6 +30,7 @@ export interface KauthMoziAuthenticationInformation {
|
|
|
30
30
|
primaryPrincipal: KauthPrimaryPrincipal;
|
|
31
31
|
principal: KauthMoziPrincipal;
|
|
32
32
|
credential: KauthMoziCredential;
|
|
33
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
33
34
|
}
|
|
34
35
|
export interface KauthGooglePrincipal {
|
|
35
36
|
sub: string;
|
|
@@ -50,6 +51,7 @@ export interface KauthGoogleAuthenticationInformation {
|
|
|
50
51
|
primaryPrincipal: KauthPrimaryPrincipal;
|
|
51
52
|
principal: KauthGooglePrincipal;
|
|
52
53
|
credential: KauthGoogleCredential;
|
|
54
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
53
55
|
}
|
|
54
56
|
export interface KauthMiniprogramPrincipal {
|
|
55
57
|
trustLoginId: string;
|
|
@@ -64,6 +66,7 @@ export interface KauthMiniprogramAuthenticationInformation {
|
|
|
64
66
|
primaryPrincipal: PrimaryPrincipal;
|
|
65
67
|
principal: KauthMiniprogramPrincipal;
|
|
66
68
|
credential: KauthMiniprogramCredential;
|
|
69
|
+
preAuthorizationAllowed?: PreAuthorizationAllowed;
|
|
67
70
|
}
|
|
68
71
|
export interface KauthPermission {
|
|
69
72
|
id: number;
|
|
@@ -89,3 +92,25 @@ export interface KauthPagable<T> {
|
|
|
89
92
|
data: T;
|
|
90
93
|
pagination: MarmotPagination;
|
|
91
94
|
}
|
|
95
|
+
export interface KauthPreAuthorization {
|
|
96
|
+
id: number;
|
|
97
|
+
tenantId: string;
|
|
98
|
+
token: string;
|
|
99
|
+
authorizerId: number;
|
|
100
|
+
authorizeeTargets?: Array<{
|
|
101
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
102
|
+
target: string;
|
|
103
|
+
}>;
|
|
104
|
+
resolvedAuthorizeeTargets: Array<{
|
|
105
|
+
type: 'mozi' | 'google' | 'miniprogram';
|
|
106
|
+
id: number;
|
|
107
|
+
target: string;
|
|
108
|
+
}>;
|
|
109
|
+
expiredAt?: Date;
|
|
110
|
+
count?: number;
|
|
111
|
+
oldTimeUserAllowed?: boolean;
|
|
112
|
+
roleType: 'kauth' | string;
|
|
113
|
+
roleName: string;
|
|
114
|
+
roleExtendValue?: string;
|
|
115
|
+
callback: string;
|
|
116
|
+
}
|
|
@@ -114,7 +114,6 @@ class MarmotUtil {
|
|
|
114
114
|
headers['x-service-name'] = this.serviceName;
|
|
115
115
|
headers['x-service-port'] = this.servicePort;
|
|
116
116
|
headers.authorization = `Marmot ${this.accessKeyId}:${signature}`;
|
|
117
|
-
console.log('request headers', headers);
|
|
118
117
|
return headers;
|
|
119
118
|
}
|
|
120
119
|
sign(method, path, accessKeySecret) {
|
|
@@ -134,8 +133,7 @@ class MarmotUtil {
|
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
formatTraceConsumers(traceConsumers) {
|
|
137
|
-
return Object
|
|
138
|
-
.keys(traceConsumers)
|
|
136
|
+
return Object.keys(traceConsumers)
|
|
139
137
|
.map((k) => {
|
|
140
138
|
const v = this.traceConsumers[k];
|
|
141
139
|
return `${k}:${v}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { KauthApi } from './common/http/kauth';
|
|
|
3
3
|
export { KflowApi } from './common/http/kflow';
|
|
4
4
|
export * from './common/http/request/kauth';
|
|
5
5
|
export * from './common/http/request/kflow';
|
|
6
|
-
export { GoogleAuthenticator, MoziAuthenticator, MiniprogramAuthenticator, AuthenticationInformation, PrimaryPrincipal, JsonWebTokenSubjectProvider, JsonWebTokenAuthenticationProvider, } from './authenticator';
|
|
6
|
+
export { GoogleAuthenticator, MoziAuthenticator, MiniprogramAuthenticator, AuthenticationInformation, PrimaryPrincipal, JsonWebTokenSubjectProvider, JsonWebTokenAuthenticationProvider, UserAccountType, PreAuthorizationAllowed, } from './authenticator';
|
|
7
7
|
export { PermissionCore } from './authorizer';
|
|
8
8
|
export { MoziAuthenticationInformation, MoziPrincipal, MoziCredential } from './authenticator/mozi';
|
|
9
9
|
export { GoogleAuthenticationInformation, GooglePrincipal, GoogleCredential } from './authenticator/google';
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "MiniprogramAuthenticator", { enumerable: true, g
|
|
|
23
23
|
Object.defineProperty(exports, "PrimaryPrincipal", { enumerable: true, get: function () { return authenticator_1.PrimaryPrincipal; } });
|
|
24
24
|
Object.defineProperty(exports, "JsonWebTokenSubjectProvider", { enumerable: true, get: function () { return authenticator_1.JsonWebTokenSubjectProvider; } });
|
|
25
25
|
Object.defineProperty(exports, "JsonWebTokenAuthenticationProvider", { enumerable: true, get: function () { return authenticator_1.JsonWebTokenAuthenticationProvider; } });
|
|
26
|
+
Object.defineProperty(exports, "UserAccountType", { enumerable: true, get: function () { return authenticator_1.UserAccountType; } });
|
|
26
27
|
var authorizer_1 = require("./authorizer");
|
|
27
28
|
Object.defineProperty(exports, "PermissionCore", { enumerable: true, get: function () { return authorizer_1.PermissionCore; } });
|
|
28
29
|
var mozi_1 = require("./authenticator/mozi");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kauth-sdk-node",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
"watch": "tsc -w",
|
|
14
14
|
"type-check": "tsc --noEmit",
|
|
15
15
|
"lint": "npm run type-check && eslint . --fix --ext .ts",
|
|
16
|
-
"test": "mocha --recursive --require ts-node/register 'test/**/*.ts'",
|
|
17
|
-
"
|
|
18
|
-
"ci": "npm run lint && npm run coverage",
|
|
16
|
+
"test": "multi='spec=- mocha-junit-reporter=-' mocha --reporter=mocha-multi --recursive --require ts-node/register 'test/**/*.ts'",
|
|
17
|
+
"ci": "nyc -t coverage --reporter=cobertura npm run test",
|
|
19
18
|
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add .",
|
|
20
19
|
"prepublishOnly": "rm -rf dist && npm run build"
|
|
21
20
|
},
|
|
@@ -42,6 +41,8 @@
|
|
|
42
41
|
"eslint-plugin-prettier": "^3.3.1",
|
|
43
42
|
"lint-staged": "^10.5.3",
|
|
44
43
|
"mocha": "^8.0.1",
|
|
44
|
+
"mocha-junit-reporter": "^2.0.2",
|
|
45
|
+
"mocha-multi": "^1.1.6",
|
|
45
46
|
"nyc": "^15.1.0",
|
|
46
47
|
"prettier": "^2.2.1",
|
|
47
48
|
"sinon": "^9.0.2",
|