> ## 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 Dashboard、Authentication API、または Management API を使用して取り消す方法を学びます。

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

<Tooltip tip="リフレッシュトークン: ユーザーに再度ログインさせることなく、新しいアクセストークンを取得するために使われるトークンです。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=refresh+tokens">リフレッシュトークン</Tooltip>が漏えいした場合は、取り消すことができます。Auth0 は、トークンの取り消しを、そのトークンが悪意のある第三者に渡った可能性があるものとして処理します。

さらに、クライアントがリフレッシュトークンを使って新しいアクセストークンを取得するたびに、新しいリフレッシュトークンも返されるように、[Refresh Tokenのローテーション](/docs/ja-jp/secure/tokens/refresh-tokens/refresh-token-rotation)を有効にすることも検討できます。

<div id="choose-whether-token-revocation-deletes-grants">
  ## トークン取り消し時にグラントも削除するかどうかを選択する
</div>

グラントは、ユーザーの資格情報を公開することなく、別のエンティティ上のリソースへのアクセス権をアプリケーションに付与するものです。トークンはグラントに基づいて発行されます。

グラントが取り消されると、そのグラントに基づいて発行されたすべてのトークンも取り消されます。ただし、トークンを取り消しても、必ずしもグラントまで取り消す必要はありません。

テナント設定で、トークンの取り消し時に関連するグラントを削除するかどうかを選択できます。

1. [Auth0 Dashboard > Tenant Settings > Advanced](https://manage.auth0.com/#/tenant/advanced) に移動します。

2. **Settings** セクションで、**Refresh Token Revocation Deletes Grant** トグルを有効または無効にします。

   * リフレッシュトークンを取り消すときに、元になるグラントも削除するには、このトグルを有効にします。

   取り消しリクエストが行われるたびに、同じ認可グラントに基づくほかのすべてのトークンが無効になり、同じユーザー、アプリケーション、audience に対して発行されたすべてのリフレッシュトークンが取り消されます。

   * リフレッシュトークンを取り消すときに、元になるグラントを保持するには、このトグルを無効にします。

   デバイスのリンクが解除されると、関連付けられたリフレッシュトークンのみが取り消され、グラントはそのまま維持されます。

この機能は、2021 年 1 月 13 日以降に作成されたすべてのテナントで、デフォルトで無効になっています。

<div id="revoke-a-refresh-token">
  ## リフレッシュトークンを取り消す
</div>

リフレッシュトークンは、次の方法で取り消せます。

* [Auth0 Dashboardを使用する](#using-the-auth0-dashboard)
* [Authentication APIを使用する](#using-the-authenticaton-api)
* [Management APIを使用する](#using-the-management-api)

<div id="using-the-auth0-dashboard">
  ### Auth0 Dashboardを使用する
</div>

Auth0 Dashboardを使用して、トークンを発行したアプリケーションに対するユーザーのアクセス承認を取り消すことができます。これによりリフレッシュトークンは無効になり、実質的にはトークン自体を取り消すのと同じです。

1. [Auth0 Dashboard > User Management > Users](https://manage.auth0.com/#/users) に移動し、詳細を表示するユーザーの名前を選択します。
2. **Authorized Applications** タブを選択します。このページには、ユーザーがアクセスを承認しているすべてのアプリケーションが一覧表示されます。
3. 承認済みアプリケーションへのユーザーのアクセスを取り消してリフレッシュトークンを無効にするには、**Revoke** をクリックします。

<div id="using-the-authentication-api">
  ### Authentication API の使用
</div>

Authentication API の[リフレッシュトークン取り消しエンドポイント](https://auth0.com/docs/api/authentication/revoke-refresh-token/revoke-refresh-token)を使用して、リフレッシュトークンを取り消すことができます。

このエンドポイントは、<Tooltip tip="Client Secret: client（アプリケーション）がAuthorization Serverに対して認証を行うために使用するSecret です。これはclientとAuthorization Serverのみが知っているべき情報であり、推測されないよう十分にランダムでなければなりません。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=client+secret">client secret</Tooltip> を安全に保持できないアプリケーション (ネイティブアプリなど) 向けに、client secret なしでのアクセスをサポートしています。アプリケーション自体の[認証方式](/docs/ja-jp/get-started/applications/credentials) (`tokenEndpointAuthMethod`) は `none` に設定されている必要があります。

リクエストを行うと、API はまずアプリケーションの資格情報を検証し、次にそのトークンが取り消しリクエストを行っているアプリケーションに対して発行されたものかどうかを確認します。この検証に失敗した場合、リクエストは拒否され、アプリケーションにエラーが通知されます。

次に、API はトークンを無効化します。無効化は即時に行われ、取り消し後、そのトークンは再度使用できません。各取り消しリクエストでは、同じ認可グラントに対して発行されたすべてのトークンが無効化されます。

body パラメーター、response schema、コード例などの詳細については、Authentication API ドキュメントの[リフレッシュトークン取り消しエンドポイント](https://auth0.com/docs/api/authentication/revoke-refresh-token/revoke-refresh-token)を参照してください。

<div id="using-the-management-api-device-credentials-endpoints">
  ### Management API のデバイス資格情報エンドポイントを使用する
</div>

Auth0 Management API のデバイス資格情報エンドポイントを使用してリフレッシュトークンを取り消すには、次の手順に従います。

1. [デバイス資格情報を取得するエンドポイント](https://auth0.com/docs/api/management/v2/device-credentials/get-device-credentials)を使用して、取り消す対象のリフレッシュトークンの `id` を取得します。

   `read:device_credentials` スコープを含むアクセストークンを使用し、`type=refresh_token` と `user_id` を指定します。結果を絞り込むには、トークンに関連付けられた `client_id` (わかっている場合) を指定することもできます。

2. [デバイス資格情報を削除するエンドポイント](https://auth0.com/docs/api/management/v2/device-credentials/delete-device-credentials-by-id)を使用して、リフレッシュトークンを取り消します。`delete:device_credentials` スコープを含むアクセストークンと、リフレッシュトークン ID を指定します。

<div id="using-the-management-api-refresh-token-endpoints">
  ### Management API のリフレッシュトークンエンドポイントを使用する
</div>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Auth0 Management API のリフレッシュトークンエンドポイントは現在、Enterprise プランをご利用のお客様のみご利用いただけます。詳しくは、[料金](https://auth0.com/pricing)をご覧ください。
</Callout>

Management API のリフレッシュトークンエンドポイントは、拡張プロパティと一括取り消し操作を備えており、`/v2/device-credentials` リソースエンドポイントに代わるものです。

以下のエンドポイントを使用して、特定のリフレッシュトークンの情報を確認したり、取り消したりできます。

* [Get a refresh token endpoint](https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token) を使用して、ID でリフレッシュトークンの情報を確認する
* [Delete a refresh token endpoint](https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token) を使用して、ID でリフレッシュトークンを取り消す
* [Get refresh tokens for a user endpoint](https://auth0.com/docs/api/management/v2/users/get-refresh-tokens-for-user) を使用して、ユーザーのすべてのリフレッシュトークンを一覧表示する
* [Delete refresh tokens for a user endpoint](https://auth0.com/docs/api/management/v2/users/delete-refresh-tokens-for-user) を使用して、ユーザーのすべてのリフレッシュトークンを取り消す

<div id="considerations-and-limitations">
  ## 考慮事項と制限事項
</div>

* [Device Authorization Flow](/docs/ja-jp/get-started/authentication-and-authorization-flow/device-authorization-flow) では、デバイスに再認可を強制する唯一の方法は、そのデバイスに割り当てられたリフレッシュトークンを取り消すことです。デバイスが再認可を求められるのは、現在のアクセストークンの有効期限が切れ、アプリケーションが取り消されたリフレッシュトークンを使用しようとしたときです。詳しくは、[Unlink Devices from Users](/docs/ja-jp/manage-users/user-accounts/unlink-devices-from-users) を参照してください。

* [Refresh Tokenのローテーション](/docs/ja-jp/secure/tokens/refresh-tokens/refresh-token-rotation) を使用している場合、以前に無効化されたトークンが使用されると、その無効化されたトークンの発行以降に発行されたリフレッシュトークン一式が直ちに取り消されるため、エンドユーザーは再度認証する必要があります。

* リフレッシュトークンの取り消し (`DELETE`) 操作は非同期で実行され、結果整合性です。

* 2023-09-21 以降 (US-3 リージョンのテナントでは 2024-02-22 以降) に発行されたリフレッシュトークンには、適切な値が設定されたセッション ID (`session_id`) プロパティが含まれます。この日付より前に発行されたリフレッシュトークンでは、このプロパティの値は `null` です。

リフレッシュトークンの制限事項の詳細については、[Refresh Tokens limitations](/docs/ja-jp/secure/tokens/refresh-tokens) を参照してください。
