> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-update-anonymous-sessons-ea.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ユーザーアカウントをリンクする際に、ID トークンからアクセストークンへ移行する方法を説明します。

# Account Linking でアクセストークンに移行する

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

export const codeExample1 = `https://{yourDomain}/authorize?
  scope=openid
  &response_type=id_token
  &client_id={yourClientId}
  &redirect_uri=https://{yourApp}/callback
  &nonce=NONCE
  &state=OPAQUE_VALUE
`;

export const codeExample2 = `https://{yourDomain}/authorize?
  audience=https://{yourDomain}/api/v2/
  &scope=update:current_user_identities
  &response_type=token%20id_token
  &client_id={yourClientId}
  &redirect_uri=https://{yourApp}/callback
  &nonce={nonce}
  &state={opaqueValue}
`;

export const codeExample3 = `{
  "iss": "https://{yourDomain}/",
  "sub": "auth0|5a620d29a840170a9ef43672",
  "aud": "https://{yourDomain}/api/v2/",
  "iat": 1521031317,
  "exp": 1521038517,
  "azp": "{yourClientId}",
  "scope": "\${scope}"
}`;

export const codeExample4 = `{
  "method": "POST",
  "url": "https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities",
  "httpVersion": "HTTP/1.1",
  "headers": [
      {
        "name": "Authorization",
        "value": "Bearer ACCESS_TOKEN"
      },
      {
        "name": "content-type",
        "value": "application/json"
      }
  ],
  "postData" : {
      "mimeType": "application/json",
      "text": "{\\"link_with\\":\\"SECONDARY_ACCOUNT_ID_TOKEN\\"}"
  }
}`;

export const codeExample5 = `// ID トークンを取得
var webAuth = new auth0.WebAuth({
  clientID: '{yourClientId}',
  domain: '{yourDomain}',
  redirectUri: 'https://{yourApp}/callback',
  scope: 'openid',
  responseType: 'id_token'
});
// インスタンスを新規作成
var auth0Manage = new auth0.Management({
  domain: '{yourDomain}',
  token: '{yourIdToken}'
});`;

export const codeExample6 = `// アクセストークンを取得
  var webAuth = new auth0.WebAuth({
    clientID: '{yourClientId}',
    domain: '{yourDomain}',
    redirectUri: 'https://{yourApp}/callback',
    audience: 'https://{yourDomain}/api/v2/',
    scope: 'update:current_user_identities',
    responseType: 'token id_token'
  });
  // インスタンスを新規作成
  var auth0Manage = new auth0.Management({
    domain: '{yourDomain}',
    token: '{yourMgmtApiAccessToken}'
  });
`;

export const codeExample17 = `https://{yourDomain}/authorize?
  scope=openid
  &response_type=id_token
  &client_id={yourClientId}
  &redirect_uri=https://{yourApp}/callback
  &nonce={nonce}
  &state={opaqueValue}`;

export const codeExample18 = `https://{yourDomain}/authorize?
  audience=https://{yourDomain}/api/v2/
  &scope=update:current_user_identities
  &response_type=token%20id_token
  &client_id={yourClientId}
  &redirect_uri=https://{yourApp}/callback
  &nonce={nonce}
  &state={opaqueValue}
`;

export const codeExample19 = `{
  "iss": "https://{yourDomain}/",
  "sub": "auth0|5a620d29a840170a9ef43672",
  "aud": "https://{yourDomain}/api/v2/",
  "iat": 1521031317,
  "exp": 1521038517,
  "azp": "{yourClientId}",
  "scope": "update:current_user_identities"
}`;

export const codeExample20 = `DELETE https://{yourDomain}/api/v2/users/{primaryAccountUserId}/identities/{secondaryAccountProvider}/{secondaryAccountUserId}
  Authorization: 'Bearer {yourMgmtApiAccessToken}'
`;

これまで、一部のユースケースでは、ユーザーアカウントのリンクやリンク解除に <Tooltip tip="ID トークン: リソースへのアクセスではなく、クライアント自体のための認証情報。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=ID+tokens">ID トークン</Tooltip> を使用できました。Auth0 では、この機能を非推奨化しています。今後は、すべてのケースで <Tooltip tip="ID トークン: リソースへのアクセスではなく、クライアント自体のための認証情報。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=access+tokens">アクセストークン</Tooltip> を使用する必要があります。

<Warning>
  この非推奨化は、潜在的なセキュリティ脆弱性への対応として行われるものです。Auth0 は、できるだけ早くコードを更新することを強く推奨しています。
</Warning>

<h2 id="features-affected">
  影響を受ける機能
</h2>

アカウントリンクに関する変更点は次のとおりです。

* `Authorization` ヘッダーでは ID トークンを使用できなくなりました。代わりにアクセストークンを使用する必要があります。
* `Authorization` ヘッダーで、付与された権限が `update:users` のアクセストークンを使用する場合、リクエストの本文にはセカンダリアカウントの `user_id` または ID トークンのいずれかを送信できます。
* `Authorization` ヘッダーで、付与された権限が `update:current_user_metadata` のアクセストークンを使用する場合、リクエストの本文にはセカンダリアカウントの ID トークンのみを送信できます。
* リクエストの本文にセカンダリアカウントの ID トークンを送信する場合 (前の 2 つの箇条書きで説明したユースケース) 、次の条件を満たす必要があります。

  * ID トークンは `RS256` で署名されている必要があります (この値は **Auth0 Dashboard > クライアント > Client Settings > Advanced Settings > OAuth** で設定できます。
  * ID トークンの `aud` クレームはクライアントを識別するものであり、アクセストークンの `azp` クレームと同じ値である必要があります。
* アカウントのリンク解除では、`Authorization` ヘッダーで ID トークンを使用できなくなりました。代わりにアクセストークンを使用する必要があります。

アカウントをリンクおよびリンク解除する方法はいくつかあります。以下のリストでは、ユースケースと、それぞれが今回の変更によってどのような影響を受けるかを確認できます。

| Use Case                                                                                                                                                                            | Status    |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| Management API の `POST /api/v2/users/{id}/identities` エンドポイントを使用し、プライマリアカウントの ID トークンを `Authorization` ヘッダーで送信する。                                                                   | 影響あり      |
| Management API の `POST /api/v2/users/{id}/identities` エンドポイントを使用し、`authorization` ヘッダーでアクセストークン (スコープ `update:users` を持つ) を送信し、ペイロードにセカンダリアカウントの `user_id` を送信する。                   | 影響なし      |
| Management API の `POST /api/v2/users/{id}/identities` エンドポイントを使用し、`Authorization` ヘッダーでアクセストークン (スコープ `update:current_user_identities` を持つ) を送信し、ペイロードにセカンダリアカウントの `user_id` を送信する。 | 影響あり      |
| Management API の `POST /api/v2/users/{id}/identities` エンドポイントを使用し、`Authorization` ヘッダーでアクセストークンを送信し、ペイロードにセカンダリアカウントの ID トークンを送信する。                                                 | 新しいユースケース |
| auth0.js ライブラリとプライマリアカウントの ID トークンを使用して `auth0.Management` をインスタンス化する。                                                                                                              | 影響あり      |
| auth0.js ライブラリとアクセストークン (スコープ `update:users` を持つ) を使用して `auth0.Management` をインスタンス化する。                                                                                              | 影響なし      |
| auth0.js ライブラリとアクセストークン (スコープ `update:current_user_identities` を持つ) を使用して `auth0.Management` をインスタンス化する。                                                                            | 影響あり      |
| Management API の `DELETE	/api/v2/users/{id}/identities/{provider}/{user_id}` エンドポイントを使用し、プライマリアカウントの ID トークンを `Authorization` ヘッダーで送信する。                                            | 影響あり      |
| Management API の `DELETE	/api/v2/users/{id}/identities/{provider}/{user_id}` エンドポイントを使用し、`Authorization` ヘッダーでアクセストークンを送信する。                                                        | 影響なし      |

<h2 id="actions">
  Actions
</h2>

アカウントリンク用の [Identities endpoint](https://auth0.com/docs/api/management/v2/#!/Users/post_identities) へのすべての呼び出しを確認し、上述の脆弱なフローを利用しているものを更新してください。呼び出しは、次のいずれかの方法に更新できます。

* **クライアント側 / ユーザー主導のリンクのシナリオ:** クライアント側のリンクシナリオでは、`update:current_user_identities` スコープ を持つ アクセストークン を使用して Identities endpoint を呼び出し、ペイロード (`link_with`) にセカンダリアカウントの ID トークンを指定します。この ID トークンは、<Tooltip tip="OAuth 2.0: 認可プロトコルとワークフローを定義する認可フレームワーク。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=OAuth">OAuth</Tooltip>/OIDC-conformant フローを通じて取得する必要があります。
* **サーバー側のリンクのシナリオ**: サーバー側のリンクシナリオでは、`update:users` スコープ を持つ アクセストークン を使用して Identities endpoint を呼び出し、ペイロード にセカンダリアカウントの `user_id` を指定します。

詳しくは、[Link User Accounts](/docs/ja-jp/manage-users/user-accounts/user-account-linking/link-user-accounts) を参照してください。

<h3 id="link-user-accounts">
  ユーザーアカウントをリンクする
</h3>

ユーザーアカウントをリンクするには、<Tooltip tip="Management API: お客様が管理タスクを実行できるようにする製品です。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Management+API">Management API</Tooltip> の[ユーザーアカウントをリンクするエンドポイント](https://auth0.com/docs/api/management/v2#!/Users/post_identities)を呼び出すか、[auth0.js ライブラリ](/docs/ja-jp/libraries/auth0js)を使用します。

<h4 id="link-current-user-accounts-with-the-management-api">
  Management API で現在のユーザーアカウントをリンクする
</h4>

よくあるユースケースとして、ログイン中のユーザーがアプリを使って自分のアカウントをリンクできるようにすることが挙げられます。

非推奨化以前は、Management API で認証するために、プライマリユーザーの ID トークンまたはアクセストークン (`update:current_user_identities` スコープを含む) を使用し、[ユーザーアカウントをリンクするエンドポイント](https://auth0.com/docs/api/management/v2#!/Users/post_identities)を利用できました。

現在は、アクセストークン (`update:current_user_identities` スコープを含む) を取得し、それを使って API で認証したうえで、ユーザーアカウントをリンクするエンドポイントを利用する必要があります。ペイロード には、セカンダリユーザーの ID トークンを指定する必要があります。

1. 次の例のように、`update:current_user_identities` スコープを持つアクセストークンを取得します。この例では [implicit flow](/docs/ja-jp/get-started/authentication-and-authorization-flow/implicit-flow-with-form-post) を使用していますが、どのアプリケーションタイプでも [アクセストークンを取得する](/docs/ja-jp/secure/tokens/access-tokens/get-access-tokens) ことができます。

2. 以前の ID トークンを使う方法では、コードは次のようになります。

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

   新しいアクセストークンを使う方法では、コードは次のようになります。

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

3. Management API にアクセスできるアクセストークンを取得するには:

   1. `audience` を `https://{yourDomain}/api/v2/` に設定します。
   2. `scope` として `${scope}` を要求します。
   3. `response_type` を `id_token token` に設定し、Auth0 が ID トークンとアクセストークンの両方を送信するようにします。
      アクセストークンをデコードして内容を確認すると、次のようになります。

      <AuthCodeBlock children={codeExample3} language="json" />

      `aud` にはテナントの API URI、`scope` には `${scope}`、`sub` にはログイン中のユーザー ID が設定されていることがわかります。

4. 次の条件を満たしている必要があります。

   1. セカンダリアカウントの ID トークンは `RS256` で署名されている必要があります。
   2. セカンダリアカウントの ID トークン内の `aud` クレームはクライアントを識別している必要があり、リクエストに使用するアクセストークンの `azp` クレームと同じ値である必要があります。

5. アクセストークンを取得したら、それを使ってユーザーアカウントをリンクできます。この部分は変わらず、リクエストで変わるのは `Bearer` トークンとして使用する値だけです。レスポンスも同じです。

   <AuthCodeBlock children={codeExample4} language="json" />

<h4 id="link-current-user-accounts-with-auth0js">
  auth0.js で現在のユーザーアカウントをリンクする
</h4>

[auth0.js library](/docs/ja-jp/libraries/auth0js) を使用して Management API にアクセスし、アカウントをリンクしている場合は、ユーザーのプライマリ ID の ID トークンを使って `auth0.Management` をインスタンス化し、それを使ってアカウントをリンクしていることが多いでしょう。

1. `update:current_user_identities` スコープ を含む アクセストークン を取得し、そのトークンを使って `auth0.Management` をインスタンス化します。最後の `linkUser` の呼び出しはこれまでと同じです。
2. 従来の ID トークンを使用する方法では、コードは次のようになります。

   <AuthCodeBlock children={codeExample5} language="javascript" />

   新しい アクセストークン を使用する方法では、コードは次のようになります。

   <AuthCodeBlock children={codeExample6} language="javascript" />

   1. レスポンスとして ID トークンと アクセストークン の両方を要求します (`` responseType: `token id_token` ``)。
   2. トークンの対象 audience として Management API を設定します (`` audience: `https://YOUR_DOMAIN/api/v2/` ``)。
   3. 必要な permission を要求します (`` scope: `update:current_user_identities` ``)。
   4. アクセストークン を使用して Management API に対して認証します。

<h4 id="link-any-user-account-with-the-management-api">
  Management API を使用して任意のユーザーアカウントをリンクする
</h4>

`update:users` スコープを含むアカウントリンク用のアクセストークンを取得し、セカンダリアカウントの `user_id` と `provider` をリクエストで送信している場合は、何も変更する必要はありません。

ただし、この新しい方法では、これとは別の方法も利用できます。引き続き、API で認証するには `update:users` スコープを含むアクセストークンを使用しますが、リクエストのペイロードでは、`user_id` と `provider` の代わりに、セカンダリアカウントの ID トークンを送信できます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">Auth0 CLI を使用していますか？まだの場合は、このコマンドを実行する前に、[CLI セッションを設定して認証してください](/docs/ja-jp/deploy-monitor/auth0-cli)。</Callout>

<AuthCodeGroup>
  ```bash Auth0 CLI lines theme={null}
  auth0 api post "users/PRIMARY_ACCOUNT_USER_ID/identities" \
    --data '{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}'
  ```

  ```bash cURL lines theme={null}
  curl --request POST \
    --url 'https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities' \
    --header 'authorization: Bearer ACCESS_TOKEN' \
    --header 'content-type: application/json' \
    --data '{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}'
  ```

  ```csharp C# lines theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities");
  var request = new RestRequest(Method.POST);
  request.AddHeader("authorization", "Bearer ACCESS_TOKEN");
  request.AddHeader("content-type", "application/json");
  request.AddParameter("application/json", "{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}", ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  ```

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

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

  func main() {

  	url := "https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities"

  	payload := strings.NewReader("{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}")

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

  	req.Header.Add("authorization", "Bearer ACCESS_TOKEN")
  	req.Header.Add("content-type", "application/json")

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

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

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

  }
  ```

  ```java Java lines theme={null}
  HttpResponse<String> response = Unirest.post("https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities")
    .header("authorization", "Bearer ACCESS_TOKEN")
    .header("content-type", "application/json")
    .body("{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}")
    .asString();
  ```

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

  var options = {
    method: 'POST',
    url: 'https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities',
    headers: {authorization: 'Bearer ACCESS_TOKEN', 'content-type': 'application/json'},
    data: {link_with: 'SECONDARY_ACCOUNT_ID_TOKEN'}
  };

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

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

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}",
    CURLOPT_HTTPHEADER => [
      "authorization: Bearer ACCESS_TOKEN",
      "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 lines theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")

  payload = "{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}"

  headers = {
      'authorization': "Bearer ACCESS_TOKEN",
      'content-type': "application/json"
      }

  conn.request("POST", "/{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities", payload, headers)

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

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

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

  url = URI("https://{yourDomain}/api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities")

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

  request = Net::HTTP::Post.new(url)
  request["authorization"] = 'Bearer ACCESS_TOKEN'
  request["content-type"] = 'application/json'
  request.body = "{"link_with":"SECONDARY_ACCOUNT_ID_TOKEN"}"

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

以下の条件が適用されます：

* セカンダリ アカウントの ID トークン は、`RS256` で署名されている必要があります。
* セカンダリ アカウントの ID トークン の `aud` クレームはクライアントを識別する必要があり、リクエストの実行に使用するアクセストークンの `azp` クレームと同じ値でなければなりません。

<h3 id="unlink-user-accounts">
  ユーザーアカウントのリンク解除
</h3>

アカウントのリンク解除に ID トークンを使用している場合は、アクセストークンを使うようにコードを更新する必要があります。

1. まず、`update:current_user_identities` scope を持つアクセストークンを取得する必要があります。

2. 以前の ID トークンを使う方法では、コードは次のようになります。

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

   新しいアクセストークンを使う方法では、コードは次のようになります。

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

3. Management API にアクセスできるアクセストークンを取得するには:

   1. `audience` を `https://{yourDomain}/api/v2/` に設定します。
   2. `scope` に `${scope}` を指定します。
   3. `response_type` を `id_token token` に設定すると、Auth0 から ID トークンとアクセストークンの両方が返されます。
      アクセストークンをデコードして内容を確認すると、次のようになります。

      <AuthCodeBlock children={codeExample19} language="json" />

      `aud` にはテナントの API URI が、`scope` には `update:current_user_identities` が、`sub` にはログインしているユーザーのユーザー ID が設定されていることに注目してください。

4. アクセストークンを取得したら、それを `Authorization` ヘッダーに指定して、Management API の [Unlink a user identity endpoint](https://auth0.com/docs/api/management/v2#!/Users/delete_user_identity_by_user_id) を呼び出すことができます。

5. 以前の方法での呼び出しは、次のようになります。

   ```http lines theme={null}
   DELETE https://YOUR_DOMAIN/api/v2/users/{primaryAccountUserId}/identities/{secondaryAccountProvider}/{secondaryAccountUserId}
       Authorization: 'Bearer {yourIdTokenOrMgmtApiAccessToken}'
   ```

   新しい方法での呼び出しは、次のようになります。

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

<h2 id="security-considerations">
  セキュリティに関する考慮事項
</h2>

特定のアカウントリンクのフローに脆弱性があることを確認しており、特定の状況では悪用される可能性があります。これが悪意をもって利用された証拠は見つかっていませんが、そのような事態を未然に防ぐため、このフローを非推奨とすることを決定しました。

そのため、影響を受けるアカウントリンクのフローを使用している Auth0 のお客様は、2018 年 10 月 19 日までに、より安全な実装へ移行する必要があります。移行方法はこのガイドで案内しており、機能が失われることはありません。

2018 年 10 月 19 日以降、影響を受けるアカウントリンクのフローは無効化され、実行時エラーが発生します。

[Post Identities endpoint](https://auth0.com/docs/api/management/v2#!/Users/post_identities) を、Authorization ヘッダーでスコープ `update:current_user_identities` を持つトークン (ID トークンまたはアクセストークン) を使用して呼び出し、かつペイロードにセカンダリアカウントの `user_id` を含めている場合は、影響を受けます。その他のユースケースには影響ありません。

<h2 id="learn-more">
  詳しくはこちら
</h2>

* [アクセストークンを使用した Management API エンドポイントの呼び出しへの移行](/docs/ja-jp/troubleshoot/product-lifecycle/past-migrations/migrate-to-calling-api-with-access-tokens)
