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

> Auth0のOrganizations機能で、アプリケーション内の組織 behaviorを定義する方法について説明します。

# Organization Behavior を定義する

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

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

Auth0 でアプリケーションを表現する際には、そのアプリケーションがどの種類のユーザーをサポートするかを指定できます。個人アカウントでログインするユーザーをサポートするアプリケーションもあれば、[組織](/docs/ja-jp/manage-users/organizations/organizations-overview)のメンバーによる利用を想定したものもあります。両方をサポートするものもあります。これは 組織 behavior と呼ばれ、Auth0 に接続する各アプリケーションごとに設定できます。

たとえば、アプリケーションには次のようなものがあります。

* **ログイン** ボタンのある一般的なマーケティング用ランディングページがあり、そのボタンからユーザーを組織なしで Auth0 のログインフローに遷移させる。
* B2B 顧客ごとに個別の URL がある (例: Acme のユーザーは `acme.yourcompany.com` にアクセスする) 構成で、ユーザーを組織付きで Auth0 にリダイレクトし、Acme の <Tooltip tip="Single Sign-On (SSO): ユーザーが 1 つのアプリケーションにログインすると、その後ほかのアプリケーションにも自動的にログインされるサービス。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=SSO">SSO</Tooltip> Login ボタンが表示されるようにする。

組織 behavior を定義することで、これらのいずれのシナリオにも対応できます。さらに、アプリケーションで組織の指定を必須にしているにもかかわらず、ユーザーが誤って組織なしで Auth0 に送られた場合に、組織名を入力できるプロンプトが表示されるように 組織 behavior を設定することもできます。

組織 behavior は、<Tooltip tip="Management API: 顧客が管理タスクを実行できるようにするための製品です。" 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> のいずれかを使用して定義できます。

<div id="auth0-dashboard">
  ## Auth0 Dashboard
</div>

Auth0 Dashboard で 組織 behavior を定義するには、次の手順に従います。

1. [Auth0 Dashboard > アプリケーション](https://manage.auth0.com/#/applications) に移動し、組織を設定するアプリケーションを選択します。
2. ログインフロー view に切り替え、適切な設定を行います。

| Field                      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | API Mapping                                                                                                                                                                                                                                          |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Type of Users**          | アプリケーションにログインできるユーザーの種類を決定します。<br /><br />選択肢: <ul> <li> **Individuals**: ユーザーは個人アカウントでサインアップし、アプリケーションに直接ログインできます。個人ユーザーは 組織 を使用してログインすることはできません。 </li> <li> **Business Users**: ユーザーがログインするには、組織 のメンバーである必要があります。これを選択した場合、ユーザーを `/authorize` エンドポイント にリダイレクトする際に 組織 を指定するか、ログインフロー を Prompt for Organization に設定する必要があります。 </li> <li> **Both**: ユーザーは 組織 のメンバーとしてログインすることも、個人アカウントでサインアップすることもできます。 </li> </ul>                                                               | **Type of Users** は `organization_usage` に対応します<br /><br />選択肢: <ul> <li>**Individuals** は `deny` に対応</li> <li>**Business Users** は `require` に対応</li> <li>**Both** は `allow` に対応</li> </ul>                                                         |
| **Login Flow**             | ユーザーがアプリケーションにアクセスしたときに最初に表示される login prompt を決定します。この field は、Type of Users が Business Users または Both に設定されている場合にのみ設定できます。<br /><br />選択肢: <ul> <li> **Prompt for Credentials**: まずユーザーにログイン資格情報の入力を求めます。ログイン後、ユーザーは自分の 組織 を選択できます。 </li> <li> **Prompt for Organization**: まずユーザーに自分の 組織 を選択するよう求めます。その後、ログインするための資格情報を入力できます。 </li> <li> **No Prompt**: Auth0 は、どの login prompt をユーザーに表示するかを指定しません。代わりに、適切な prompt を表示するために必要なパラメータを Auth0 に送信するのはアプリケーション側の役割です。 </li> </ul> | **ログインフロー** は `organization_require_behavior` に対応します<br /><br />選択肢: <ul> <li>**Prompt for Credentials** は `post_login_prompt` に対応</li> <li>**Prompt for Organization** は `pre_login_prompt` に対応</li> <li>**No Prompt** は `no_prompt` に対応</li> </ul> |
| **Organization Discovery** | 認証前にユーザーの組織を特定するために使用する方法を定義します。Prompt for Organization ログインフロー でのみ使用できます。<br /><br />選択肢: <ul> <li> **Prompt for Organization Email**: まずユーザーに、その 組織 に関連付けられたメールアドレスの入力を求めます。 </li> <li> **Prompt for Organization Name**: まずユーザーに、自分の 組織 の名前の入力を求めます。 </li> <li> **Prompt for Organization Email and Name**: まずユーザーに、自分の 組織 の名前、またはその 組織 に関連付けられたメールアドレスの入力を求めます。 </li> </ul>                                                                                                  | <ul> <li> **Prompt for Emails**: `email` に対応します。 </li> <li> **Prompt for Organization**: `organization_name` に対応します。 </li> <li> **Prompt for Organization Email and Name**: `email` と `organization_name` に対応します。 </li> </ul>                        |

3. **Save changes** を選択します。

<div id="management-api">
  ## Management API
</div>

[Update a Client エンドポイント](https://auth0.com/docs/api/management/v2#!/Clients/patch_clients_by_id) に `PATCH` リクエストを送信します。`client_id`、`mgmt_api_access_token`、`organization_usage`、`organization_require_behavior` の各プレースホルダー値は、それぞれ <Tooltip tip="Client ID: Auth0 から登録済みリソースに付与された識別値。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=client+ID">クライアントID</Tooltip>、Management API の <Tooltip tip="Client ID: Auth0 から登録済みリソースに付与された識別値。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Access+Token">アクセストークン</Tooltip>、組織 の使用オプション、組織 の動作オプションに必ず置き換えてください。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request PATCH \
    --url 'https://{yourDomain}/api/v2/clients/CLIENT_ID' \
    --header 'authorization: Bearer MGMT_API_ACCESS_TOKEN' \
    --header 'cache-control: no-cache' \
    --header 'content-type: application/json' \
    --data '{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }'
  ```

  ```csharp C# theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/clients/CLIENT_ID");
  var request = new RestRequest(Method.PATCH);
  request.AddHeader("content-type", "application/json");
  request.AddHeader("authorization", "Bearer MGMT_API_ACCESS_TOKEN");
  request.AddHeader("cache-control", "no-cache");
  request.AddParameter("application/json", "{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }", ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"strings"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://{yourDomain}/api/v2/clients/CLIENT_ID"

  	payload := strings.NewReader("{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }")

  	req, _ := http.NewRequest("PATCH", url, payload)

  	req.Header.Add("content-type", "application/json")
  	req.Header.Add("authorization", "Bearer MGMT_API_ACCESS_TOKEN")
  	req.Header.Add("cache-control", "no-cache")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.patch("https://{yourDomain}/api/v2/clients/CLIENT_ID")
    .header("content-type", "application/json")
    .header("authorization", "Bearer MGMT_API_ACCESS_TOKEN")
    .header("cache-control", "no-cache")
    .body("{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }")
    .asString();
  ```

  ```javascript Node.JS theme={null}
  var axios = require("axios").default;

  var options = {
    method: 'PATCH',
    url: 'https://{yourDomain}/api/v2/clients/CLIENT_ID',
    headers: {
      'content-type': 'application/json',
      authorization: 'Bearer MGMT_API_ACCESS_TOKEN',
      'cache-control': 'no-cache'
    },
    data: {
      organization_usage: 'ORG_USAGE',
      organization_require_behavior: 'ORG_REQUIRE_BEHAVIOR'
    }
  };

  axios.request(options).then(function (response) {
    console.log(response.data);
  }).catch(function (error) {
    console.error(error);
  });
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://{yourDomain}/api/v2/clients/CLIENT_ID",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "PATCH",
    CURLOPT_POSTFIELDS => "{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }",
    CURLOPT_HTTPHEADER => [
      "authorization: Bearer MGMT_API_ACCESS_TOKEN",
      "cache-control: no-cache",
      "content-type: application/json"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```python Python theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")

  payload = "{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }"

  headers = {
      'content-type': "application/json",
      'authorization': "Bearer MGMT_API_ACCESS_TOKEN",
      'cache-control': "no-cache"
      }

  conn.request("PATCH", "/{yourDomain}/api/v2/clients/CLIENT_ID", payload, headers)

  res = conn.getresponse()
  data = res.read()

  print(data.decode("utf-8"))
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'openssl'

  url = URI("https://{yourDomain}/api/v2/clients/CLIENT_ID")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER

  request = Net::HTTP::Patch.new(url)
  request["content-type"] = 'application/json'
  request["authorization"] = 'Bearer MGMT_API_ACCESS_TOKEN'
  request["cache-control"] = 'no-cache'
  request.body = "{ "organization_usage": "ORG_USAGE", "organization_require_behavior": "ORG_REQUIRE_BEHAVIOR" }"

  response = http.request(request)
  puts response.read_body
  ```
</AuthCodeGroup>

| Value                            | 説明                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CLIENT_ID`                      | 組織 behavior を追加する対象のアプリケーションの ID。                                                                                                                                                                                                                                                                                                                                                                                                              |
| `MGMT_API_ACCESS_TOKEN`          | スコープ `update:clients` を持つ [Management API のアクセストークン](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens)。                                                                                                                                                                                                                                                                                                                    |
| `ORGANIZATION_USAGE`             | アプリケーションが、組織 へのログインを行うユーザーをサポートできるかどうかを指定します。Options include: <ul> <li>`deny`:  (デフォルト) ユーザーは 組織 を使用してログインできません。</li> <li>`allow`: ユーザーは 組織 の有無にかかわらずログインできます。これを選択した場合、ユーザーを `/authorize` エンドポイントにリダイレクトする際に 組織 を指定する必要があります。</li> <li>`require`: ユーザーは 組織 を使用してログインする必要があります。これを選択した場合、ユーザーを `/authorize` エンドポイントにリダイレクトする際に 組織 を指定するか、ログイン前にユーザーが 組織 を選択できるよう `organization_require_behavior` を `pre_login_prompt` に設定する必要があります。</li> </ul> |
| `ORGANIZATION_REQUIRE_BEHAVIOR`  | アプリケーションにアクセスするユーザーに表示するログインフローを決定します。`organization_usage` が `require` または `allow` に設定されている場合にのみ適用されます。<br /><br />Options include: <ul> <li>`no_prompt`:  (デフォルト) prompt を表示しません。有効な 組織 パラメータがない request は拒否されます。</li> <li>`pre_login_prompt`: ユーザーがログインする前に、組織 を選択するよう求めます。このオプションは、`organization_usage` が `require` に設定されている場合にのみ使用できます。</li> <li>`post_login_prompt`: ユーザーに資格情報を使用してログインするよう求めます。ログイン後、ユーザーに 組織 を選択するよう求めます。</li> </ul>    |
| `ORGANIZATION_DISCOVERY_METHODS` | 認証前にユーザーの 組織 を特定する方法を決定します。`organization_require_behavior` が `pre_login_prompt` で、`organization_usage` が `require` または `allow` に設定されている場合にのみ適用されます。 <ul> <li> `email`:  (デフォルト) ユーザーは、自分の 組織 に関連付けられたメールアドレスの入力を求められます。 </li> <li> `organization_name`: ユーザーは、自分の 組織 に関連付けられた名前の入力を求められます。 </li> <li> `Organization name` and `email`: ユーザーは、自分の 組織 に関連付けられたメールアドレスまたは名前の入力を求められます。 </li> </ul>                                                |

<div id="response-status-codes">
  ### レスポンスステータスコード
</div>

想定されるレスポンスステータスコードは、次のとおりです。

| ステータスコード | エラーコード                    | メッセージ                                                                                    | 原因                                                         |
| -------- | ------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| `200`    |                           | クライアントが正常に更新されました。                                                                       |                                                            |
| `400`    | `invalid_uri`             | リクエスト URI が無効です。メッセージは原因によって異なります。                                                       | パスが無効です。                                                   |
| `400`    | `invalid_body`            | リクエスト本文が無効です。メッセージは原因によって異なります。                                                          | リクエストのペイロードが無効です。                                          |
| `401`    |                           | トークンが無効です。                                                                               |                                                            |
| `401`    |                           | クライアントはグローバルではありません。                                                                     |                                                            |
| `401`    |                           | JSON Web トークンのバリデーションで無効な署名を受信しました。                                                      |                                                            |
| `403`    | `insufficient_scope`      | スコープが不足しています。必要なスコープはいずれか 1 つです: `update:clients`。                                       | 指定された bearer token のスコープでは許可されていないフィールドの読み取りまたは書き込みを試みました。 |
| `403`    | `insufficient_scope`      | bearer token のスコープで付与された権限では、一部のフィールドを更新できません。メッセージはフィールドやスコープによって異なります。                 | 指定された bearer token のスコープでは許可されていないフィールドの読み取りまたは書き込みを試みました。 |
| `403`    | `operation_not_supported` | このアカウントではこの操作を実行できません。                                                                   | このアカウントではこの操作を実行できません。                                     |
| `404`    | `inexistent_client`       | クライアントが見つかりません。                                                                          | 存在しないリソースです。指定されたアプリケーションは存在しません。                          |
| `429`    |                           | リクエストが多すぎます。X-RateLimit-Limit、X-RateLimit-Remaining、および X-RateLimit-Reset ヘッダーを確認してください。 |                                                            |
