@contentstack/cli-auth 1.2.0 → 1.3.1
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/README.md +5 -3
- package/lib/commands/auth/login.js +51 -17
- package/lib/commands/auth/logout.js +27 -9
- package/lib/utils/auth-handler.js +3 -0
- package/oclif.manifest.json +20 -3
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
|
|
|
18
18
|
$ csdx COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ csdx (--version)
|
|
21
|
-
@contentstack/cli-auth/1.
|
|
21
|
+
@contentstack/cli-auth/1.3.1 linux-x64 node-v16.20.0
|
|
22
22
|
$ csdx --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ csdx COMMAND
|
|
@@ -46,11 +46,12 @@ User sessions login
|
|
|
46
46
|
|
|
47
47
|
```
|
|
48
48
|
USAGE
|
|
49
|
-
$ csdx auth:login [-u <value>] [-p <value>]
|
|
49
|
+
$ csdx auth:login [-u <value> | --oauth] [-p <value> | ]
|
|
50
50
|
|
|
51
51
|
FLAGS
|
|
52
52
|
-p, --password=<value> Password
|
|
53
53
|
-u, --username=<value> User name
|
|
54
|
+
--oauth Enables single sign-on (SSO) in Contentstack CLI
|
|
54
55
|
|
|
55
56
|
DESCRIPTION
|
|
56
57
|
User sessions login
|
|
@@ -226,11 +227,12 @@ User sessions login
|
|
|
226
227
|
|
|
227
228
|
```
|
|
228
229
|
USAGE
|
|
229
|
-
$ csdx login [-u <value>] [-p <value>]
|
|
230
|
+
$ csdx login [-u <value> | --oauth] [-p <value> | ]
|
|
230
231
|
|
|
231
232
|
FLAGS
|
|
232
233
|
-p, --password=<value> Password
|
|
233
234
|
-u, --username=<value> User name
|
|
235
|
+
--oauth Enables single sign-on (SSO) in Contentstack CLI
|
|
234
236
|
|
|
235
237
|
DESCRIPTION
|
|
236
238
|
User sessions login
|
|
@@ -5,30 +5,56 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
class LoginCommand extends cli_command_1.Command {
|
|
7
7
|
async run() {
|
|
8
|
-
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost });
|
|
9
|
-
const { flags: loginFlags } = await this.parse(LoginCommand);
|
|
10
|
-
utils_1.authHandler.client = managementAPIClient;
|
|
11
8
|
try {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost, skipTokenValidity: true });
|
|
10
|
+
const { flags: loginFlags } = await this.parse(LoginCommand);
|
|
11
|
+
utils_1.authHandler.client = managementAPIClient;
|
|
12
|
+
const oauth = loginFlags === null || loginFlags === void 0 ? void 0 : loginFlags.oauth;
|
|
13
|
+
if (oauth === true) {
|
|
14
|
+
cli_utilities_1.authHandler.host = this.cmaHost;
|
|
15
|
+
await cli_utilities_1.authHandler.oauth();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const username = (loginFlags === null || loginFlags === void 0 ? void 0 : loginFlags.username) || (await utils_1.interactive.askUsername());
|
|
19
|
+
const password = (loginFlags === null || loginFlags === void 0 ? void 0 : loginFlags.password) || (await utils_1.interactive.askPassword());
|
|
20
|
+
cli_utilities_1.logger.debug('username', username);
|
|
21
|
+
await this.login(username, password);
|
|
22
|
+
}
|
|
16
23
|
}
|
|
17
24
|
catch (error) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
let errorMessage = '';
|
|
26
|
+
if (error) {
|
|
27
|
+
if (error.message) {
|
|
28
|
+
if (error.message.message) {
|
|
29
|
+
errorMessage = error.message.message;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
errorMessage = error.message;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
errorMessage = error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
cli_utilities_1.logger.error('login failed', errorMessage);
|
|
40
|
+
cli_utilities_1.cliux.error('CLI_AUTH_LOGIN_FAILED');
|
|
41
|
+
cli_utilities_1.cliux.error(errorMessage);
|
|
42
|
+
process.exit();
|
|
21
43
|
}
|
|
22
44
|
}
|
|
23
45
|
async login(username, password) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
try {
|
|
47
|
+
const user = await utils_1.authHandler.login(username, password);
|
|
48
|
+
if (typeof user !== 'object' || !user.authtoken || !user.email) {
|
|
49
|
+
throw new cli_utilities_1.CLIError('Failed to login - invalid response');
|
|
50
|
+
}
|
|
51
|
+
await cli_utilities_1.authHandler.setConfigData('basicAuth', user);
|
|
52
|
+
cli_utilities_1.logger.info('successfully logged in');
|
|
53
|
+
cli_utilities_1.cliux.success('CLI_AUTH_LOGIN_SUCCESS');
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw error;
|
|
27
57
|
}
|
|
28
|
-
cli_utilities_1.configHandler.set('authtoken', user.authtoken);
|
|
29
|
-
cli_utilities_1.configHandler.set('email', user.email);
|
|
30
|
-
cli_utilities_1.logger.info('successfully logged in');
|
|
31
|
-
cli_utilities_1.cliux.success('CLI_AUTH_LOGIN_SUCCESS');
|
|
32
58
|
}
|
|
33
59
|
}
|
|
34
60
|
exports.default = LoginCommand;
|
|
@@ -46,12 +72,20 @@ LoginCommand.flags = {
|
|
|
46
72
|
description: 'User name',
|
|
47
73
|
multiple: false,
|
|
48
74
|
required: false,
|
|
75
|
+
exclusive: ['oauth'],
|
|
49
76
|
}),
|
|
50
77
|
password: cli_utilities_1.flags.string({
|
|
51
78
|
char: 'p',
|
|
52
79
|
description: 'Password',
|
|
53
80
|
multiple: false,
|
|
54
81
|
required: false,
|
|
82
|
+
exclusive: ['oauth'],
|
|
83
|
+
}),
|
|
84
|
+
oauth: cli_utilities_1.flags.boolean({
|
|
85
|
+
description: 'Enables single sign-on (SSO) in Contentstack CLI',
|
|
86
|
+
required: false,
|
|
87
|
+
default: false,
|
|
88
|
+
exclusive: ['username', 'password'],
|
|
55
89
|
}),
|
|
56
90
|
};
|
|
57
91
|
LoginCommand.aliases = ['login'];
|
|
@@ -6,8 +6,6 @@ const utils_1 = require("../../utils");
|
|
|
6
6
|
class LogoutCommand extends cli_command_1.Command {
|
|
7
7
|
async run() {
|
|
8
8
|
const { flags: logoutFlags } = await this.parse(LogoutCommand);
|
|
9
|
-
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost });
|
|
10
|
-
utils_1.authHandler.client = managementAPIClient;
|
|
11
9
|
let confirm = logoutFlags.force === true || logoutFlags.yes === true;
|
|
12
10
|
if (!confirm) {
|
|
13
11
|
confirm = await cli_utilities_1.cliux.inquire({
|
|
@@ -17,26 +15,46 @@ class LogoutCommand extends cli_command_1.Command {
|
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
17
|
try {
|
|
20
|
-
|
|
18
|
+
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost, skipTokenValidity: true });
|
|
19
|
+
utils_1.authHandler.client = managementAPIClient;
|
|
20
|
+
if ((await cli_utilities_1.authHandler.isAuthenticated()) && (await cli_utilities_1.authHandler.isAuthorisationTypeBasic())) {
|
|
21
21
|
if (confirm === true) {
|
|
22
22
|
cli_utilities_1.cliux.loader('CLI_AUTH_LOGOUT_LOADER_START');
|
|
23
|
-
|
|
24
|
-
await utils_1.authHandler.logout(authtoken);
|
|
23
|
+
await utils_1.authHandler.logout(cli_utilities_1.configHandler.get('authtoken'));
|
|
25
24
|
cli_utilities_1.cliux.loader('');
|
|
26
25
|
cli_utilities_1.logger.info('successfully logged out');
|
|
27
26
|
cli_utilities_1.cliux.success('CLI_AUTH_LOGOUT_SUCCESS');
|
|
28
27
|
}
|
|
29
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
cli_utilities_1.cliux.loader('CLI_AUTH_LOGOUT_LOADER_START');
|
|
31
|
+
cli_utilities_1.cliux.loader('');
|
|
32
|
+
cli_utilities_1.logger.info('successfully logged out');
|
|
33
|
+
cli_utilities_1.cliux.success('CLI_AUTH_LOGOUT_SUCCESS');
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
catch (error) {
|
|
32
|
-
|
|
37
|
+
let errorMessage = '';
|
|
38
|
+
if (error) {
|
|
39
|
+
if (error.message) {
|
|
40
|
+
if (error.message.message) {
|
|
41
|
+
errorMessage = error.message.message;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
errorMessage = error.message;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
errorMessage = error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
cli_utilities_1.logger.error('Logout failed', errorMessage);
|
|
33
52
|
cli_utilities_1.cliux.print('CLI_AUTH_LOGOUT_FAILED', { color: 'yellow' });
|
|
34
|
-
cli_utilities_1.cliux.print(
|
|
53
|
+
cli_utilities_1.cliux.print(errorMessage, { color: 'red' });
|
|
35
54
|
}
|
|
36
55
|
finally {
|
|
37
56
|
if (confirm === true) {
|
|
38
|
-
cli_utilities_1.
|
|
39
|
-
cli_utilities_1.configHandler.delete('email');
|
|
57
|
+
await cli_utilities_1.authHandler.setConfigData('logout');
|
|
40
58
|
}
|
|
41
59
|
}
|
|
42
60
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.3.1",
|
|
3
3
|
"commands": {
|
|
4
4
|
"auth:login": {
|
|
5
5
|
"id": "auth:login",
|
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
"char": "u",
|
|
26
26
|
"description": "User name",
|
|
27
27
|
"required": false,
|
|
28
|
-
"multiple": false
|
|
28
|
+
"multiple": false,
|
|
29
|
+
"exclusive": [
|
|
30
|
+
"oauth"
|
|
31
|
+
]
|
|
29
32
|
},
|
|
30
33
|
"password": {
|
|
31
34
|
"name": "password",
|
|
@@ -33,7 +36,21 @@
|
|
|
33
36
|
"char": "p",
|
|
34
37
|
"description": "Password",
|
|
35
38
|
"required": false,
|
|
36
|
-
"multiple": false
|
|
39
|
+
"multiple": false,
|
|
40
|
+
"exclusive": [
|
|
41
|
+
"oauth"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
"oauth": {
|
|
45
|
+
"name": "oauth",
|
|
46
|
+
"type": "boolean",
|
|
47
|
+
"description": "Enables single sign-on (SSO) in Contentstack CLI",
|
|
48
|
+
"required": false,
|
|
49
|
+
"allowNo": false,
|
|
50
|
+
"exclusive": [
|
|
51
|
+
"username",
|
|
52
|
+
"password"
|
|
53
|
+
]
|
|
37
54
|
}
|
|
38
55
|
},
|
|
39
56
|
"args": {}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-auth",
|
|
3
3
|
"description": "Contentstack CLI plugin for authentication activities",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"scripts": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"test:unit": "mocha --forbid-only \"test/unit/*.test.ts\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@contentstack/cli-command": "^1.2.
|
|
25
|
-
"@contentstack/cli-utilities": "^1.
|
|
24
|
+
"@contentstack/cli-command": "^1.2.2",
|
|
25
|
+
"@contentstack/cli-utilities": "^1.3.1",
|
|
26
26
|
"chalk": "^4.0.0",
|
|
27
27
|
"debug": "^4.1.1",
|
|
28
28
|
"inquirer": "8.2.4",
|
|
@@ -74,9 +74,14 @@
|
|
|
74
74
|
"bin": "csdx",
|
|
75
75
|
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-auth/<%- commandPath %>"
|
|
76
76
|
},
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
77
|
+
"csdxConfig": {
|
|
78
|
+
"shortCommandName": {
|
|
79
|
+
"auth:login": "LIN",
|
|
80
|
+
"auth:logout": "LOT",
|
|
81
|
+
"auth:whoami": "WHO",
|
|
82
|
+
"auth:tokens": "LSTKN",
|
|
83
|
+
"auth:tokens:add": "ADTKN",
|
|
84
|
+
"auth:tokens:remove": "RMTKN"
|
|
80
85
|
}
|
|
81
86
|
},
|
|
82
87
|
"repository": "contentstack/cli"
|