Skip to content

Commit 5f162ab

Browse files
committed
fix jwt token
1 parent 4cc20ac commit 5f162ab

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ $ vim config/config.js
8282
//文件下载地址 CodePush Server 地址 + '/download' download对应app.js里面的地址
8383
downloadUrl: "http://localhost:3000/download"
8484
},
85+
jwt: {
86+
// 登录jwt签名密钥,必须更改,否则有安全隐患,可以使用随机生成的字符串
87+
// Recommended: 63 random alpha-numeric characters
88+
// Generate using: https://www.grc.com/passwords.htm
89+
tokenSecret: 'INSERT_RANDOM_TOKEN_KEY'
90+
},
8591
common: {
86-
//登录jwt签名密钥,必须更改,否则有安全隐患,可以使用随机生成的字符串
87-
loginSecret: "CodePushServer",
8892
dataDir: "/Users/tablee/workspaces/data",
8993
//选择存储类型,目前支持local和qiniu配置
9094
storageType: "local"
@@ -110,7 +114,7 @@ or point config file and ENV
110114
$ CONFIG_FILE=/path/to/config.js NODE_ENV=production node ./bin/www # or CONFIG_FILE=/path/to/config.js NODE_ENV=production code-push-server
111115
```
112116

113-
notice. you have to change `loginSecret` in config.js for security.
117+
notice. you have to change `tokenSecret` in config.js for security.
114118

115119
## Default listen Host/Port 0.0.0.0/3000
116120
you can change like this.
@@ -215,7 +219,6 @@ eg.
215219
```json
216220
...
217221
"common": {
218-
"loginSecret": "CodePushServer",
219222
"codePushWebUrl": "Your CodePush Web address",
220223
}
221224
...

config/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ config.development = {
3030
// public static download spacename.
3131
public: '/download'
3232
},
33+
jwt: {
34+
// Recommended: 63 random alpha-numeric characters
35+
// Generate using: https://www.grc.com/passwords.htm
36+
tokenSecret: 'INSERT_RANDOM_TOKEN_KEY'
37+
},
3338
common: {
34-
// jwt sign secret for auth. you have to modify it for security. use random string instead it.
35-
loginSecret: "CodePushServer",
3639
/*
3740
* tryLoginTimes is control login error times to avoid force attack.
3841
* if value is 0, no limit for login auth, it may not safe for account. when it's a number, it means you can

config/config.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ config.test = {
1414
downloadUrl: "http://localhost:3000/download",
1515
public: '/download'
1616
},
17+
jwt: {
18+
tokenSecret: 'INSERT_RANDOM_TOKEN_KEY'
19+
},
1720
common: {
18-
loginSecret: "CodePushServer",
1921
tryLoginTimes: 10,
2022
diffNums: 3,
2123
dataDir: os.tmpdir(),

config/config.testwin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ config.test = {
1414
downloadUrl: "http://localhost:3000/download",
1515
public: '/download'
1616
},
17+
jwt: {
18+
tokenSecret: 'INSERT_RANDOM_TOKEN_KEY'
19+
},
1720
common: {
18-
loginSecret: "CodePushServer",
1921
tryLoginTimes: 10,
2022
diffNums: 3,
2123
dataDir: os.tmpdir(),

core/middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ var checkAccessToken = function (accessToken) {
3636
throw new Error('401 Unauthorized');
3737
}
3838
var config = require('../core/config');
39-
var loginSecret = _.get(config, 'common.loginSecret');
39+
var tokenSecret = _.get(config, 'jwt.tokenSecret');
4040
var jwt = require('jsonwebtoken');
41-
var authData = jwt.verify(accessToken, loginSecret);
41+
var authData = jwt.verify(accessToken, tokenSecret);
4242
var uid = _.get(authData, 'uid', null);
4343
var hash = _.get(authData, 'hash', null);
4444
if (parseInt(uid) > 0) {

routes/auth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ router.post('/login', function(req, res) {
5050
var account = _.trim(req.body.account);
5151
var password = _.trim(req.body.password);
5252
var config = require('../core/config');
53-
var loginSecret = _.get(config, 'common.loginSecret');
53+
var tokenSecret = _.get(config, 'jwt.tokenSecret');
5454
accountManager.login(account, password)
5555
.then(function (users) {
5656
var jwt = require('jsonwebtoken');
57-
return jwt.sign({ uid: users.id, hash: security.md5(users.ack_code), expiredIn: 7200 }, loginSecret);
57+
return jwt.sign({ uid: users.id, hash: security.md5(users.ack_code), expiredIn: 7200 }, tokenSecret);
5858
})
5959
.then(function (token) {
6060
res.send({status:'OK', results: {tokens: token}});

0 commit comments

Comments
 (0)