> ## 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 SignupCTA = ({children}) => {
  return <div className="flex flex-wrap items-center gap-4 p-5 rounded-lg border border-gray-200 dark:border-gray-700 my-6" style={{
    background: "linear-gradient(135deg, rgba(0, 97, 213, 0.06), rgba(0, 97, 213, 0.02))"
  }}>
      <div className="flex-1 text-sm leading-relaxed text-gray-700 dark:text-gray-300" style={{
    minWidth: "280px"
  }}>
        {children}
      </div>
      <div className="flex flex-col items-center gap-2">
        <a href="https://account.box.com/signup/developer#ty9l3" className="signup-cta-button inline-flex items-center whitespace-nowrap px-5 py-2 text-sm font-semibold text-white no-underline">
          {translate("Get started for free")}
        </a>
        <a href="https://account.box.com/developers/console" className="signup-cta-login text-xs text-gray-500 dark:text-gray-400 no-underline whitespace-nowrap">
          {translate("Already have an account? Log in")}
        </a>
      </div>
    </div>;
};

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>;
};

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

<RelatedLinks
  title="必須のガイド"
  items={[
{ label: translate("Select Auth Method"), href: "/guides/authentication/select", badge: "GUIDE" }
]}
/>

サーバー認証を利用し、クライアントIDとクライアントシークレットを使用してアプリケーションのIDを確認する場合は、以下の手順に従います。

## 前提条件

* Box[開発者コンソール][devconsole]で、Platformアプリケーションがサーバー認証 (クライアント資格情報許可) を使用するように構成されていること。
* Boxアカウントで[2要素認証][2fa]が有効になっており、このアプリケーションのクライアントシークレットを \[構成] タブで表示およびコピーできるようになっていること。
* このアプリケーションの使用が企業で<Link href="/guides/authorization">承認</Link>されていること。

<SignupCTA>
  無料のDeveloperアカウントを作成すると、開発者コンソールにアクセスして、クライアント資格情報許可による認証を数分で設定できます。
</SignupCTA>

<Danger>
  クライアントシークレットは機密情報であり、保護する必要があります。アクセストークンの取得時にBoxがアプリケーションのIDを安全に確認するために使用されるため、クライアントシークレットを自由に配布するべきではありません。配布方法には、メール、公開フォーラム、コードリポジトリ、分散されたネイティブアプリケーション、クライアント側のコードなどがあります。さらにセキュリティメカニズムを追加する場合は、Boxの標準的なJWTアプリケーションを使用することをお勧めします。
</Danger>

## 利用方法

APIコールを実行して<Link href="/reference/post-oauth2-token">アクセストークン</Link>を取得する際は、リクエスト本文にクライアントIDとクライアントシークレットを含める必要があります。`grant_type`を`client_credentials`に設定します。

アプリケーションの<Link href="/platform/user-types/#service-account">サービスアカウント</Link>として認証する場合は、以下のようにします。

* `box_subject_type`を`enterprise`に設定します。
* `box_subject_id`をEnterprise IDに設定します。

管理者または管理対象ユーザーとして認証する場合は、以下のようにします。

* `box_subject_type`を`user`に設定します。
* `box_subject_id`をユーザーIDに設定します。
* Box[開発者コンソール][devconsole]で \[**アプリ + Enterpriseアクセス**] および \[**ユーザーアクセストークンを生成**] を有効にします。

任意のアプリケーションユーザーとして認証する場合は、以下のようにします。

* `box_subject_type`を`user`に設定します。
* `box_subject_id`をユーザーIDに設定します。
* Box[開発者コンソール][devconsole]で \[**ユーザーアクセストークンを生成**] を有効にします。

## 一般的なエラー

### Grant credentials are invalid (許可の資格情報が無効です)

認証中に、次のエラーが表示される場合があります。

```sh theme={null}
Grant credentials are invalid [400 Bad Request] invalid_grant - Grant credentials are invalid
```

このエラーは次のいずれかを示します。

* 渡されたクライアントIDとクライアントシークレットが正しくないか、同じアプリケーションのものではありません。

* 選択した<Link href="/guides/authentication/client-credentials/client-credentials-setup/#application-access">アプリケーションアクセス</Link>に基づいて`box_subject_id`を使用することができません。

<Warning>
  \[アプリアクセスのみ] が指定されているCCGアプリは、そのサービスアカウントとして認証するために送信時に`box_subject_type`を`enterprise`に設定できますが、管理対象ユーザーまたは管理者として認証することはできません。
</Warning>

* `box_subject_type`を`user`に設定して使用するには、\[**構成**] タブの \[**高度な機能**] セクションでユーザーアクセストークンを生成するようアプリケーションを構成する必要があります。

  <Frame>
    <img src="https://mintcdn.com/box/biE81cmEmV1QnYl4/guides/authentication/client-credentials/image.png?fit=max&auto=format&n=biE81cmEmV1QnYl4&q=85&s=eb49d9cdb4654e44e101e877baa60ef7" alt="アクセストークンの生成のチェックボックス" width="750" height="98" data-path="guides/authentication/client-credentials/image.png" />
  </Frame>

<Warning>
  アプリの設定に変更を加えたら、忘れずに管理コンソールでアプリケーションを<Link href="/guides/authorization/platform-app-approval#re-authorization-on-changes">再承認</Link>してください。
</Warning>

* アプリケーションがBox管理コンソールで承認されていません。

[2fa]: https://support.box.com/hc/ja/articles/360043697154-アカウントの多要素認証の設定

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

<RelatedLinks
  title="関連するAPI"
  items={[
{ label: translate("Authorize user"), href: "/reference/get-authorize", badge: "GET" }
]}
/>

<RelatedLinks
  title="関連するガイド"
  items={[
{ label: translate("Platform App"), href: "/guides/applications/platform-apps/index", badge: "GUIDE" },
{ label: translate("Best Practices"), href: "/guides/authentication/best-practices", badge: "GUIDE" }
]}
/>
