@nocobase/auth 0.20.0-alpha.9 → 0.21.0-alpha.10
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/lib/actions.js +1 -0
- package/lib/auth-manager.d.ts +3 -0
- package/lib/auth-manager.js +5 -2
- package/lib/base/auth.d.ts +9 -0
- package/lib/base/auth.js +10 -1
- package/lib/base/jwt-service.js +2 -0
- package/package.json +7 -7
package/lib/actions.js
CHANGED
package/lib/auth-manager.d.ts
CHANGED
package/lib/auth-manager.js
CHANGED
|
@@ -24,6 +24,9 @@ module.exports = __toCommonJS(auth_manager_exports);
|
|
|
24
24
|
var import_utils = require("@nocobase/utils");
|
|
25
25
|
var import_jwt_service = require("./base/jwt-service");
|
|
26
26
|
const _AuthManager = class _AuthManager {
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
27
30
|
jwt;
|
|
28
31
|
options;
|
|
29
32
|
authTypes = new import_utils.Registry();
|
|
@@ -73,9 +76,9 @@ const _AuthManager = class _AuthManager {
|
|
|
73
76
|
if (!authenticator) {
|
|
74
77
|
throw new Error(`Authenticator [${name}] is not found.`);
|
|
75
78
|
}
|
|
76
|
-
const { auth } = this.authTypes.get(authenticator.authType);
|
|
79
|
+
const { auth } = this.authTypes.get(authenticator.authType) || {};
|
|
77
80
|
if (!auth) {
|
|
78
|
-
throw new Error(`AuthType [${
|
|
81
|
+
throw new Error(`AuthType [${authenticator.authType}] is not found.`);
|
|
79
82
|
}
|
|
80
83
|
return new auth({ authenticator, options: authenticator.options, ctx });
|
|
81
84
|
}
|
package/lib/base/auth.d.ts
CHANGED
|
@@ -11,10 +11,19 @@ export declare class BaseAuth extends Auth {
|
|
|
11
11
|
userCollection: Collection;
|
|
12
12
|
});
|
|
13
13
|
get userRepository(): import("@nocobase/database").Repository<any, any>;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
14
17
|
get jwt(): JwtService;
|
|
15
18
|
set user(user: Model);
|
|
16
19
|
get user(): Model;
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
17
23
|
getCacheKey(userId: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
18
27
|
validateUsername(username: string): boolean;
|
|
19
28
|
check(): Promise<any>;
|
|
20
29
|
validate(): Promise<Model>;
|
package/lib/base/auth.js
CHANGED
|
@@ -32,6 +32,9 @@ const _BaseAuth = class _BaseAuth extends import_auth.Auth {
|
|
|
32
32
|
get userRepository() {
|
|
33
33
|
return this.userCollection.repository;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
35
38
|
get jwt() {
|
|
36
39
|
return this.ctx.app.authManager.jwt;
|
|
37
40
|
}
|
|
@@ -41,9 +44,15 @@ const _BaseAuth = class _BaseAuth extends import_auth.Auth {
|
|
|
41
44
|
get user() {
|
|
42
45
|
return this.ctx.state.currentUser;
|
|
43
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
44
50
|
getCacheKey(userId) {
|
|
45
51
|
return `auth:${userId}`;
|
|
46
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
47
56
|
validateUsername(username) {
|
|
48
57
|
return /^[^@.<>"'/]{2,16}$/.test(username);
|
|
49
58
|
}
|
|
@@ -80,7 +89,7 @@ const _BaseAuth = class _BaseAuth extends import_auth.Auth {
|
|
|
80
89
|
try {
|
|
81
90
|
user = await this.validate();
|
|
82
91
|
} catch (err) {
|
|
83
|
-
this.ctx.throw(401, err.message);
|
|
92
|
+
this.ctx.throw(err.status || 401, err.message);
|
|
84
93
|
}
|
|
85
94
|
if (!user) {
|
|
86
95
|
this.ctx.throw(401, "Unauthorized");
|
package/lib/base/jwt-service.js
CHANGED
|
@@ -50,6 +50,7 @@ const _JwtService = class _JwtService {
|
|
|
50
50
|
secret() {
|
|
51
51
|
return this.options.secret;
|
|
52
52
|
}
|
|
53
|
+
/* istanbul ignore next -- @preserve */
|
|
53
54
|
sign(payload, options) {
|
|
54
55
|
const opt = { expiresIn: this.expiresIn(), ...options };
|
|
55
56
|
if (opt.expiresIn === "never") {
|
|
@@ -57,6 +58,7 @@ const _JwtService = class _JwtService {
|
|
|
57
58
|
}
|
|
58
59
|
return import_jsonwebtoken.default.sign(payload, this.secret(), opt);
|
|
59
60
|
}
|
|
61
|
+
/* istanbul ignore next -- @preserve */
|
|
60
62
|
decode(token) {
|
|
61
63
|
return new Promise((resolve, reject) => {
|
|
62
64
|
import_jsonwebtoken.default.verify(token, this.secret(), (err, decoded) => {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/actions": "0.
|
|
10
|
-
"@nocobase/cache": "0.
|
|
11
|
-
"@nocobase/database": "0.
|
|
12
|
-
"@nocobase/resourcer": "0.
|
|
13
|
-
"@nocobase/utils": "0.
|
|
9
|
+
"@nocobase/actions": "0.21.0-alpha.10",
|
|
10
|
+
"@nocobase/cache": "0.21.0-alpha.10",
|
|
11
|
+
"@nocobase/database": "0.21.0-alpha.10",
|
|
12
|
+
"@nocobase/resourcer": "0.21.0-alpha.10",
|
|
13
|
+
"@nocobase/utils": "0.21.0-alpha.10",
|
|
14
14
|
"@types/jsonwebtoken": "^8.5.8",
|
|
15
15
|
"jsonwebtoken": "^8.5.1"
|
|
16
16
|
},
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
20
20
|
"directory": "packages/auth"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "98adf5ec996a4f359c6ca1c4a6ac837c43b6e268"
|
|
23
23
|
}
|