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

# User Access Token

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = 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("OAuth 2.0 with SDKs"), href: "/guides/authentication/oauth2/with-sdk", badge: "GUIDE" },
{ label: translate("OAuth 2.0 without SDKs"), href: "/guides/authentication/oauth2/without-sdk", badge: "GUIDE" }
]}
/>

It is possible for a JWT application to create an Access Token for a specific
user instead of for the <Link href="/platform/user-types/#service-account">Service Account</Link>.

## Preconditions

The application must be configured to allow the creation of user Access Tokens.
This setting can be found in the **Configuration** tab of the
[Developer Console][devconsole].

<Frame border center>
  <img src="https://mintcdn.com/box/J_EwM_J-GUl8Mc67/guides/authentication/jwt/enable-user-access-tokens.png?fit=max&auto=format&n=J_EwM_J-GUl8Mc67&q=85&s=4a2d894b7a27b5f765765d9ade62f4d9" alt="Advanced Features" width="1362" height="478" data-path="guides/authentication/jwt/enable-user-access-tokens.png" />
</Frame>

Additionally, the authenticated user needs to be a user with Admin permissions,
meaning either an Admin, Co-Admin, or Service Account. See our guide on
<Link href="/platform/user-types">User Types</Link> for more details.

## User Access Tokens with SDKs

To create a Box SDK client that authenticates as a specific user, follow the
steps described in the <Link href="/guides/authentication/jwt/with-sdk">JWT with SDK guide</Link>,
but create a user client instead of an "Enterprise" client.

<CodeGroup>
  ```csharp .Net theme={null}
  var userId = "12345";
  var sdk = new BoxJWTAuth(config);
  var token = sdk.UserToken(appUserID);
  BoxClient client = sdk.UserClient(userToken, userId);
  ```

  ```java Java theme={null}
  String userId = "12345";
  BoxDeveloperEditionAPIConnection api = new BoxDeveloperEditionAPIConnection.getAppUserConnection(userId, config)
  ```

  ```python Python theme={null}
  user = client.user(user_id='12345')

  auth = JWTAuth(
      client_id='[CLIENT_ID]',
      client_secret='[CLIENT_SECRET]',
      user=app_user,
      jwt_key_id='[JWT_KEY_ID]',
      rsa_private_key_file_sys_path='[CERT.PEM]',
      rsa_private_key_passphrase='[PASSPHRASE]'
  )
  auth.authenticate_user()
  user_client = Client(auth)
  ```

  ```js Node theme={null}
  var sdk = BoxSDK.getPreconfiguredInstance(config);
  var client = sdk.getAppAuthClient('user', '12345');
  ```
</CodeGroup>

<Card href="/guides/authentication/jwt/with-sdk" arrow title="Learn more about using the Box SDKs with JWT" />

## User Access Tokens without SDKs

To create a user Access Token that authenticates as a specific user, follow the
steps as described in the
<Link href="/guides/authentication/jwt/without-sdk">JWT without SDK guide</Link> but instead of creating
a claim for the enterprise, create one for a specific user ID.

<CodeGroup>
  ```csharp .Net theme={null}
  var userId = "12345";

  var claims = new List<Claim>{
      new Claim("sub", userid),
      new Claim("box_sub_type", "user"),
      new Claim("jti", jti),
  };
  ```

  ```java Java theme={null}
  String userId = "12345";

  JwtClaims claims = new JwtClaims();
  claims.setIssuer(config.boxAppSettings.clientID);
  claims.setAudience(authenticationUrl);
  claims.setSubject(userId);
  claims.setClaim("box_sub_type", "user");
  claims.setGeneratedJwtId(64);
  claims.setExpirationTimeMinutesInTheFuture(0.75f);
  ```

  ```python Python theme={null}
  user_id = '12345'

  claims = {
      'iss': config['boxAppSettings']['clientID'],
      'sub': user_id,
      'box_sub_type': 'user',
      'aud': authentication_url,
      'jti': secrets.token_hex(64),
      'exp': round(time.time()) + 45
  }
  ```

  ```js Node theme={null}
  let user_id = '12345';

  let claims = {
      iss: config.boxAppSettings.clientID,
      sub: user_id,
      box_sub_type: "user",
      aud: authenticationUrl,
      jti: crypto.randomBytes(64).toString("hex"),
      exp: Math.floor(Date.now() / 1000) + 45
  };
  ```

  ```ruby Ruby theme={null}
  user_id = '12345'

  claims = {
    iss: config['boxAppSettings']['clientID'],
    sub: user_id,
    box_sub_type: 'user',
    aud: authentication_url,
    jti: SecureRandom.hex(64),
    exp: Time.now.to_i + 45
  }
  ```

  ```php PHP theme={null}
  $userId = '12345';

  $claims = [
    'iss' => $config->boxAppSettings->clientID,
    'sub' => $userId,
    'box_sub_type' => 'user',
    'aud' => $authenticationUrl,
    'jti' => base64_encode(random_bytes(64)),
    'exp' => time() + 45,
    'kid' => $config->boxAppSettings->appAuth->publicKeyID
  ];
  ```
</CodeGroup>

<Card href="/guides/authentication/jwt/with-sdk" arrow title="Learn more about manually using JWT authentication" />

[devconsole]: https://app.box.com/developers/console

<RelatedLinks
  title="RELATED GUIDES"
  items={[
{ label: translate("JWT Auth"), href: "/guides/authentication/jwt/index", badge: "GUIDE" },
{ label: translate("Select Auth Method"), href: "/guides/authentication/select", badge: "GUIDE" }
]}
/>
