joye-backend-utility 4.1.22-test4 → 4.1.22-test5
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/jwt.js +10 -4
- package/package.json +1 -1
package/dist/jwt.js
CHANGED
|
@@ -2,17 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jwtVerify = exports.createToken = void 0;
|
|
4
4
|
const jwt = require('jsonwebtoken');
|
|
5
|
-
const
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
// const JWT_SECRET = '3s6v9y$B&E)H+MbQeThWmZq4t7w!z%C*F-JaNcRfUjXn2r5u8x/A?D(G+KbPeSgV';
|
|
7
|
+
// const JWT_SECRET = '3s6v9y$B&E)H+MbQeThWmZq4t7w!z%C*F-JaNcRfUjXn2r5u8x/A?D(G+KbPeSgV';
|
|
8
|
+
const JWT_PRIVATE_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key`, 'utf8');
|
|
9
|
+
const JWT_PUBLIC_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key.pub`, 'utf8');
|
|
10
|
+
// const JWT_PRIVATE_KEY = '';
|
|
11
|
+
// const JWT_PUBLIC_KEY = '';
|
|
6
12
|
const createToken = async (payload, expiresIn) => {
|
|
7
|
-
const token = jwt.sign(payload,
|
|
13
|
+
const token = jwt.sign(payload, { key: JWT_PRIVATE_KEY.replace(/\\n/gm, '\n'), passphrase: '64d5f73bb3f132821122d68330263edd44023810a1f05efb701fc7ec8d0f6382' }, {
|
|
8
14
|
expiresIn,
|
|
9
|
-
algorithm: '
|
|
15
|
+
algorithm: 'RS256',
|
|
10
16
|
});
|
|
11
17
|
return token;
|
|
12
18
|
};
|
|
13
19
|
exports.createToken = createToken;
|
|
14
20
|
const jwtVerify = async (token) => new Promise(resolve => {
|
|
15
|
-
jwt.verify(token,
|
|
21
|
+
jwt.verify(token, JWT_PUBLIC_KEY.replace(/\\n/gm, '\n'), async (err, decoded) => {
|
|
16
22
|
if (err) {
|
|
17
23
|
return resolve(err);
|
|
18
24
|
}
|