> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Authentication API で組織名を使用するための設定方法、セキュリティに関する考慮事項、ベストプラクティス。

# Authentication API で組織名を使用する

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [displayText, setDisplayText] = useState(children);
  const [copyText, setCopyText] = useState(children);
  const wrapperRef = React.useRef(null);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      if (!window.autorun || !window.rootStore) {
        return;
      }
      unsubscribe = window.autorun(() => {
        let processedChildrenForDisplay = children;
        let processedChildrenForCopy = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
          let displayValue = value;
          if (key === "{yourClientSecret}" && value !== "{yourClientSecret}") {
            displayValue = value.substring(0, 3) + "*****マスク済み*****";
          }
          processedChildrenForDisplay = processedChildrenForDisplay.replaceAll(new RegExp(escapedKey, "g"), displayValue);
          processedChildrenForCopy = processedChildrenForCopy.replaceAll(new RegExp(escapedKey, "g"), value);
        }
        setDisplayText(processedChildrenForDisplay);
        setCopyText(processedChildrenForCopy);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  useEffect(() => {
    if (!wrapperRef.current) return;
    const originalWriteText = navigator.clipboard.writeText.bind(navigator.clipboard);
    let isOverriding = false;
    const handleClick = e => {
      const button = e.target.closest('[data-testid="copy-code-button"]');
      if (!button || !wrapperRef.current.contains(button)) return;
      isOverriding = true;
      navigator.clipboard.writeText = text => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
          return originalWriteText(copyText);
        }
        return originalWriteText(text);
      };
      setTimeout(() => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
        }
      }, 100);
    };
    const wrapper = wrapperRef.current;
    wrapper.addEventListener('click', handleClick, true);
    return () => {
      wrapper.removeEventListener('click', handleClick, true);
      if (navigator.clipboard.writeText !== originalWriteText) {
        navigator.clipboard.writeText = originalWriteText;
      }
    };
  }, [copyText]);
  return <div ref={wrapperRef}>
      <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
        {displayText}
      </CodeBlock>
    </div>;
};

デフォルトでは、[Authentication API](https://auth0.com/docs/api/authentication) は特定の組織を識別するために組織 ID を使用します。必要に応じて、テナントを設定し、識別子として組織名も使用できるようにすることができます。ただし、この機能を有効にする前に、ユーザビリティとセキュリティの両面への影響を考慮する必要があります。想定される影響をより正確に理解するには、[考慮事項と推奨事項](#considerations-and-recommendations) のセクションを確認してください。

<div id="how-it-works">
  ## 仕組み
</div>

Authentication API で組織名をサポートするようにテナントを設定すると、次のようになります。

* [/authorize](https://auth0.com/docs/api/authentication#authorize-application) エンドポイントおよび [SAML](https://auth0.com/docs/api/authentication#saml) エンドポイントの `organization` パラメーターで、組織名と ID の両方を指定できるようになります。
* アクセストークンと <Tooltip tip="IDトークン: リソースへのアクセスではなく、クライアント自体のための認証情報です。" cta="用語集を見る" href="/ja/docs/glossary?term=ID+tokens">IDトークン</Tooltip> には、自動的に `org_name` と `org_id` の両方の クレーム が含まれます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  - [組織](/ja/docs/manage-users/organizations/configure-organizations/create-organizations) には、2 つの名前を設定できます。1 つは一意の論理識別子として使用される必須の Name 値、もう 1 つは任意の表示用の Display Name です。`org_name` パラメーターで指定できるのは必須の Name 値のみで、Display Name 値はサポートされません。
  - この機能はテナント レベルで管理されます。特定の組織ごとに個別に有効化することはできません。
</Callout>

この機能は、<Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要製品です。" cta="用語集を見る" href="/ja/docs/glossary?term=Auth0+Dashboard">Auth0 Dashboard</Tooltip> または <Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要製品です。" cta="用語集を見る" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip> から有効にできます。

* **Auth0 Dashboard**: 左側のメニューから [Settings](/ja/docs/get-started/tenant-settings) を選択し、**Advanced** タブを開きます。**Settings** セクションで、**Allow Organization Names in Authentication API** トグルを有効にします。
* **Management API**: `PATCH /api/v2/tenants/settings` エンドポイントを使用して、`allow_organization_name_in_authentication_api` を `true` に設定します。詳細については、[Management API](https://auth0.com/docs/api/management/v2) のドキュメントを参照してください。

<div id="example-flow">
  ### フローの例
</div>

次の例では、組織名を使用する認可コードフローを示します。

1. `organization` パラメーターに組織名を指定して、`/authorize` エンドポイントを呼び出します。

export const codeExample1 = `https://{yourDomain}/authorize?
    response_type=code&
    client_id={yourClientId}&
    redirect_uri={https://yourApp/callback}&
    scope={scope}&
    state={state}&
    organization={yourOrganizationName}`;

<AuthCodeBlock children={codeExample1} language="http" />

2. 認可コードを取得したら、`POST /oauth/token` エンドポイントを呼び出して、アクセストークンとIDトークンを取得します。

export const codeExample2 = `curl --request POST \
  --url 'https://{yourDomain}/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=authorization_code \
  --data 'client_id={yourClientId}' \
  --data 'client_secret={yourClientSecret}' \
  --data 'code=yourAuthorizationCode}' \
  --data 'redirect_uri={https://yourApp/callback}'`;

<AuthCodeBlock children={codeExample2} language="bash" />

3. 返されるデコード済みトークンには、`org_id` と `org_name` の クレーム の両方が含まれます。

```json lines theme={null}
{
    "sub": "google-oauth2|10...17",
    "aud": [
        "https://yourApp"
    ],
    "iat": 1686840988,
    "exp": 1686927388,
    "azp": "Suo...qTd",
    "scope": "openid profile",
    "org_id": "{yourOrganizationId}",
    "org_name": "{yourOrganizationName}"
}
```

<div id="considerations-and-recommendations">
  ## 考慮事項と推奨事項
</div>

Authentication API で組織名を使用する前に、まず組織名と ID の主な違いを理解しておくことが重要です。

組織 ID は変更されませんが、組織名は初回作成後であればいつでも変更できます。さらに、単一のテナント内では、ある時点で **厳密に 1 つ** の組織にのみ割り当てられている限り、組織名を再利用できます。実際には、ある組織の名前を変更し、その元の名前をテナント内の別の組織に再利用できることを意味します。組織名が一意なのは単一のテナント内のみであり、複数のテナントにまたがる 2 つ以上の組織で同じ名前が使用されることがあります。

一般に、トークンの検証には組織 ID の使用を推奨します。ただし、ユースケースによっては組織名を使用するほうが適切な場合もあるため、この機能を実装する際は以下の影響を考慮してください。

<div id="usability-and-security-considerations">
  ### ユーザビリティとセキュリティに関する考慮事項
</div>

組織名を使用してトークンを要求および検証する場合は、以下の潜在的な影響を考慮してください。

* **組織名は再利用される可能性があります**: 有効期間の長いトークンは、組織が名前を変更しても失効せず、それらのトークン内の `org_name` クレームには元の値が保持されます。後でその元の名前が別の組織によって再利用された場合、そのようなトークンによって、ユーザーに新しい組織が管理するデータやリソースへの未承認のアクセスが許可される可能性があります。
* **組織名は単一のテナント内でのみ一意です**: API がトークン内の `iss` (issuer) クレームを検証しない場合、別のテナントにある同名の組織が生成したトークンを、API が誤って受け入れる可能性があります。
* **組織名は変更できます**: 組織名を変更した場合、アプリケーションは Authentication API リクエストで新しい組織名を指定する必要があります。トークンは長期間有効な場合があるため、トークン内の `org_name` クレームが現在の組織名と一致しなくなる可能性があり、その結果、アプリケーションが適切な組織へのアクセスを許可できなくなるおそれがあります。

<div id="recommended-best-practices">
  ### 推奨されるベストプラクティス
</div>

セキュリティとユーザビリティに影響する可能性があるため、組織を扱う際にトークンを検証する場合は、名前ではなく ID を使用することを推奨します。組織名を使用する場合は、最適な運用のために以下のベストプラクティスに従ってください。

* トークンが Auth0 テナントによって発行されたことを確認するため、`iss` クレームは必ず検証してください。
* テナント内で以前使用されていた組織名は再利用しないでください。名前の再利用を防ぎ、過去に発行されたトークンが別の組織へのアクセスに使われないようにするため、過去の組織名を正確かつ最新の状態で記録してください。
* 組織の利用開始後は、どうしても必要な場合を除き、名前を変更しないでください。組織名を変更する場合、既存のアクセストークンと ID トークンには新しい組織名が自動的には反映されない点に注意してください。組織名を変更した後は、ユーザーに再度ログインするよう促してください。
