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

# as-userヘッダー

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" }
]}
/>

`as-user`ヘッダーを利用すると、JWTアプリケーションは別のユーザーの代理になることができます。

```sh theme={null}
curl https://api.box.com/2.0/folders/0 \
    -H "as-user: [USER_ID]" \
    -H "authorization: Bearer [ACCESS_TOKEN]"
```

<Info>
  この場合、ユーザーIDはユーザーのBox識別子です。どのユーザーでも、ユーザーIDは、管理者だけが利用可能な`GET /users`エンドポイントを介して確認できます。また、認証済みのユーザーセッションで`GET /users/me`エンドポイントを呼び出して確認することもできます。
</Info>

## 前提条件

アプリケーションは、[開発者コンソール][devconsole]で、ユーザーとして操作を実行するように構成する必要があります。

<Frame border center>
  <img src="https://mintcdn.com/box/ozetuUHA5lVSDzR-/ja/guides/authentication/jwt/enable-perform-actions-as-users.png?fit=max&auto=format&n=ozetuUHA5lVSDzR-&q=85&s=7e7d115812175af1221f118d52e05eda" alt="高度な機能" width="1394" height="496" data-path="ja/guides/authentication/jwt/enable-perform-actions-as-users.png" />
</Frame>

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

## as-userを使用できるSDK

すべての<Link href="/guides/tooling/sdks">Box公式SDK</Link>では、`as-user`ヘッダーを使用してユーザーの代わりに処理を実行することがサポートされています。

<CodeGroup>
  ```csharp .NET theme={null}
  var userClient = client.WithAsUserHeader("[USER_ID]");
  ```

  ```java Java theme={null}
  BoxClient userClient = client.withAsUserHeader("[USER_ID]");
  ```

  ```python Python theme={null}
  user_client = client.with_as_user_header('[USER_ID]')
  ```

  ```js Node theme={null}
  const userClient = client.withAsUserHeader('[USER_ID]');
  ```
</CodeGroup>

<Warning>
  これらのメソッドは、as-userヘッダーが適用された新しいクライアントインスタンスを返し、元のクライアントには変更を加えません。
</Warning>

## 制限

* `as-user`ヘッダーでは<Link href="/platform/user-types/#service-account">サービスアカウント</Link>の`user_id`を使用することはできません。
* 管理対象ユーザーを代理する場合、その企業が所有または管理するコンテンツにしかアクセスできません。`as-user`ヘッダーを使用して、外部ユーザーが所有するコンテンツにアクセスすることはできません。
* `as-user`ヘッダーには、認証済みユーザーと同じユーザーIDを指定することはできません。指定されたユーザーIDが現在のユーザーと一致した場合、リクエストは失敗し、`403 Forbidden`エラーが返されます。

[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" }
]}
/>
