@nocobase/auth 2.0.0-alpha.9 → 2.0.0-beta.2
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/auth-manager.d.ts +1 -0
- package/lib/auth-manager.js +37 -1
- package/lib/auth.js +1 -1
- package/lib/base/jwt-service.d.ts +3 -2
- package/lib/base/jwt-service.js +2 -4
- package/package.json +7 -7
package/lib/auth-manager.d.ts
CHANGED
package/lib/auth-manager.js
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
17
|
var __export = (target, all) => {
|
|
@@ -24,6 +26,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
26
|
}
|
|
25
27
|
return to;
|
|
26
28
|
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
27
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
38
|
var auth_manager_exports = {};
|
|
29
39
|
__export(auth_manager_exports, {
|
|
@@ -32,6 +42,9 @@ __export(auth_manager_exports, {
|
|
|
32
42
|
module.exports = __toCommonJS(auth_manager_exports);
|
|
33
43
|
var import_utils = require("@nocobase/utils");
|
|
34
44
|
var import_jwt_service = require("./base/jwt-service");
|
|
45
|
+
var import_path = __toESM(require("path"));
|
|
46
|
+
var import_fs = __toESM(require("fs"));
|
|
47
|
+
var import_crypto = __toESM(require("crypto"));
|
|
35
48
|
const _AuthManager = class _AuthManager {
|
|
36
49
|
/**
|
|
37
50
|
* @internal
|
|
@@ -44,7 +57,11 @@ const _AuthManager = class _AuthManager {
|
|
|
44
57
|
storer;
|
|
45
58
|
constructor(options) {
|
|
46
59
|
this.options = options;
|
|
47
|
-
|
|
60
|
+
const jwtOptions = options.jwt || {};
|
|
61
|
+
if (!jwtOptions.secret) {
|
|
62
|
+
jwtOptions.secret = this.getDefaultJWTSecret();
|
|
63
|
+
}
|
|
64
|
+
this.jwt = new import_jwt_service.JwtService(jwtOptions);
|
|
48
65
|
}
|
|
49
66
|
setStorer(storer) {
|
|
50
67
|
this.storer = storer;
|
|
@@ -125,6 +142,25 @@ const _AuthManager = class _AuthManager {
|
|
|
125
142
|
await next();
|
|
126
143
|
}, "AuthManagerMiddleware");
|
|
127
144
|
}
|
|
145
|
+
getDefaultJWTSecret() {
|
|
146
|
+
const jwtSecretPath = import_path.default.resolve(process.cwd(), "storage", "apps", "main", "jwt_secret.dat");
|
|
147
|
+
const jwtSecretExists = import_fs.default.existsSync(jwtSecretPath);
|
|
148
|
+
if (jwtSecretExists) {
|
|
149
|
+
const key2 = import_fs.default.readFileSync(jwtSecretPath);
|
|
150
|
+
if (key2.length !== 32) {
|
|
151
|
+
throw new Error("Invalid api key length in file");
|
|
152
|
+
}
|
|
153
|
+
return key2;
|
|
154
|
+
}
|
|
155
|
+
const envKey = process.env.APP_KEY;
|
|
156
|
+
if (envKey && envKey !== "your-secret-key" && envKey !== "test-key") {
|
|
157
|
+
return envKey;
|
|
158
|
+
}
|
|
159
|
+
const key = import_crypto.default.randomBytes(32);
|
|
160
|
+
import_fs.default.mkdirSync(import_path.default.dirname(jwtSecretPath), { recursive: true });
|
|
161
|
+
import_fs.default.writeFileSync(jwtSecretPath, key, { mode: 384 });
|
|
162
|
+
return key;
|
|
163
|
+
}
|
|
128
164
|
};
|
|
129
165
|
__name(_AuthManager, "AuthManager");
|
|
130
166
|
let AuthManager = _AuthManager;
|
package/lib/auth.js
CHANGED
|
@@ -73,7 +73,7 @@ const _Auth = class _Auth {
|
|
|
73
73
|
}
|
|
74
74
|
const { resourceName, actionName } = this.ctx.action;
|
|
75
75
|
const acl = this.ctx.dataSource.acl;
|
|
76
|
-
const isPublic = await acl.allowManager.
|
|
76
|
+
const isPublic = await acl.allowManager.isPublic(resourceName, actionName, this.ctx);
|
|
77
77
|
return isPublic;
|
|
78
78
|
}
|
|
79
79
|
// The following methods are mainly designed for user authentications.
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
/// <reference types="node" />
|
|
9
10
|
import jwt, { JwtPayload, SignOptions } from 'jsonwebtoken';
|
|
10
11
|
import { ITokenBlacklistService } from './token-blacklist-service';
|
|
11
12
|
export interface JwtOptions {
|
|
12
|
-
secret: string;
|
|
13
|
+
secret: Buffer | string;
|
|
13
14
|
expiresIn?: string;
|
|
14
15
|
}
|
|
15
16
|
export type SignPayload = Parameters<typeof jwt.sign>[0];
|
|
16
17
|
export declare class JwtService {
|
|
17
18
|
protected options: JwtOptions;
|
|
18
|
-
constructor(options
|
|
19
|
+
constructor(options: JwtOptions);
|
|
19
20
|
blacklist: ITokenBlacklistService;
|
|
20
21
|
private expiresIn;
|
|
21
22
|
private secret;
|
package/lib/base/jwt-service.js
CHANGED
|
@@ -42,13 +42,11 @@ __export(jwt_service_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(jwt_service_exports);
|
|
43
43
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
44
44
|
const _JwtService = class _JwtService {
|
|
45
|
-
constructor(options
|
|
46
|
-
secret: process.env.APP_KEY
|
|
47
|
-
}) {
|
|
45
|
+
constructor(options) {
|
|
48
46
|
this.options = options;
|
|
49
47
|
const { secret, expiresIn } = options;
|
|
50
48
|
this.options = {
|
|
51
|
-
secret
|
|
49
|
+
secret,
|
|
52
50
|
expiresIn: expiresIn || process.env.JWT_EXPIRES_IN || "7d"
|
|
53
51
|
};
|
|
54
52
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/auth",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/actions": "2.0.0-
|
|
10
|
-
"@nocobase/cache": "2.0.0-
|
|
11
|
-
"@nocobase/database": "2.0.0-
|
|
12
|
-
"@nocobase/resourcer": "2.0.0-
|
|
13
|
-
"@nocobase/utils": "2.0.0-
|
|
9
|
+
"@nocobase/actions": "2.0.0-beta.2",
|
|
10
|
+
"@nocobase/cache": "2.0.0-beta.2",
|
|
11
|
+
"@nocobase/database": "2.0.0-beta.2",
|
|
12
|
+
"@nocobase/resourcer": "2.0.0-beta.2",
|
|
13
|
+
"@nocobase/utils": "2.0.0-beta.2",
|
|
14
14
|
"@types/jsonwebtoken": "^9.0.9",
|
|
15
15
|
"jsonwebtoken": "^9.0.2"
|
|
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": "b77a33ee933ae6e09d2d5dce017ca15d8552d57b"
|
|
23
23
|
}
|