> ## 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.Android を使用してユーザーを管理する方法

# Auth0.Android: ユーザー管理

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

<Tooltip tip="Management API: お客様が管理タスクを実行するための製品です。" cta="用語集を見る" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip> には、アプリケーションのユーザーを管理するための機能が用意されており、次のようなタスクを実行できます。

* 異なるプロバイダーに属する別々のユーザーアカウントをリンクして、1 つのプロフィールに関連付けます。詳しくは、[ユーザーアカウントのリンク](/ja/docs/manage-users/user-accounts/user-account-linking)を参照してください。
* ユーザーアカウントのリンクを解除し、別々のアイデンティティに戻します。
* ユーザーメタデータを更新します。詳しくは、[ユーザープロフィールにおけるメタデータの仕組み](/ja/docs/manage-users/user-accounts/metadata)を参照してください。

<div id="initialize-the-usersapiclient">
  ## UsersAPIClient を初期化する
</div>

まず、`account` とプライマリ ID のトークンを渡して、新しい `UsersAPIClient` インスタンスを作成します。ユーザーをリンクする場合、このプライマリ ID は、データを"保持"する対象のユーザープロファイルであり、そこに他の アイデンティティ をリンクします。

export const codeExample = `val account = Auth0("{yourClientId}", "{yourDomain}")
val client = UsersAPIClient(account, "token")`;

<AuthCodeBlock children={codeExample} language="kotlin" />

<div id="link-users">
  ## ユーザーをリンクする
</div>

ユーザーアカウントをリンクすると、ユーザーはどのアカウントからでも認証できるようになります。どのアカウントで認証しても、同じプロフィールでログインされます。アカウントをリンクしない場合、Auth0 はそれぞれの異なるアカウントを別個のプロフィールとして扱います。

`link` メソッドは 2 つのパラメーターを受け取ります。プライマリユーザー id とセカンダリユーザーのトークン (この ID でログインした後に取得されるトークン) です。ここでのユーザー id は、このユーザーアカウントの一意の識別子です。id が `facebook|1234567890` 形式の場合、必要な id は区切り文字であるパイプの後ろの部分です。

```kotlin lines theme={null}
client
    .link("primary user id", "secondary user token")
    .start(object: Callback<List<UserIdentity>, ManagementException>() {
        override fun onSuccess(payload: List<UserIdentity>) {
            // アイデンティティが更新されました！アカウントがリンクされました。
        }

        override fun onFailure(error: ManagementException) {
            // エラー！
        }
    })
```

<div id="unlink-users">
  ## ユーザーのリンク解除
</div>

ユーザーのリンクを解除すると、アカウントはそれぞれ別々のプロフィールに戻ります。`unlink` メソッドは 3 つのパラメーターを受け取ります。1 つ目はプライマリ ユーザー id、2 つ目はセカンダリ ユーザー id、3 つ目はセカンダリ プロバイダー (セカンダリ ユーザーのもの) です。

```kotlin lines theme={null}
users
    .unlink("primary user id", "secondary user id", "secondary provider")
    .start(object: Callback<List<UserIdentity>, ManagementException>() {
        override fun onSuccess(payload: List<UserIdentity>) {
            // 更新されたアイデンティティを取得しました！アカウントがリンクされました。
        }

        override fun onFailure(error: ManagementException) {
            // エラー！
        }
    })
```

アカウントをリンクしても、セカンダリアカウントのメタデータがプライマリアカウントのメタデータに統合されることはありません。同様に、2 つのアカウントのリンクを解除しても、セカンダリアカウントにプライマリアカウントのメタデータが保持されることはありません。

<div id="updating-user-metadata">
  ## ユーザーメタデータの更新
</div>

ユーザーメタデータを更新するには、`metadata` オブジェクトを作成し、ユーザー id とその `metadata` オブジェクトを渡して `updateMetadata` メソッドを呼び出します。このオブジェクト内の値は、同じキーを持つ既存の値を上書きし、ユーザーメタデータにまだ存在しないキーについては新しい値を追加します。

```kotlin lines theme={null}
val metadata = mutableMapOf<String, Any?>()
metadata.put("name", listOf("My", "Name", "Is"));
metadata.put("phoneNumber", "1234567890");

users
    .updateMetadata("user id", metadata)
    .start(object: Callback<UserProfile, ManagementException>() {
        override fun onSuccess(payload: UserProfile) {
            // メタデータが更新されました
        }

        override fun onFailure(error: ManagementException) {
            // エラー！
        }
    })
```
