> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-actions-triggers-prototype.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) + "*****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>;
};

<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/ja-jp/glossary?term=management-api" tip="Management API: 顧客が管理タスクを実行できるようにするための製品。" cta="用語集の表示">Management API</Tooltip>には、以下のタスクなど、アプリケーションのユーザー管理に使用できる機能が備わっています。

* さまざまなプロバイダーから取得した個別のユーザーアカウントを1つのプロファイルにリンクする。詳細については、「[ユーザーアカウントをリンクする](/docs/ja-jp/manage-users/user-accounts/user-account-linking)」をお読みください。
* ユーザーアカウントのリンクを解除して、個別のアイデンティティに戻す。
* ユーザーメタデータを更新する。詳細については、「[ユーザープロファイルでのメタデータの使い方](/docs/ja-jp/manage-users/user-accounts/metadata)」をお読みください。

## UsersAPIClientを初期化する

使い始めるには、プライマリーIDの`account`とトークンを渡して、新しい`UsersAPIClient`インスタンスを作成します。ユーザーのリンクでは、このプライマリーIDがデータを保持するユーザープロファイルになり、これに他のIDをリンクさせます。

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

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

## ユーザーをリンクする

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

`link`メソッドは、プライマリーユーザーのIDとセカンダリーユーザーのトークン（このIDでログイン後に取得するトークン）という2つのパラメーターを受け付けます。ユーザー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>) {
            // Got the updated identities! Accounts linked.
        }

        override fun onFailure(error: ManagementException) {
            // Error!
        }
    })
```

## ユーザーをリンク解除する

ユーザーをリンク解除すると、アカウントを個別のプロファイルに戻します。`unlink`メソッドは、プライマリーユーザーのID、セカンダリーユーザーの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>) {
            // Got the updated identities! Accounts linked.
        }

        override fun onFailure(error: ManagementException) {
            // Error!
        }
    })
```

アカウントのリンクでは、セカンダリーアカウントのメタデータはプライマリーアカウントのメタデータとマージされません。同様に、2つのアカウントのリンク解除では、セカンダリーアカウントはプライマリーアカウントのメタデータを保持しません。

## ユーザーメタデータを更新する

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

```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) {
            // Metadata updated
        }

        override fun onFailure(error: ManagementException) {
            // Error!
        }
    })
```
