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

# ユーザーアクセストークン

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="必須のガイド"
  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" }
]}
/>

JWTアプリケーションは、<Link href="/platform/user-types/#service-account">サービスアカウント</Link>ではなく特定のユーザーに対してアクセストークンを作成できます。

## 前提条件

アプリケーションは、ユーザーアクセストークンの作成を許可するように構成する必要があります。この設定は、[開発者コンソール][devconsole]の \[**構成**] タブにあります。

<Frame border center>
  <img src="https://mintcdn.com/box/ozetuUHA5lVSDzR-/ja/guides/authentication/jwt/enable-user-access-tokens.png?fit=max&auto=format&n=ozetuUHA5lVSDzR-&q=85&s=675cd15a0f7d3b45b888fc2b82d220c6" alt="高度な機能" width="1362" height="478" data-path="ja/guides/authentication/jwt/enable-user-access-tokens.png" />
</Frame>

さらに、認証済みユーザーは、管理者権限を持つユーザー、つまり、管理者、共同管理者、サービスアカウントのいずれかである必要があります。詳細については、<Link href="/platform/user-types">ユーザータイプ</Link>のガイドを参照してください。

## SDKを使用したユーザーアクセストークン

特定のユーザーとして認証するBox SDKクライアントを作成するには、<Link href="/guides/authentication/jwt/with-sdk">SDKを使用したJWTのガイド</Link>で説明されている手順に従います。ただし、「Enterprise」クライアントではなく、ユーザークライアントを作成します。

<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={localizeLink("/guides/authentication/jwt/with-sdk")} arrow title="Box SDKとJWTの使用の詳細を確認する" />

## SDKを使用しないユーザーアクセストークン

特定のユーザーとして認証するユーザーアクセストークンを作成するには、<Link href="/guides/authentication/jwt/without-sdk">SDKを使用しないJWTのガイド</Link>で説明されている手順に従います。ただし、企業用のクレームを作成するのではなく、特定のユーザー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={localizeLink("/guides/authentication/jwt/with-sdk")} arrow title="手動によるJWT認証の使用の詳細を確認する" />

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

<RelatedLinks
  title="関連するガイド"
  items={[
{ label: translate("JWT Auth"), href: "/guides/authentication/jwt/index", badge: "GUIDE" },
{ label: translate("Select Auth Method"), href: "/guides/authentication/select", badge: "GUIDE" }
]}
/>
