kauth-sdk-node 2.0.12-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.
@@ -19,6 +19,7 @@ class GoogleAuthenticator {
19
19
  authenticationInformation.primaryPrincipal = result.primaryPrincipal;
20
20
  authenticationInformation.principal = result.principal;
21
21
  authenticationInformation.credential = result.credential;
22
+ authenticationInformation.preAuthorizationAllowed = result.preAuthorizationAllowed;
22
23
  return authenticationInformation;
23
24
  }
24
25
  async bind(userId, token, redirectUri) {
@@ -48,6 +49,7 @@ class MoziAuthenticator {
48
49
  authenticationInformation.primaryPrincipal = result.primaryPrincipal;
49
50
  authenticationInformation.principal = result.principal;
50
51
  authenticationInformation.credential = result.credential;
52
+ authenticationInformation.preAuthorizationAllowed = result.preAuthorizationAllowed;
51
53
  return authenticationInformation;
52
54
  }
53
55
  async bind(userId, token, redirectUri) {
@@ -77,6 +79,7 @@ class MiniprogramAuthenticator {
77
79
  authenticationInformation.primaryPrincipal = result.primaryPrincipal;
78
80
  authenticationInformation.principal = result.principal;
79
81
  authenticationInformation.credential = result.credential;
82
+ authenticationInformation.preAuthorizationAllowed = result.preAuthorizationAllowed;
80
83
  return authenticationInformation;
81
84
  }
82
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;
@@ -1,6 +1,7 @@
1
1
  import { KauthConfig } from '../config/config';
2
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, PreAuthorizationAllowed } from './response/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,9 +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>;
54
- createPreAuthorization(data: KauthCreatePreAuthorizationRequest): Promise<void>;
55
- getPreAuthorization(data: GetPreAuthorizationRequest): Promise<any>;
56
- refreshPreAuthorization(data: RefreshPreAuthorizatioRequest): Promise<any>;
55
+ createPreAuthorization(data: KauthCreatePreAuthorizationRequest): Promise<KauthPreAuthorization>;
56
+ getPreAuthorization(data: GetPreAuthorizationRequest): Promise<KauthPreAuthorization>;
57
+ refreshPreAuthorization(data: RefreshPreAuthorizatioRequest): Promise<{
58
+ id: number;
59
+ token: string;
60
+ }>;
57
61
  processPreAuthorization(data: ProcessPreAuthorizatioRequest): Promise<PreAuthorizationAllowed>;
58
62
  commitPreAuthorization(data: ProcessPreAuthorizatioRequest): Promise<PreAuthorizationAllowed>;
59
63
  }
@@ -1,17 +1,5 @@
1
- import { PrimaryPrincipal } from '../../../authenticator/base';
1
+ import { PreAuthorizationAllowed, PrimaryPrincipal } from '../../../authenticator/base';
2
2
  import { MarmotPagination } from '../tool/marmot';
3
- export declare enum UserAccountType {
4
- Mozi = "mozi",
5
- Google = "google",
6
- Miniprogram = "miniprogram"
7
- }
8
- export declare enum PreAuthorizationIsAllowedErrorCode {
9
- UserNotFound = "userNotFound",
10
- UserNotInWhitelist = "userNotInWhitelist",
11
- TokenExpired = "tokenExpired",
12
- TokenNotExisted = "tokenNotExisted",
13
- TokenUsedUp = "tokenUsedUp"
14
- }
15
3
  export declare enum KauthPrincipalStatus {
16
4
  Normal = 0,
17
5
  Locked = 1
@@ -38,34 +26,11 @@ export interface KauthMoziCredential {
38
26
  expiresIn: number;
39
27
  refreshToken: string;
40
28
  }
41
- export declare type KauthPreAuthorized = ({
42
- allowed: true;
43
- } & {
44
- processed: boolean;
45
- id: number;
46
- userId: number;
47
- type: UserAccountType;
48
- target: string;
49
- token: string;
50
- roleType: 'kauth' | string;
51
- roleName: string;
52
- roleExtendValue: string;
53
- resolvedAuthorizeeTargets: Array<{
54
- type: UserAccountType;
55
- target: string;
56
- id: number;
57
- }>;
58
- }) | ({
59
- allowed: false;
60
- } & {
61
- code: PreAuthorizationIsAllowedErrorCode;
62
- reason: string;
63
- });
64
29
  export interface KauthMoziAuthenticationInformation {
65
30
  primaryPrincipal: KauthPrimaryPrincipal;
66
31
  principal: KauthMoziPrincipal;
67
32
  credential: KauthMoziCredential;
68
- preAuthorized?: KauthPreAuthorized;
33
+ preAuthorizationAllowed?: PreAuthorizationAllowed;
69
34
  }
70
35
  export interface KauthGooglePrincipal {
71
36
  sub: string;
@@ -86,6 +51,7 @@ export interface KauthGoogleAuthenticationInformation {
86
51
  primaryPrincipal: KauthPrimaryPrincipal;
87
52
  principal: KauthGooglePrincipal;
88
53
  credential: KauthGoogleCredential;
54
+ preAuthorizationAllowed?: PreAuthorizationAllowed;
89
55
  }
90
56
  export interface KauthMiniprogramPrincipal {
91
57
  trustLoginId: string;
@@ -100,6 +66,7 @@ export interface KauthMiniprogramAuthenticationInformation {
100
66
  primaryPrincipal: PrimaryPrincipal;
101
67
  principal: KauthMiniprogramPrincipal;
102
68
  credential: KauthMiniprogramCredential;
69
+ preAuthorizationAllowed?: PreAuthorizationAllowed;
103
70
  }
104
71
  export interface KauthPermission {
105
72
  id: number;
@@ -125,21 +92,7 @@ export interface KauthPagable<T> {
125
92
  data: T;
126
93
  pagination: MarmotPagination;
127
94
  }
128
- export interface PreAuthorizationAllowed {
129
- allowed: true;
130
- processed: boolean;
131
- id: number;
132
- userId: number;
133
- roleType: 'kauth' | string;
134
- roleName: string;
135
- roleExtendValue: string;
136
- resolvedAuthorizeeTargets: Array<{
137
- type: 'mozi' | 'google' | 'miniprogram';
138
- id: number;
139
- target: string;
140
- }>;
141
- }
142
- export interface PreAuthorization {
95
+ export interface KauthPreAuthorization {
143
96
  id: number;
144
97
  tenantId: string;
145
98
  token: string;
@@ -1,20 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KauthPrincipalStatus = 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 = {}));
3
+ exports.KauthPrincipalStatus = void 0;
18
4
  var KauthPrincipalStatus;
19
5
  (function (KauthPrincipalStatus) {
20
6
  KauthPrincipalStatus[KauthPrincipalStatus["Normal"] = 0] = "Normal";
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.12-alpha.0",
3
+ "version": "2.0.12-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [