Skip to content

Commit bcd6835

Browse files
authored
feat: Add support for Box Official App in login command (#638)
1 parent 465d478 commit bcd6835

File tree

13 files changed

+723
-108
lines changed

13 files changed

+723
-108
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Avatar URL: 'https://app.box.com/api/avatar/large/77777'
152152
* [`box help`](docs/help.md) - Display help for the Box CLI
153153
* [`box integration-mappings`](docs/integration-mappings.md) - List Slack integration mappings
154154
* [`box legal-hold-policies`](docs/legal-hold-policies.md) - List legal hold policies
155-
* [`box login`](docs/login.md) - Sign in with OAuth and set a new environment or update an existing if reauthorize flag is used
155+
* [`box login`](docs/login.md) - Sign in with OAuth 2.0 and create a new environment (or update an existing one with --reauthorize).
156156
* [`box metadata-cascade-policies`](docs/metadata-cascade-policies.md) - List the metadata cascade policies on a folder
157157
* [`box metadata-query`](docs/metadata-query.md) - Create a search using SQL-like syntax to return items that match specific metadata
158158
* [`box metadata-templates`](docs/metadata-templates.md) - Get all metadata templates in your Enterprise

docs/authentication.md

Lines changed: 140 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,127 +8,211 @@ overview of how the Box API handles authentication.
88
- [Developer Token](#developer-token)
99
- [Server Auth with JWT](#server-auth-with-jwt)
1010
- [Server Auth with CCG](#server-auth-with-ccg)
11-
- [Traditional 3-Legged OAuth2](#traditional-3-legged-oauth2)
12-
- [Reauthorize OAuth2](#reauthorize-oauth2)
11+
- [OAuth 2.0 Login (`box login`)](#oauth-20-login-box-login)
12+
- [Option 1: Official Box CLI App (Recommended)](#option-1-official-box-cli-app-recommended)
13+
- [Option 2: Your Own Custom App](#option-2-your-own-custom-app)
14+
- [Supported Ports](#supported-ports)
15+
- [Additional Flags](#additional-flags)
16+
- [Reauthorize OAuth2](#reauthorize-oauth2)
1317

1418

1519
Ways to Authenticate
1620
--------------------
1721

1822
### Developer Token
1923

20-
The fastest way to get started using the API is with developer tokens. A
21-
developer token is simply a short-lived access token that cannot be refreshed
22-
and can only be used with your own account. Therefore, they're only useful for
23-
testing an app and aren't suitable for production. You can obtain a developer
24-
token from your application's
25-
[developer console][dev-console] page.
24+
A developer token is a token that you can generate directly from the [Box Developer Console][dev-console]. It provides a quick way to test API calls without setting up a full authentication flow.
2625

27-
You can pass dev token to any cli command by using `--token` flag
26+
[dev-console]: https://app.box.com/developers/console
27+
28+
**Key characteristics:**
29+
30+
- Cannot be refreshed.
31+
- Scoped to your own account only.
32+
- Intended for **development and testing** — not suitable for production use.
33+
34+
**Usage** — pass the token to any CLI command with the `--token` flag:
2835

2936
```bash
30-
box users:get --token myToken
37+
box users:get --token <DEVELOPER_TOKEN>
3138
```
3239

33-
[dev-console]: https://app.box.com/developers/console
40+
> **Tip:** You can generate a new developer token at any time from the **Configuration** tab of your application in the [Developer Console][dev-console].
3441
3542
### Server Auth with JWT
3643

37-
Server auth allows your application to authenticate itself with the Box API
38-
for a given enterprise. By default, your application has a
39-
[Service Account](https://developer.box.com/en/guides/authentication/user-types/)
40-
that represents it and can perform API calls. The Service Account is separate
41-
from the Box accounts of the application developer and the enterprise admin of
42-
any enterprise that has authorized the app — files stored in that account are
43-
not accessible in any other account by default, and vice versa.
44+
JSON Web Token (JWT) authentication allows your application to authenticate as a [Service Account](https://developer.box.com/platform/user-types#service-account) without requiring user interaction. This is ideal for server-to-server integrations, automated workflows, and backend services.
45+
46+
**Key characteristics:**
4447

45-
If you generated your public and private keys automatically through the
46-
[Box Developer Console][dev-console], you can use the JSON file created there
47-
to configure the SDK and create an environment to make calls as the
48-
Service Account:
48+
- The application authenticates on behalf of a **Service Account**, which is separate from any individual user's account.
49+
- Files stored in the Service Account are not accessible from other accounts by default, and vice versa.
50+
- Requires a public/private key pair, which can be generated automatically in the [Developer Console][dev-console].
51+
52+
**Setup:**
53+
54+
1. In the [Developer Console][dev-console], create or open an application that uses **JWT** authentication.
55+
2. Generate a public/private key pair (or upload your own). This produces a JSON configuration file.
56+
3. Download the configuration file and add it as an environment:
4957

5058
```bash
51-
box configure:environments:add /path/to/file/config.json
59+
box configure:environments:add /path/to/config.json --name 'YOUR_ENVIRONMENT_NAME'
5260
```
5361

54-
Remember to set your current environment to the proper one
62+
4. If you have multiple environments, set the active one:
5563

5664
```bash
5765
box configure:environments:set-current
5866
```
5967

68+
After setup, all CLI commands will authenticate using the JWT credentials from the selected environment.
69+
6070
### Server Auth with CCG
6171

62-
Server auth allows your application to authenticate itself with the Box API
63-
for a given enterprise.
64-
Client Credentials Grant (CCG) allows you to authenticate by providing `clientId` and `clientSecret` and `enterpriseId` of your app.
65-
By default, your application has a
66-
[Service Account](https://developer.box.com/en/guides/authentication/user-types/)
67-
that represents it and can perform API calls. The Service Account is separate
68-
from the Box accounts of the application developer and the enterprise admin of
69-
any enterprise that has authorized the app — files stored in that account are
70-
not accessible in any other account by default, and vice versa.
72+
Client Credentials Grant (CCG) authentication allows your application to authenticate as a [Service Account](https://developer.box.com/platform/user-types#service-account) using a **Client ID**, **Client Secret**, and **Enterprise ID**. Like JWT, this method is designed for server-to-server communication and does not require user interaction.
7173

72-
Adding a CCG environment is a similar process to adding a JWT environment. However, you must manually create a configuration file.
73-
This file should contain `clientID`, `clientSecret` and `enterpriseId`. You can find this information in the [Box Developer Console][dev-console].
74+
**Key characteristics:**
7475

75-
Example configuration file:
76+
- The application authenticates on behalf of a **Service Account**, which is separate from any individual user's account.
77+
- Files stored in the Service Account are not accessible from other accounts by default, and vice versa.
78+
- No key pair generation is needed — authentication relies on the Client ID and Client Secret only.
79+
80+
**Setup:**
81+
82+
1. In the [Developer Console][dev-console], create or open an application that uses **Client Credentials Grant** authentication.
83+
2. Create a JSON configuration file with the following structure:
7684

7785
```json
7886
{
7987
"boxAppSettings": {
80-
"clientID": "myClientId",
81-
"clientSecret": "mySecret"
88+
"clientID": "your_client_id",
89+
"clientSecret": "your_client_secret"
8290
},
83-
"enterpriseID": "myEnterpriseId"
91+
"enterpriseID": "your_enterprise_id"
8492
}
8593
```
8694

87-
Then create a new environment with `--ccg-auth` flag and point it to the configuration file
95+
> **Tip:** You can find the `clientID` and `clientSecret` values in the **Configuration** tab, and the `enterpriseID` in the **General Settings** tab of your application in the [Developer Console][dev-console].
96+
97+
3. Add the environment with the `--ccg-auth` flag:
8898

8999
```bash
90-
box configure:environments:add /path/to/file/config.json --ccg-auth
100+
box configure:environments:add /path/to/config.json --ccg-auth --name 'YOUR_ENVIRONMENT_NAME'
91101
```
92102

93-
Remember to set your current environment to the proper one
103+
4. If you have multiple environments, set the active one:
94104

95105
```bash
96106
box configure:environments:set-current
97107
```
98108

99-
An environment for making calls as an App User or Managed User can be created just like a Service Account environment. You need to pass an additional `--ccg-user` flag with `userId` as the value
109+
**Authenticating as a specific user:**
110+
111+
By default, CCG authenticates as the Service Account. To make API calls as an App User or Managed User instead, pass the `--ccg-user` flag with the user's ID:
100112

101113
```bash
102-
box configure:environments:add /path/to/file/config.json --ccg-auth --ccg-user "USER_ID"
114+
box configure:environments:add /path/to/config.json --ccg-auth --ccg-user "USER_ID"
103115
```
104116

105-
### Traditional 3-Legged OAuth2
117+
### OAuth 2.0 Login (`box login`)
106118

107-
Refer to the [OAuth Guide](https://developer.box.com/guides/cli/quick-start) if you want to use OAuth2.
119+
The `box login` command authenticates you with Box using OAuth 2.0. It starts a local callback server, opens your browser for authorization, and stores the resulting tokens in a named environment.
108120

109-
#### Reauthorize OAuth2
121+
When you run `box login`, the CLI presents two login options: the **Official Box CLI App** and a **custom app** you create yourself. You can either choose interactively or skip the selection entirely using the `--default-box-app` (`-d`) flag.
122+
123+
#### Option 1: Official Box CLI App (Recommended)
110124

111-
After each successful OAuth2 authorization, a pair of tokens is generated, the Access Token and Refresh Token.
125+
This is the fastest way to get started with Box CLI. No app creation in the Box Developer Console is required — just run the command and authorize.
112126

113-
The first one, the [Access Token](https://developer.box.com/guides/authentication/tokens/access-tokens/), is used to represent the authenticated user to the Box servers and is valid for 60 minutes.
127+
**Interactive selection** — run `box login` and press **Enter** at the Client ID prompt to use the built-in app:
128+
129+
```bash
130+
box login
131+
# When prompted for a Client ID, press Enter to use the Official Box CLI App.
132+
```
114133

115-
The second one, the [Refresh Token](https://developer.box.com/guides/authentication/tokens/refresh/), is used to refresh the Access Token when it has expired or is close to expiring. A Refresh Token is valid for 1 use within 60 days.
134+
**Skip the prompt** — use the `--default-box-app` (or `-d`) flag to go directly to authorization:
116135

117-
However, it may happen that both mentioned tokens, `Access Token` and `Refresh Token`, have expired. You may then see following error:
136+
```bash
137+
box login --default-box-app
138+
```
118139

119140
```bash
120-
Your refresh token has expired.
141+
box login -d
142+
```
143+
144+
> **Note:** The Official Box CLI App uses scopes limited to content actions, which allows you to effectively manage your files and folders. If you need broader scopes (e.g., managing users, groups, or enterprise settings), use your own custom app instead.
145+
146+
#### Option 2: Your Own Custom App
147+
148+
If you need customized scopes or a dedicated application, you can log in with your own OAuth app. When prompted, enter the **Client ID** and **Client Secret** from your application's configuration.
149+
150+
Before running the command, set up the app in the [Box Developer Console](https://cloud.app.box.com/developers/console):
151+
152+
1. Select an application with **OAuth 2.0 user authentication** (or create a new Custom App).
153+
2. In the **Configuration** tab, set the **Redirect URI** to `http://localhost:3000/callback` (adjust the port if you use a different `--port` value).
154+
3. Click **Save Changes**.
155+
156+
Then log in:
157+
158+
```bash
159+
box login
160+
# When prompted, enter your Client ID and Client Secret.
161+
```
162+
163+
For a step-by-step walkthrough, see the [Quickstart Guide](https://developer.box.com/guides/tooling/cli/quick-start/).
164+
165+
#### Supported Ports
166+
167+
The `box login` command starts a local callback server to receive the OAuth redirect. You can control the port with the `--port` (`-p`) flag. The default port is **3000**.
168+
169+
When using the **Official Box CLI App**, only the following ports are supported:
170+
171+
| Port | Command |
172+
|------|---------|
173+
| 3000 | `box login -d` (default) |
174+
| 3001 | `box login -d --port 3001` |
175+
| 4000 | `box login -d --port 4000` |
176+
| 5000 | `box login -d --port 5000` |
177+
| 8080 | `box login -d --port 8080` |
178+
179+
When using your own custom app, any port can be used — just make sure the **Redirect URI** in the Developer Console matches `http://localhost:<port>/callback`.
180+
181+
#### Additional Flags
182+
183+
| Flag | Short | Description |
184+
|------|-------|-------------|
185+
| `--default-box-app` | `-d` | Use the Official Box CLI App and proceed directly to authorization. |
186+
| `--port <number>` | `-p` | Set the port for the local callback server. Default: `3000`. |
187+
| `--name <string>` | `-n` | Set a name for the environment. Default: `oauth`. |
188+
| `--reauthorize` | `-r` | Reauthorize an existing environment (requires `--name`). |
189+
| `--code` | `-c` | Manually visit the authorize URL and input the auth code. |
190+
| `--incognito-browser` | `-i` | Open the authorize URL in a private/incognito browser window. |
191+
192+
#### Reauthorize OAuth2
193+
194+
After each successful OAuth 2.0 authorization, a pair of tokens is generated: an **Access Token** and a **Refresh Token**.
195+
196+
- The [Access Token](https://developer.box.com/guides/authentication/tokens/access-tokens/) represents the authenticated user and is valid for **60 minutes**.
197+
- The [Refresh Token](https://developer.box.com/guides/authentication/tokens/refresh/) is used to obtain a new Access Token. It is valid for **1 use within 60 days**.
198+
199+
If both tokens expire, you will see the following error:
200+
201+
```
202+
Your refresh token has expired.
121203
Please run this command "box login --name <ENVIRONMENT_NAME> --reauthorize" to reauthorize selected environment and then run your command again.
122204
```
123205

124-
In this case, you need to log in again to obtain required tokens by using the following command:
206+
To reauthorize, run:
125207

126208
```bash
127209
box login --name "ENVIRONMENT_NAME" --reauthorize
128210
```
129211

130-
where `ENVIRONMENT_NAME` is the name of the environment to be reauthorized.
212+
The `--reauthorize` flag retrieves the existing `clientID` and `clientSecret` from the stored environment, so you do not need to enter them again. After a successful login, the environment is updated and set as the default.
131213

132-
Thanks to the `--reauthorize` flag, the `clientID` and `clientSecret` parameters will be retrieved from the existing environment instead of asking the user for them.
214+
You can also combine `--reauthorize` with `--default-box-app` to switch an existing environment to the Official Box CLI App:
133215

134-
After a successful login, the `ENVIRONMENT_NAME` environment will be updated and set as the default.
216+
```bash
217+
box login --name "ENVIRONMENT_NAME" --reauthorize --default-box-app
218+
```

docs/groups.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,6 @@ FLAGS
745745
DESCRIPTION
746746
Validates the roles and permissions of the group, and creates asynchronous jobs to terminate the group's sessions.
747747
748-
ALIASES
749-
$ box groups:terminate-session
750-
751748
EXAMPLES
752749
$ box groups:terminate-session --group-ids 123 345
753750
```

docs/login.md

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,76 @@
11
`box login`
22
===========
33

4-
Sign in with OAuth and set a new environment or update an existing if reauthorize flag is used
4+
Sign in with OAuth 2.0 and create a new environment (or update an existing one with --reauthorize).
5+
6+
Login options:
7+
8+
(1) Official Box CLI App
9+
No app setup needed. Use --default-box-app (-d) to skip the prompt.
10+
11+
(2) Your own custom OAuth app
12+
Enter your Client ID and Client Secret when prompted.
13+
14+
Quickstart: run "box login -d" to sign in immediately. A browser window will open for authorization. Once access is granted, the environment is created and set as default — you can start running commands right away.
515

616
* [`box login`](#box-login)
717

818
## `box login`
919

10-
Sign in with OAuth and set a new environment or update an existing if reauthorize flag is used
20+
Sign in with OAuth 2.0 and create a new environment (or update an existing one with --reauthorize).
1121

1222
```
1323
USAGE
14-
$ box login [--no-color] [-h] [-v] [-q] [-c] [-p <value>] [-r -n <value>] [-i]
24+
$ box login [--no-color] [-h] [-v] [-q] [-c] [-p <value>] [-d] [-r -n <value>] [-i]
1525
1626
FLAGS
17-
-c, --code Manually visit authorize URL and input code
18-
-h, --help Show CLI help
19-
-i, --incognito-browser Visit authorize URL with incognito browser
20-
-n, --name=<value> [default: oauth] Set a name for the environment
21-
-p, --port=<value> [default: 3000] Set the port number for the local OAuth callback server
22-
-q, --quiet Suppress any non-error output to stderr
23-
-r, --reauthorize Reauthorize the existing environment with given `name`
24-
-v, --verbose Show verbose output, which can be helpful for debugging
25-
--no-color Turn off colors for logging
27+
-c, --code
28+
Manually visit authorize URL and input code
29+
30+
-d, --default-box-app
31+
Use the Official Box CLI app flow and proceed directly to authorization.
32+
This is the fastest way to integrate with Box — no app creation in the Developer Console is needed.
33+
Scopes are limited to content actions, allowing you to effectively operate with your files and folders.
34+
This flow requires a local callback server on a supported port (3000, 3001, 4000, 5000, or 8080). The default port
35+
is 3000; use --port to change it.
36+
37+
-h, --help
38+
Show CLI help
39+
40+
-i, --incognito-browser
41+
Visit authorize URL with incognito browser
42+
43+
-n, --name=<value>
44+
[default: oauth] Set a name for the environment
45+
46+
-p, --port=<value>
47+
[default: 3000] Set the port number for the local OAuth callback server
48+
49+
-q, --quiet
50+
Suppress any non-error output to stderr
51+
52+
-r, --reauthorize
53+
Reauthorize the existing environment with given `name`
54+
55+
-v, --verbose
56+
Show verbose output, which can be helpful for debugging
57+
58+
--no-color
59+
Turn off colors for logging
2660
2761
DESCRIPTION
28-
Sign in with OAuth and set a new environment or update an existing if reauthorize flag is used
62+
Sign in with OAuth 2.0 and create a new environment (or update an existing one with --reauthorize).
63+
64+
Login options:
65+
66+
(1) Official Box CLI App
67+
No app setup needed. Use --default-box-app (-d) to skip the prompt.
68+
69+
(2) Your own custom OAuth app
70+
Enter your Client ID and Client Secret when prompted.
71+
72+
Quickstart: run "box login -d" to sign in immediately. A browser window will open for authorization. Once access is
73+
granted, the environment is created and set as default — you can start running commands right away.
2974
```
3075

3176
_See code: [src/commands/login.js](https://github.com/box/boxcli/blob/v4.5.0/src/commands/login.js)_

docs/search.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ USAGE
2020
[--limit <value>] [--all] [--include-recent-shared-links]
2121
2222
ARGUMENTS
23-
[QUERY] The search term
23+
[QUERY] The search term. Some queries with special characters (e.g. double quotes for exact match) may require
24+
escaping (e.g. box search '\"query_term\"').
2425
2526
FLAGS
2627
-h, --help Show CLI help

docs/users.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,6 @@ FLAGS
757757
DESCRIPTION
758758
Validates the roles and permissions of the user, and creates asynchronous jobs to terminate the user's sessions.
759759
760-
ALIASES
761-
$ box users:terminate-session
762-
763760
EXAMPLES
764761
$ box users:terminate-session --user-ids 123 345 --user-logins [email protected] [email protected]
765762
```

0 commit comments

Comments
 (0)