@contentstack/cli-auth 0.1.1-beta.1 → 0.1.1-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/README.md CHANGED
@@ -1,29 +1,33 @@
1
- @contentstack/cli-auth
2
- ===
1
+ # @contentstack/cli-auth
3
2
 
4
3
  It is Contentstack’s CLI plugin to perform authentication-related activities. To get started with authenticating yourself with the CLI, refer to the [CLI’s Authentication documentation](https://www.contentstack.com/docs/developers/cli/authentication)
5
4
 
6
5
  [![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
7
6
 
8
7
  <!-- toc -->
8
+ * [@contentstack/cli-auth](#contentstackcli-auth)
9
9
  * [Usage](#usage)
10
10
  * [Commands](#commands)
11
11
  <!-- tocstop -->
12
+
12
13
  # Usage
14
+
13
15
  <!-- usage -->
14
16
  ```sh-session
15
17
  $ npm install -g @contentstack/cli-auth
16
18
  $ csdx COMMAND
17
19
  running command...
18
20
  $ csdx (-v|--version|version)
19
- @contentstack/cli-auth/0.1.1-beta.1 darwin-x64 node-v10.19.0
21
+ @contentstack/cli-auth/0.1.1-beta.2 linux-x64 node-v12.22.7
20
22
  $ csdx --help [COMMAND]
21
23
  USAGE
22
24
  $ csdx COMMAND
23
25
  ...
24
26
  ```
25
27
  <!-- usagestop -->
28
+
26
29
  # Commands
30
+
27
31
  <!-- commands -->
28
32
  * [`csdx auth:login`](#csdx-authlogin)
29
33
  * [`csdx auth:logout`](#csdx-authlogout)
@@ -37,6 +41,8 @@ USAGE
37
41
  Login to Contentstack and save the session for further use
38
42
 
39
43
  ```
44
+ Login to Contentstack and save the session for further use
45
+
40
46
  USAGE
41
47
  $ csdx auth:login
42
48
 
@@ -47,13 +53,15 @@ ALIASES
47
53
  $ csdx login
48
54
  ```
49
55
 
50
- _See code: [src/commands/auth/login.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/packages/auth/src/commands/auth/login.js)_
56
+ _See code: [src/commands/auth/login.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.2/packages/auth/src/commands/auth/login.js)_
51
57
 
52
58
  ## `csdx auth:logout`
53
59
 
54
60
  Log out from Contentstack and clear the session
55
61
 
56
62
  ```
63
+ Log out from Contentstack and clear the session
64
+
57
65
  USAGE
58
66
  $ csdx auth:logout
59
67
 
@@ -64,13 +72,16 @@ ALIASES
64
72
  $ csdx logout
65
73
  ```
66
74
 
67
- _See code: [src/commands/auth/logout.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/packages/auth/src/commands/auth/logout.js)_
75
+ _See code: [src/commands/auth/logout.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.2/packages/auth/src/commands/auth/logout.js)_
68
76
 
69
77
  ## `csdx auth:tokens`
70
78
 
71
79
  Lists all existing tokens added to the session
72
80
 
73
81
  ```
82
+ Lists all existing tokens added to the session
83
+
84
+
74
85
  USAGE
75
86
  $ csdx auth:tokens
76
87
 
@@ -88,13 +99,16 @@ ALIASES
88
99
  $ csdx tokens
89
100
  ```
90
101
 
91
- _See code: [src/commands/auth/tokens/index.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/packages/auth/src/commands/auth/tokens/index.js)_
102
+ _See code: [src/commands/auth/tokens/index.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.2/packages/auth/src/commands/auth/tokens/index.js)_
92
103
 
93
104
  ## `csdx auth:tokens:add`
94
105
 
95
106
  Adds management/delivery tokens to your session to use it with further CLI command
96
107
 
97
108
  ```
109
+ Adds management/delivery tokens to your session to use it with further CLI command
110
+ by default it adds management token if either of management or delivery flags are not set
111
+
98
112
  USAGE
99
113
  $ csdx auth:tokens:add
100
114
 
@@ -116,13 +130,15 @@ ALIASES
116
130
  $ csdx tokens:add
117
131
  ```
118
132
 
119
- _See code: [src/commands/auth/tokens/add.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/packages/auth/src/commands/auth/tokens/add.js)_
133
+ _See code: [src/commands/auth/tokens/add.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.2/packages/auth/src/commands/auth/tokens/add.js)_
120
134
 
121
135
  ## `csdx auth:tokens:remove`
122
136
 
123
137
  Removes stored tokens
124
138
 
125
139
  ```
140
+ Removes stored tokens
141
+
126
142
  USAGE
127
143
  $ csdx auth:tokens:remove
128
144
 
@@ -136,13 +152,16 @@ ALIASES
136
152
  $ csdx tokens:remove
137
153
  ```
138
154
 
139
- _See code: [src/commands/auth/tokens/remove.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/packages/auth/src/commands/auth/tokens/remove.js)_
155
+ _See code: [src/commands/auth/tokens/remove.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.2/packages/auth/src/commands/auth/tokens/remove.js)_
140
156
 
141
157
  ## `csdx auth:whoami`
142
158
 
143
159
  Display current users email address
144
160
 
145
161
  ```
162
+ Display current users email address
163
+
164
+
146
165
  USAGE
147
166
  $ csdx auth:whoami
148
167
 
@@ -150,5 +169,5 @@ ALIASES
150
169
  $ csdx whoami
151
170
  ```
152
171
 
153
- _See code: [src/commands/auth/whoami.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/packages/auth/src/commands/auth/whoami.js)_
172
+ _See code: [src/commands/auth/whoami.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.2/packages/auth/src/commands/auth/whoami.js)_
154
173
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.1","commands":{"auth:login":{"id":"auth:login","description":"Login to Contentstack and save the session for further use","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["login"],"flags":{"username":{"name":"username","type":"option","char":"u","description":"Email address of your Contentstack account"}},"args":[]},"auth:logout":{"id":"auth:logout","description":"Log out from Contentstack and clear the session","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["logout"],"flags":{"force":{"name":"force","type":"boolean","char":"f","description":"Exclude confirmation to logout","allowNo":false}},"args":[]},"auth:whoami":{"id":"auth:whoami","description":"Display current users email address\n","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["whoami"],"flags":{},"args":[]},"auth:tokens:add":{"id":"auth:tokens:add","description":"Adds management/delivery tokens to your session to use it with further CLI command\nby default it adds management token if either of management or delivery flags are not set","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens:add"],"flags":{"alias":{"name":"alias","type":"option","char":"a"},"delivery":{"name":"delivery","type":"boolean","char":"d","description":"Set this while saving delivery token","allowNo":false},"management":{"name":"management","type":"boolean","char":"m","description":"Set this while saving management token","allowNo":false},"environment":{"name":"environment","type":"option","char":"e","description":"Environment name for delivery token"},"api-key":{"name":"api-key","type":"option","char":"k","description":"Stack API key for the token"},"force":{"name":"force","type":"boolean","char":"f","description":"Exclude confirmation to replace existing alias","allowNo":false},"token":{"name":"token","type":"option","char":"t","description":"Sets token. Can be set via environment variable 'TOKEN'. We recommend to use env variable"}},"args":[]},"auth:tokens":{"id":"auth:tokens","description":"Lists all existing tokens added to the session \n","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens"],"flags":{"columns":{"name":"columns","type":"option","description":"only show provided columns (comma-separated)"},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)"},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo"},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","options":["csv","json","yaml"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false}},"args":[]},"auth:tokens:remove":{"id":"auth:tokens:remove","description":"Removes stored tokens","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens:remove"],"flags":{"alias":{"name":"alias","type":"option","char":"a","description":"Alias (name) of the token to remove"},"ignore":{"name":"ignore","type":"boolean","char":"i","description":"Ignores if token not present. Command shows show list of available aliases with multi select option to delete tokens from that list.","allowNo":false}},"args":[]}}}
1
+ {"version":"0.1.1-beta.2","commands":{"auth:login":{"id":"auth:login","description":"Login to Contentstack and save the session for further use","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["login"],"flags":{"username":{"name":"username","type":"option","char":"u","description":"Email address of your Contentstack account"}},"args":[]},"auth:logout":{"id":"auth:logout","description":"Log out from Contentstack and clear the session","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["logout"],"flags":{"force":{"name":"force","type":"boolean","char":"f","description":"Exclude confirmation to logout","allowNo":false}},"args":[]},"auth:whoami":{"id":"auth:whoami","description":"Display current users email address\n","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["whoami"],"flags":{},"args":[]},"auth:tokens:add":{"id":"auth:tokens:add","description":"Adds management/delivery tokens to your session to use it with further CLI command\nby default it adds management token if either of management or delivery flags are not set","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens:add"],"flags":{"alias":{"name":"alias","type":"option","char":"a"},"delivery":{"name":"delivery","type":"boolean","char":"d","description":"Set this while saving delivery token","allowNo":false},"management":{"name":"management","type":"boolean","char":"m","description":"Set this while saving management token","allowNo":false},"environment":{"name":"environment","type":"option","char":"e","description":"Environment name for delivery token"},"api-key":{"name":"api-key","type":"option","char":"k","description":"Stack API key for the token"},"force":{"name":"force","type":"boolean","char":"f","description":"Exclude confirmation to replace existing alias","allowNo":false},"token":{"name":"token","type":"option","char":"t","description":"Sets token. Can be set via environment variable 'TOKEN'. We recommend to use env variable"}},"args":[]},"auth:tokens":{"id":"auth:tokens","description":"Lists all existing tokens added to the session \n","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens"],"flags":{"columns":{"name":"columns","type":"option","description":"only show provided columns (comma-separated)"},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)"},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo"},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","options":["csv","json","yaml"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false}},"args":[]},"auth:tokens:remove":{"id":"auth:tokens:remove","description":"Removes stored tokens","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens:remove"],"flags":{"alias":{"name":"alias","type":"option","char":"a","description":"Alias (name) of the token to remove"},"ignore":{"name":"ignore","type":"boolean","char":"i","description":"Ignores if token not present. Command shows show list of available aliases with multi select option to delete tokens from that list.","allowNo":false}},"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": "0.1.1-beta.1",
4
+ "version": "0.1.1-beta.2",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -37,7 +37,9 @@
37
37
  ],
38
38
  "homepage": "https://github.com/contentstack/cli",
39
39
  "keywords": [
40
- "contentstack","cli", "plugin"
40
+ "contentstack",
41
+ "cli",
42
+ "plugin"
41
43
  ],
42
44
  "license": "MIT",
43
45
  "oclif": {
@@ -50,7 +52,6 @@
50
52
  },
51
53
  "repository": "https://github.com/contentstack/cli",
52
54
  "scripts": {
53
- "pack": "npm pack && mv *.tgz ../../build/",
54
55
  "postpack": "rm -f oclif.manifest.json",
55
56
  "posttest": "npx eslint .",
56
57
  "prepack": "oclif-dev manifest && oclif-dev readme",
@@ -20,7 +20,7 @@ class LoginCommand extends Command {
20
20
 
21
21
  const password = await cli.prompt(messages.promptPassword, {type: 'hide'})
22
22
  try {
23
- const user = await authHandler.login(username, password)
23
+ const user = await authHandler.login(username, password)
24
24
  debug('User object ', user)
25
25
  config.set('authtoken', user.authtoken)
26
26
  config.set('email', user.email)
@@ -1,3 +1,7 @@
1
+ const { cli } = require('cli-ux')
2
+ const inquirer = require('inquirer')
3
+ const chalk = require('chalk')
4
+
1
5
  let client = {}
2
6
 
3
7
  class AuthHandler {
@@ -12,18 +16,59 @@ class AuthHandler {
12
16
  * @param {string} password User's password for contentstack account
13
17
  * @returns {Promise} Promise object returns authtoken on success
14
18
  */
15
- async login(email, password) {
16
- return new Promise(function (resolve, reject) {
19
+ async login(email, password, tfaToken) {
20
+ const loginPayload = {
21
+ email,
22
+ password
23
+ };
24
+ if (tfaToken) {
25
+ loginPayload.tfa_token = tfaToken;
26
+ }
27
+ return new Promise( (resolve, reject) => {
17
28
  if (email && password) {
18
- client.login({email: email, password: password}).then(result => {
19
- return resolve(result.user)
29
+ client.login(loginPayload).then(async result => {
30
+ // 2FA enabled
31
+ if (result.error_code === 294) {
32
+ const twoFactorResult = await this.twoFactorAuthentication(loginPayload);
33
+ resolve(twoFactorResult);
34
+ } else {
35
+ resolve(result.user);
36
+ }
20
37
  }).catch(error => {
21
- return reject(error)
38
+ reject(error)
22
39
  })
23
40
  }
24
41
  })
25
42
  }
26
43
 
44
+ async twoFactorAuthentication(loginPayload) {
45
+ const actions = [{
46
+ type: 'list',
47
+ name: 'otpChannel',
48
+ message: "Two factor authentication enabled, please select a way to get the security code",
49
+ choices: [
50
+ { name: 'Authy App', value: 'authy' },
51
+ { name: 'SMS', value: 'sms' },
52
+ ],
53
+ }];
54
+
55
+ const channelResponse = await inquirer.prompt(actions)
56
+
57
+ // need to send sms to the mobile
58
+ if (channelResponse.otpChannel === 'sms') {
59
+ await client.axiosInstance.post('/user/request_token_sms', { user: loginPayload });
60
+ cli.log(chalk.yellow("Security code sent to your mobile"))
61
+ }
62
+
63
+ const tokenResponse = await inquirer.prompt({
64
+ type: 'input',
65
+ message: 'Please provide the security code',
66
+ name: 'tfaToken',
67
+ });
68
+
69
+ return this.login(loginPayload.email, loginPayload.password, tokenResponse.tfaToken);
70
+ }
71
+
27
72
  /**
28
73
  *
29
74
  * Logout from Contentstack