> ## 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.

# JWT with SDKs

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = localizeLink(href);
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

export const MultiRelatedLinks = ({sections = []}) => {
  if (!sections || sections.length === 0) {
    return null;
  }
  return <div className="space-y-8">
      {sections.map((section, index) => <RelatedLinks key={index} title={section.title} items={section.items} />)}
    </div>;
};

export const RelatedLinks = ({title, items = []}) => {
  const getBadgeClass = badge => {
    if (!badge) return "badge-default";
    const badgeType = badge.toLowerCase().replace(/\s+/g, "-");
    return `badge-${badge === "ガイド" ? "guide" : badgeType}`;
  };
  if (!items || items.length === 0) {
    return null;
  }
  return <div className="my-8">
      {}
      <h3 className="text-sm font-bold uppercase tracking-wider mb-4">{title}</h3>

      {}
      <div className="flex flex-col gap-3">
        {items.map((item, index) => <a key={index} href={item.href} className="py-2 px-3 rounded related_link hover:bg-[#f2f2f2] dark:hover:bg-[#111827] flex items-center gap-3 group no-underline hover:no-underline border-b-0">
            {}
            <span className={`px-2 py-1 rounded-full text-xs font-semibold uppercase tracking-wide flex-shrink-0 ${getBadgeClass(item.badge)}`}>
              {item.badge}
            </span>

            {}
            <span className="text-base">{item.label}</span>
          </a>)}
      </div>
    </div>;
};

<RelatedLinks
  title="REQUIRED GUIDES"
  items={[
{ label: translate("Select Auth Method"), href: "/guides/authentication/select", badge: "GUIDE" },
{ label: translate("Setup with OAuth 2.0"), href: "/guides/authentication/oauth2/oauth2-setup", badge: "GUIDE" }
]}
/>

The official Box SDKs have built-in support for JWT authentication.

This guide will take you through user authentication using JWT with the use
of the Box SDKs. JWT authentication is designed for working directly with the
Box API without requiring a user to redirect through Box to authorize your
application.

## Overview

To complete a JWT authorization the following steps need to be completed.

1. Read the configuration file
2. Initialize an SDK client

At the end of this flow, the application has a Box SDK client that can be used to
make API calls on behalf of the application.

<Note>
  The default method of authentication through JWT is inherently tied to the Service
  Account for the application. Any API call made with this token will seem to
  come from this application and will not have access to files and folders from
  other users without explicitly getting access them.
</Note>

## Prerequisites

Before we can get started, you will need to have completed the following steps.

* Create a Box Application within the developer console
* Create and download the private key configuration file for your application and save it as `config.json`
* Ensure your Box Application is approved for usage within your enterprise

## 1. Read JSON configuration

After creating a Box Application there should be a `config.json` file containing
the application's private key and other details. The following is an example.

```json config.json theme={null}
{
  "boxAppSettings": {
    "clientID": "abc...123",
    "clientSecret": "def...234",
    "appAuth": {
      "publicKeyID": "abcd1234",
      "privateKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----\n....\n-----END ENCRYPTED PRIVATE KEY-----\n",
      "passphrase": "ghi...345"
    }
  },
  "enterpriseID": "1234567"
}
```

To use this object in the application it needs to be read from file.

<CodeGroup>
  ```csharp .Net theme={null}
  var reader = new StreamReader("path/to/config.json");
  var json = reader.ReadToEnd();
  var config = BoxConfig.CreateFromJsonString(json);
  ```

  ```java Java theme={null}
  Reader reader = new FileReader("path/to/config.json");
  BoxConfig config = BoxConfig.readFrom(reader);
  ```

  ```python Python theme={null}
  from boxsdk import JWTAuth

  config = JWTAuth.from_settings_file('path/to/config.json')
  ```

  ```js Node theme={null}
  var config = require("path/to/config.json");
  ```
</CodeGroup>

<Info>
  **Parsing JSON**

  In some programming languages there is more than one way to read and parse
  JSON from a file. Refer to guides on your preferred programming language for
  more complete guides, including error handling.
</Info>

## 2. Initialize SDK client

The next step is to configure the Box SDK with the configuration and then
initialize the client to connect as the application.

<CodeGroup>
  ```csharp .Net theme={null}
  var sdk = new BoxJWTAuth(config);
  var token = sdk.AdminToken();
  BoxClient client = sdk.AdminClient(token);
  ```

  ```java Java theme={null}
  BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(config);
  ```

  ```python Python theme={null}
  client = Client(config)
  ```

  ```js Node theme={null}
  var sdk = BoxSDK.getPreconfiguredInstance(config);
  var client = sdk.getAppAuthClient("enterprise");
  ```
</CodeGroup>

<Warning>
  **Service Accounts**

  At this point the application is authenticated as an application user, not as
  a managed or app user. Head over to our guide on <Link href="/platform/user-types">User
  Types</Link> to learn more about the different types
  of users.

  **Summary**

  By now the application should be able to authorize an application using JWT
  with any of our official SDKs, by using the following steps.

  1. Read the configuration file
  2. Initialize an SDK client

  To learn how to use this client head over to the guide on <Link href="/guides/api-calls">Making API
  calls</Link>.

  **Using SDKs and JSON Web Tokens**

  To learn more about JWT for each SDK head over to:

  * [.Net][.Net]

  * [Java][Java]

  * [Python][Python]

  * [Node][Node]

  * [IOS][IOS]
</Warning>

[.Net]: https://github.com/box/box-windows-sdk-v2/blob/legacy/docs/authentication.md#server-auth-with-jwt

[Java]: https://github.com/box/box-java-sdk/blob/legacy/doc/authentication.md#server-authentication-with-jwt

[Python]: https://github.com/box/box-python-sdk/blob/legacy/docs/usage/authentication.md#server-auth-with-jwt

[Node]: https://github.com/box/box-node-sdk/blob/legacy/docs/authentication.md#server-auth-with-jwt

[IOS]: https://github.com/box/box-ios-sdk/blob/legacy/BoxSDK/docs/usage/authentication.md#server-auth-with-jwt

<RelatedLinks
  title="RELATED APIS"
  items={[
{ label: translate("Authorize user"), href: "/reference/get-authorize", badge: "GET" }
]}
/>

<RelatedLinks
  title="RELATED GUIDES"
  items={[
{ label: translate("Platform App"), href: "/guides/applications/platform-apps/index", badge: "GUIDE" },
{ label: translate("Select Auth Method"), href: "/guides/authentication/select", badge: "GUIDE" },
{ label: translate("Setup with OAuth 2.0"), href: "/guides/authentication/oauth2/oauth2-setup", badge: "GUIDE" }
]}
/>
