> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Compare Box authentication methods, see which credentials and files each one needs, and learn what the access token you get back represents.

Every Box API call carries an [access token](#the-access-token), and that token tells Box which user the call acts as. Your app gets the token by exchanging its credentials with Box, and the way it makes that exchange is its **authentication method**.

The methods available to you follow from the **app type** you pick when you create a Platform App in the Developer Console. That choice comes down to one question: does a person sign in to Box to use your app, or does your app run on its own?

* Apps that people sign in to are **User** apps, which always use **OAuth 2.0**.
* Apps that run on their own are **Server** apps, which use either **Client Credentials Grant (CCG)** or **JWT**.

## Authentication methods at a glance

The methods differ in how your app proves who it is, and in the content the resulting token can reach.

| | [OAuth 2.0](#oauth-20) | [CCG](#client-credentials-grant) | [JWT](#jwt) |
| - | - | - | - |
| **App type** | User | Server | Server |
| **Proves identity with** | Client secret plus user consent | Client secret | Public/private keypair |
| **Requires admin authorization or enablement** | Depends on enterprise settings | Yes | Yes |
| **Can act on behalf of other users** | With extra setup | Yes | Yes |
| **Can create App Users** | No | Yes | Yes |
| **Best for** | Apps whose users sign in with their own Box accounts | Backend services, automations, and integrations | Backend services that require a public/private keypair |

A Server app has to be authorized before it can call the API. An OAuth 2.0 app needs a Box Admin or Co-Admin to enable it only when your enterprise leaves unpublished apps inactive by default. Platform App Approval covers both cases.

> [!WARNING]
>
> You can't convert a User app into a Server app, or a Server app into a User app. To move between them, create a new app.

> [card] Set up JWT authentication

> [card] Learn about Box access tokens

> [card] Generate a developer token

A free developer account gives you access to the Developer Console, where you can create apps, configure authentication, and generate access tokens.

[https://account.box.com/signup/developer](https://account.box.com/signup/developer)
[https://account.box.com/developers/console](https://account.box.com/developers/console)

To try authentication without affecting production data, use a [developer sandbox](https://developer.box.com/guides/getting-started/sandbox.md).

## OAuth 2.0

OAuth 2.0 is an [open standard](https://oauth.net/2/) that lets people grant an application access to their data in another application. If you've ever signed in to a website with Google or Facebook, you've used it. Box follows the same flow: your app sends the user to Box, the user logs in and approves the request, and Box returns an authorization code that your app exchanges for an access token.

Because the token belongs to the person who signed in, your app reaches exactly the content that user owns or collaborates on, and the content it creates lives in that user's own account.

Choose OAuth 2.0 when your users already have Box accounts and you want them to sign in to Box themselves.

> [card] Learn about OAuth 2.0 authentication

## Client Credentials Grant

Client Credentials Grant (CCG) verifies your application's identity with a client ID and client secret, then returns an access token directly. No one logs in, so it suits code that runs unattended. CCG is preselected when you create a Server app.

Each token request names the subject it authenticates as: the application's Service Account, or a specific user when the app is configured to allow it.

Choose CCG for a backend service, an automation, or an integration whose end users have no Box accounts of their own or sign in through your identity system. Each of those users can get an isolated App User with its own folder tree.

> [card] Learn about Client Credentials Grant

## JWT

Server authentication with JSON Web Tokens (JWT) has your app sign a short-lived assertion with a private key rather than send a secret on its own, then exchange that assertion for an access token. Box holds only the matching public key, so the private key never leaves your infrastructure.

JWT gives you the same Service Account model as CCG, including isolated App Users. The assertion doesn't replace your client secret, which the token request still carries, so JWT adds a second factor to the exchange rather than swapping one credential for another.

> [card] Learn about JWT authentication

## Choosing between CCG and JWT

Both methods reach the same Service Account, the same App Users, and the same content, so the choice comes down to how your app proves who it is and how much credential handling you want to own.

Choose JWT when your security review calls for keypair-based verification, or when you want the private key to stay in your infrastructure: Box stores only your public key, so a leaked client secret alone isn't enough to get a token. The cost is key management, including generating the keypair, protecting the private key and its passphrase, and uploading a new public key whenever you rotate.

Choose CCG otherwise. It needs no keys and no assertion signing, which makes it the simpler option and the one Box recommends for most Server apps.

Whether you can change the method after the app exists depends on an enterprise setting, and switching revokes the credentials tied to the previous method.

> [card] Switch an existing app between CCG and JWT

## Credentials for each method

Each method needs a different set of values, and all of them come from the **Configuration** tab of your app in the Developer Console.

| Method | Values you need | Where to get them |
| - | - | - |
| OAuth 2.0 | Client ID, client secret, and at least one redirect URI | Read the ID and secret from the **Configuration** tab. Register redirect URIs in the **OAuth 2.0 Redirect URI** section, where they have to match the `redirect_uri` you send exactly. |
| Client Credentials Grant | Client ID, client secret, and the subject to authenticate as: `box_subject_type` of `enterprise` with your enterprise ID, or `user` with a user ID | Read the ID and secret from the **Configuration** tab. See Locating IDs for enterprise and user IDs. |
| JWT | Client ID, client secret, public key ID, encrypted private key, passphrase, and enterprise ID | Select **Generate a Public/Private Keypair** in the **Add and Manage Public Keys** section and Box downloads a `config.json` that holds all six values. If you generate your own keypair instead, you keep the private key and passphrase yourself and collect the other values from the **Configuration** tab. |

> [!NOTE]
>
> Your Box account needs [multi-factor authentication (MFA)](https://support.box.com/hc/en-us/articles/360043697154-Multi-Factor-Authentication-Set-Up-for-Your-Account) enabled to view a client secret or generate a keypair.

### Where credential files live

JWT is the only method where Box hands you a file. When you select **Generate a Public/Private Keypair** in the Developer Console, Box downloads a `config.json` that holds both the keypair and the application details needed to authenticate. Store that file securely outside source control and load it at runtime, or load the same values from environment variables or a secrets manager. The JWT with an SDK guide shows what the file contains and how to load it.

If you generate your own keypair and upload only the public key, there's no `config.json` to download. Store the private key wherever your application can read it at startup, keep the passphrase separate from the key, and read the remaining values from the **Configuration** tab. OAuth 2.0 and CCG apps have no file at all, so keep their client ID and client secret in environment variables or a secrets manager.

> [!WARNING]
>
> Box does not store your private key. If you lose it, you have to reset the entire keypair.
>
> Never commit `config.json` or a client secret to a repository. Add them to your `.gitignore`, and keep them out of email, public forums, distributed native applications, and client-side code. To reach Box from browser code, downscope a token first.

> [card] Read the authentication best practices

## Access token

Every method ends in the same place: Box returns an access token, and your app sends it in the `Authorization` header of each API call. The token is valid for 60 minutes, and the response reports the exact lifetime in seconds as `expires_in`.

```sh theme={null}
curl https://api.box.com/2.0/users/me \
    -H "authorization: Bearer [ACCESS_TOKEN]"
```

To call an endpoint before you build any of this, generate a developer token by hand in the Developer Console. It isn't a separate authentication method: it's an ordinary access token with the same 60-minute lifetime, tied to whoever is signed in to the console, and it's meant for development only.

### How each method requests a token

Every method requests the token from the same endpoint, `https://api.box.com/oauth2/token`, and sends a different `grant_type` with the parameters that accompany it. OAuth 2.0 reaches this request last, after the user has already signed in at Box and consented.

```sh OAuth 2.0 theme={null}
curl -X POST https://api.box.com/oauth2/token \
    -d "grant_type=authorization_code" \
    -d "code=[CODE]" \
    -d "client_id=[CLIENT_ID]" \
    -d "client_secret=[CLIENT_SECRET]"
```

```sh Client Credentials Grant theme={null}
curl -X POST https://api.box.com/oauth2/token \
    -d "grant_type=client_credentials" \
    -d "client_id=[CLIENT_ID]" \
    -d "client_secret=[CLIENT_SECRET]" \
    -d "box_subject_type=enterprise" \
    -d "box_subject_id=[ENTERPRISE_ID]"
```

```sh JWT theme={null}
curl -X POST https://api.box.com/oauth2/token \
    -d "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer" \
    -d "assertion=[JWT_ASSERTION]" \
    -d "client_id=[CLIENT_ID]" \
    -d "client_secret=[CLIENT_SECRET]"
```

OAuth 2.0 needs the `code` that Box returns after the user consents, and JWT needs an assertion you sign with your private key. The JWT without an SDK guide walks through building that assertion, and the SDKs handle both steps for you.

### What comes back

What arrives alongside the token differs by method, and it decides how your app keeps working once the token expires.

| Method | Token response contains | Getting the next token |
| - | - | - |
| OAuth 2.0 | An access token and a refresh token | Exchange the refresh token for a new pair |
| Client Credentials Grant | An access token | Request another one with the same client credentials |
| JWT | An access token | Sign a new assertion and exchange it |

A refresh token lasts 60 days and works only once, so an OAuth 2.0 app stores the newest refresh token for each user and sends that user through authorization again if 60 days pass without a refresh. CCG and JWT apps skip this bookkeeping, because they request a fresh token whenever they need one.

### Who the token represents

An access token always maps to one Box user, and that user determines which content your app can reach and where new content lives. What the token can do with that content is narrower still: it's the overlap between the user's own access and the scopes you enabled for the application, so a call can fail even when the user can see the file.

| Method | Default user | Where content lives |
| - | - | - |
| OAuth 2.0 | The person who granted access | That user's own account |
| Client Credentials Grant | The Service Account | The Service Account's folder tree, or an App User's folder tree |
| JWT | The Service Account | The Service Account's folder tree, or an App User's folder tree |

Every Box account has its own folder tree, and the root of that tree is always folder ID `0`. The same upload call therefore lands in a different place depending on which token you send it with: an OAuth 2.0 token puts the file in the signed-in user's account, while a Service Account token puts it somewhere only the application can see until you share it. Nothing crosses between trees on its own, so if your app has to work with content that already exists, give the account access first.

### Service Accounts

A Service Account is a programmatic user that represents your application inside the Box enterprise. Box generates it automatically once your JWT or CCG app is authorized, so you never create it yourself. It has no login credentials and acts only through the API, which makes it a good fit for backend integrations. You find its `@boxdevedition.com` email address in the **App Details** tab of your app, next to a link that opens the account in the Content Manager.

A Service Account starts with an empty folder tree, so it can't see your existing files until you give it access. Invite it as a collaborator using its email address, or call the create collaboration endpoint with its user ID. User types covers its storage quota, its scopes, and how an Admin browses its content.

> [!WARNING]
>
> If you call the API with a Service Account token before the app is authorized, Box returns an `unauthorized_client` error with the message `This app is not authorized by the enterprise`.

Server apps aren't limited to the Service Account. A CCG app can request a token for a specific user, and a JWT app can send the as-user header or request a user access token. In each case the Managed User or App User keeps their own folder tree.

> [card] Compare Box user types

> [card] Use, refresh, revoke, and downscope tokens

## App token

Box has a fourth method, App Token authentication, intended for Box View previews and other Limited Access App scenarios. However, it is recommended to use [CCG](#client-credentials-grant) or [JWT](#jwt) for general server-side integrations. See Legacy Limited Access Apps to move an existing app onto one of them.

## Next steps

* Set up an app with OAuth 2.0
* Set up an app with Client Credentials Grant
* Set up an app with JWT
* Get your app authorized
* Fix common authorization errors
* See how SSO affects OAuth 2.0 sign-ins
