> ## 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でorganization名を使用する際の設定、セキュリティ上の考慮事項、ベストプラクティス。

# Authentication APIでorganization名を使用する

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) + "*****MASKED*****";
          }
          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を使用します。必要に応じて、テナントを設定し、識別子として organization名 も使用できるようにすることができます。ただし、この機能を有効にする前に、ユーザビリティやセキュリティへの影響を考慮する必要があります。想定される影響をよりよく理解するには、[考慮事項と推奨事項](#considerations-and-recommendations) セクションを確認してください。

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

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

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

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  - [Organizations](/docs/ja-jp/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="/docs/ja-jp/glossary?term=Auth0+Dashboard">Auth0 Dashboard</Tooltip> または <Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要な製品です。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=Management+API">Management API</Tooltip> から有効にできます。

* **Auth0 Dashboard**: 左側のメニューから [設定](/docs/ja-jp/get-started/tenant-settings) を選択し、**Advanced** タブを開きます。**設定** セクションで、**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>

以下の例では、organization名を使用する認可コードフローを示します。

1. `organization` パラメータに 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. 認可コードを取得したら、アクセストークンと ID トークンを取得するために `POST /oauth/token` エンドポイントを呼び出します。

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でorganization名を使用する前に、organization名と組織IDの主な違いを理解しておくことが重要です。

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

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

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

organization名を使用してトークンをリクエストおよび検証する際は、以下のような潜在的影響を考慮してください。

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

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

セキュリティや使い勝手への影響を考慮すると、組織を扱う際にトークンを検証するには、名前ではなく ID を使用することを推奨します。organization名を使用する場合は、最適な利用体験のために以下のベストプラクティスに従ってください。

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