soul-cli 0.7.6 → 0.7.7
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/.env.sample +2 -2
- package/README.md +16 -16
- package/package.json +1 -1
- package/src/cli.js +0 -4
- package/src/config/index.js +12 -8
- package/src/controllers/auth/common.js +9 -1
- package/src/controllers/auth/index.js +2 -1
- package/src/index.js +4 -1
package/.env.sample
CHANGED
package/README.md
CHANGED
|
@@ -36,12 +36,12 @@ Options:
|
|
|
36
36
|
-c, --cors CORS whitelist origins [string]
|
|
37
37
|
-a, --auth Enable authentication and authorization [boolean]
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
--iuu, --initialuserusername Initial user username [string]
|
|
40
|
+
--iup, --initialuserpassword Initial user password [string]
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
--ts, --tokensecret Token Secret [string]
|
|
43
|
+
--atet, --accesstokenexpirationtime Access Token Expiration Time (Default: 5H) [string]
|
|
44
|
+
--rtet, --refreshtokenexpirationtime Refresh Token Expiration Time (Default: 1D) [string]
|
|
45
45
|
-S, --studio Start Soul Studio in parallel
|
|
46
46
|
--help Show help
|
|
47
47
|
|
|
@@ -63,7 +63,7 @@ Run the Soul command with the necessary parameters:
|
|
|
63
63
|
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
soul
|
|
66
|
+
soul -d foobar.db -a --ts=<your_jwt_secret_value> --atet=4H --rtet=3D --iuu=john --iup=<your_password>
|
|
67
67
|
|
|
68
68
|
```
|
|
69
69
|
|
|
@@ -72,30 +72,30 @@ Note: When configuring your JWT Secret, it is recommended to use a long string v
|
|
|
72
72
|
In this example:
|
|
73
73
|
|
|
74
74
|
The `-a` flag instructs Soul to run in auth mode.
|
|
75
|
-
The
|
|
76
|
-
The
|
|
77
|
-
The
|
|
78
|
-
The
|
|
79
|
-
The
|
|
75
|
+
The `--ts` flag allows you to pass a JWT secret value for the `access and refresh tokens` generation and verification. Replace <your_jwt_secret_value> with your desired secret value.
|
|
76
|
+
The `--atet` flag sets the JWT expiration time for the access token. In this case, it is set to four hours (4H), meaning the token will expire after 4 hours.
|
|
77
|
+
The `--rtet` flag sets the JWT expiration time for the refresh token. In this case, it is set to three days (3D), meaning the token will expire after 3 days.
|
|
78
|
+
The `--iuu` flag is used to pass a username for the initial user
|
|
79
|
+
The `--iup` flag is used to pass a password for the initial user
|
|
80
80
|
|
|
81
|
-
Here are some example values for the
|
|
81
|
+
Here are some example values for the `atet` and `rtet` flags
|
|
82
82
|
|
|
83
83
|
- 60M: Represents a duration of 60 minutes.
|
|
84
84
|
- 5H: Represents a duration of 5 hours.
|
|
85
85
|
- 1D: Represents a duration of 1 day.
|
|
86
86
|
|
|
87
|
-
NOTE: It is crucial to securely store a copy of the
|
|
87
|
+
NOTE: It is crucial to securely store a copy of the `--ts`(`Token Secret`) value used in Soul. Once you pass this values, make sure to keep a backup because you will need it every time you restart Soul. Losing this secret values can result in a situation where all of your users are blocked from accessing Soul.
|
|
88
88
|
|
|
89
89
|
### 3. Updating Super Users
|
|
90
90
|
|
|
91
91
|
To modify a superuser information in a database, you can utilize the `updatesuperuser` command. This command allows you to change a superuser's `password` or upgrade/downgrade a normal user to a `superuser`. Below is an example of how to use it:
|
|
92
92
|
|
|
93
93
|
```
|
|
94
|
-
soul
|
|
94
|
+
soul -d foobar.db updatesuperuser --id=1 password=<new_password_for_the_user> // Update the password for the superuser with ID 1
|
|
95
95
|
|
|
96
|
-
soul
|
|
96
|
+
soul -d foobar.db updatesuperuser --id=1 --is_superuser=true // Upgrade the user with ID 1 to a superuser
|
|
97
97
|
|
|
98
|
-
soul
|
|
98
|
+
soul -d foobar.db updatesuperuser --id=1 --is_superuser=false // Revoke the superuser role from the superuser with ID 1
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
## Documentation
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -50,28 +50,24 @@ if (process.env.NO_CLI !== 'true') {
|
|
|
50
50
|
alias: 'auth',
|
|
51
51
|
describe: 'Enable authentication and authorization',
|
|
52
52
|
type: 'boolean',
|
|
53
|
-
default: false,
|
|
54
53
|
demandOption: false,
|
|
55
54
|
})
|
|
56
55
|
.options('ts', {
|
|
57
56
|
alias: 'tokensecret',
|
|
58
57
|
describe: 'JWT secret for the access and refresh tokens',
|
|
59
58
|
type: 'string',
|
|
60
|
-
default: null,
|
|
61
59
|
demandOption: false,
|
|
62
60
|
})
|
|
63
61
|
.options('atet', {
|
|
64
62
|
alias: 'accesstokenexpirationtime',
|
|
65
63
|
describe: 'JWT expiration time for access token',
|
|
66
64
|
type: 'string',
|
|
67
|
-
default: '5H',
|
|
68
65
|
demandOption: false,
|
|
69
66
|
})
|
|
70
67
|
.options('rtet', {
|
|
71
68
|
alias: 'refreshtokenexpirationtime',
|
|
72
69
|
describe: 'JWT expiration time for refresh token',
|
|
73
70
|
type: 'string',
|
|
74
|
-
default: '3D',
|
|
75
71
|
demandOption: false,
|
|
76
72
|
})
|
|
77
73
|
.options('iuu', {
|
package/src/config/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const envVarsSchema = Joi.object()
|
|
|
20
20
|
VERBOSE: Joi.string().valid('console', null).default(null),
|
|
21
21
|
|
|
22
22
|
CORS_ORIGIN_WHITELIST: Joi.string().default('*'),
|
|
23
|
-
AUTH: Joi.boolean()
|
|
23
|
+
AUTH: Joi.boolean(),
|
|
24
24
|
|
|
25
25
|
RATE_LIMIT_ENABLED: Joi.boolean().default(false),
|
|
26
26
|
RATE_LIMIT_WINDOW_MS: Joi.number().positive().default(1000),
|
|
@@ -33,9 +33,9 @@ const envVarsSchema = Joi.object()
|
|
|
33
33
|
INITIAL_USER_USERNAME: Joi.string(),
|
|
34
34
|
INITIAL_USER_PASSWORD: Joi.string(),
|
|
35
35
|
|
|
36
|
-
TOKEN_SECRET: Joi.string()
|
|
37
|
-
ACCESS_TOKEN_EXPIRATION_TIME: Joi.string()
|
|
38
|
-
REFRESH_TOKEN_EXPIRATION_TIME: Joi.string()
|
|
36
|
+
TOKEN_SECRET: Joi.string(),
|
|
37
|
+
ACCESS_TOKEN_EXPIRATION_TIME: Joi.string(),
|
|
38
|
+
REFRESH_TOKEN_EXPIRATION_TIME: Joi.string(),
|
|
39
39
|
})
|
|
40
40
|
.unknown();
|
|
41
41
|
|
|
@@ -113,12 +113,16 @@ module.exports = {
|
|
|
113
113
|
envVars.CORS_ORIGIN_WHITELIST?.split(',') || ['*'],
|
|
114
114
|
},
|
|
115
115
|
|
|
116
|
-
auth: argv.auth || envVars.AUTH,
|
|
117
|
-
tokenSecret: argv.tokensecret || envVars.TOKEN_SECRET,
|
|
116
|
+
auth: argv.auth || envVars.AUTH || false,
|
|
117
|
+
tokenSecret: argv.tokensecret || envVars.TOKEN_SECRET || null,
|
|
118
118
|
accessTokenExpirationTime:
|
|
119
|
-
argv.accesstokenexpirationtime ||
|
|
119
|
+
argv.accesstokenexpirationtime ||
|
|
120
|
+
envVars.ACCESS_TOKEN_EXPIRATION_TIME ||
|
|
121
|
+
'5H',
|
|
120
122
|
refreshTokenExpirationTime:
|
|
121
|
-
argv.refreshtokenexpirationtime ||
|
|
123
|
+
argv.refreshtokenexpirationtime ||
|
|
124
|
+
envVars.REFRESH_TOKEN_EXPIRATION_TIME ||
|
|
125
|
+
'3D',
|
|
122
126
|
|
|
123
127
|
initialUserUsername:
|
|
124
128
|
argv.initialuserusername || envVars.INITIAL_USER_USERNAME,
|
|
@@ -13,4 +13,12 @@ const isUsernameTaken = (username) => {
|
|
|
13
13
|
return users.length > 0;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const checkAuthConfigs = ({ auth, tokenSecret }) => {
|
|
17
|
+
if (auth && !tokenSecret) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
'You need to provide a token secret either from the CLI or from your environment variables',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = { isUsernameTaken, checkAuthConfigs };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const users = require('./user');
|
|
2
2
|
const token = require('./token');
|
|
3
3
|
const tables = require('./tables');
|
|
4
|
+
const { checkAuthConfigs } = require('./common');
|
|
4
5
|
|
|
5
|
-
module.exports = { ...users, ...token, ...tables };
|
|
6
|
+
module.exports = { ...users, ...token, ...tables, checkAuthConfigs };
|
package/src/index.js
CHANGED
|
@@ -23,11 +23,11 @@ const {
|
|
|
23
23
|
createDefaultTables,
|
|
24
24
|
createInitialUser,
|
|
25
25
|
removeRevokedRefreshTokens,
|
|
26
|
+
checkAuthConfigs,
|
|
26
27
|
} = require('./controllers/auth');
|
|
27
28
|
|
|
28
29
|
const { runCLICommands } = require('./commands');
|
|
29
30
|
const { authConstants } = require('./constants');
|
|
30
|
-
|
|
31
31
|
const app = express();
|
|
32
32
|
app.get('/health', (req, res) => {
|
|
33
33
|
res.send('OK');
|
|
@@ -85,6 +85,9 @@ if (config.rateLimit.enabled) {
|
|
|
85
85
|
app.use(limiter);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
// If Auth mode is activated but if the tokenSecret value is undefined then throw an error
|
|
89
|
+
checkAuthConfigs({ auth: config.auth, tokenSecret: config.tokenSecret });
|
|
90
|
+
|
|
88
91
|
// If Auth mode is activated then create auth tables in the DB & create a super user if there are no users in the DB
|
|
89
92
|
if (config.auth) {
|
|
90
93
|
createDefaultTables();
|