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

> SSO セッションを終了し、ブラウザーをアプリケーションのログアウト URL に戻すログアウトエンドポイントを介してユーザーをログアウトさせる方法を学びます。

# OIDC エンドポイントを使用して Auth0 でユーザーをログアウトさせる

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 codeExample3 = `https://{yourDomain}/oidc/logout?{clientId}={yourClientId}&logout_hint={sessionId}`;

export const codeExample4 = `https://{yourDomain}/oidc/logout?post_logout_redirect_uri=http%3A%2F%2Fwww.example.com`;

export const codeExample5 = `PATCH https://{yourDomain}/api/v2/clients/{clientId}
Authorization: Bearer {yourMgmtApiAccessToken}
Content-Type: application/json

{
  "allowed_logout_urls": [
    "https://www.example.com",
    "https://www.example.com/logout"
  ]
}
`;

export const codeExample6 = `PATCH https://{yourDomain}/api/v2/tenants/settings
Authorization: Bearer {yourMgmtApiAccessToken}
Content-Type: application/json

{
  "allowed_logout_urls": [
    "https://www.example.com",
    "https://www.example.com/logout"
  ]
}
`;

Auth0 は、エンドユーザーのログアウト向けに <Tooltip tip="OpenID: アプリケーションがログイン情報を収集・保存することなく、ユーザーの本人確認を行えるようにする認証のためのオープン標準。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=OpenID">OpenID</Tooltip> Connect の [RP-Initiated Logout 1.0](https://openid.net/specs/openid-connect-rpinitiated-1_0.html) を実装しています。この標準は、OpenID Connect の[最終仕様](https://openid.net/developers/specs/)群の一部です。

<div id="how-it-works">
  ## 仕組み
</div>

RP-Initiated Logout は、<Tooltip tip="Relying Party: ユーザーを認証するためにサードパーティのアイデンティティプロバイダーに依存するエンティティ（サービスやアプリケーションなど）。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=relying+party">relying party</Tooltip> (ユーザー) が OpenID プロバイダー (Auth0) にログアウトを要求するシナリオです。

1. ユーザーがアプリケーションでログアウトを開始します。
2. アプリケーションはユーザーを Auth0 Authentication API の [OIDC Logout](https://auth0.com/docs/api/authentication#oidc-logout) エンドポイントに誘導します。
3. Auth0 は、指定された [OIDC Logout エンドポイントパラメーター](#oidc-logout-endpoint-parameters) に基づいて、ユーザーを適切な宛先にリダイレクトします。

<div id="configure-rp-initiated-logout">
  ## RP-Initiated Logout を設定する
</div>

RP-Initiated Logout を設定するには、アプリケーションが Auth0 テナントの[ディスカバリメタデータドキュメント](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig)から `end_session_endpoint` パラメータを取得できること、および必要なパラメータを指定して OIDC Logout エンドポイントを呼び出すことを確認する必要があります。

<div id="enable-endpoint-discovery">
  ### endpoint discovery を有効にする
</div>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  2023年11月14日以降に作成されたAuth0 テナントでは、**RP-Initiated Logout End Session Endpoint Discovery** はデフォルトで有効になっています。
</Callout>

**RP-Initiated Logout End Session Endpoint Discovery** は、<Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 のメイン製品です。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=Auth0+Dashboard">Auth0 Dashboard</Tooltip> または Auth0 の <Tooltip tip="Management API: お客様が管理タスクを実行できるようにする製品です。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=Management+API">Management API</Tooltip> で有効にできます。

<Tabs>
  <Tab title="Auth0 Dashboard">
    Auth0 Dashboard で **RP-Initiated Logout End Session Endpoint Discovery** を有効にするには:

    1. [Auth0 Dashboard > 設定 > Advanced](https://manage.auth0.com/#/tenant/advanced) に移動します。
    2. **Login and Logout** セクションを探します。
    3. **RP-Initiated Logout End Session Endpoint Discovery** のトグルを有効にします。
  </Tab>

  <Tab title="Management API">
    Management API で **RP-Initiated Logout End Session Endpoint Discovery** を有効にするには:

    1. `update:tenant_settings` スコープを含む [Management API アクセストークンを取得します](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)。
    2. 次の payload を使用して、Management API の [テナント設定を更新](https://auth0.com/docs/api/management/v2/tenants/patch-settings) endpoint を呼び出します。

       ```json JSON lines theme={null}
       {
         "oidc_logout": {
           "rp_logout_end_session_endpoint_discovery": true
         }
       }
       ```
  </Tab>
</Tabs>

<div id="call-the-oidc-logout-endpoint">
  ### OIDC Logout エンドポイントを呼び出す
</div>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Auth0の[SDKライブラリ](/docs/ja-jp/libraries)の大半はOIDCに準拠しており、標準でRP-Initiated Logoutをサポートしています。
</Callout>

OIDC Logout エンドポイントを呼び出す際は、`id_token_hint` パラメーターを指定することが Auth0 によって推奨されています。

アプリケーションで<Tooltip tip="ID トークン: リソースへのアクセスではなく、クライアント自体を対象とした資格情報です。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=ID+tokens">ID トークン</Tooltip>を安全に保存できない場合は、代わりに `logout_hint` と `client_id` パラメーターを指定できます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  OIDC Logout エンドポイントは、冗長な情報を含めて呼び出すこともできます。

  たとえば、`id_token_hint` と `logout_hint`、または `id_token_hint` と `client_id` を送信できます。

  どの場合でも、Auth0 はユーザーとセッションのデータに整合性があるかを確認し、不一致があればエラーを返します。
</Callout>

<div id="oidc-logout-endpoint-parameters">
  #### OIDC Logout エンドポイントのパラメーター
</div>

Authentication API の [OIDC Logout](https://auth0.com/docs/api/authentication#oidc-logout) エンドポイントは、以下のパラメーターをサポートしています。

| パラメーター                     | 必須? | 説明                                                                                     |
| -------------------------- | --- | -------------------------------------------------------------------------------------- |
| `id_token_hint`            | 推奨  | そのユーザーに以前発行された ID トークン。どのユーザーをログアウトするかを示します。                                           |
| `logout_hint`              | 任意  | どのユーザーをログアウトするかを示すセッション ID (`sid`) の値。                                                 |
| `post_logout_redirect_uri` | 任意  | ログアウト後にユーザーをリダイレクトする先を示すリダイレクト URL の値。                                                 |
| `client_id`                | 任意  | アプリケーションの Client ID。                                                                   |
| `federated`                | 任意  | ユーザーをそのアイデンティティプロバイダーからログアウトさせるよう Auth0 に指示します。                                        |
| `state`                    | 任意  | アプリケーションが最初のログアウトリクエストに追加し、Auth0 が `post_logout_redirect_uri` へのリダイレクト時に含める opaque な値。 |
| `ui_locales`               | 任意  | リクエストで使用する言語リストを制限するための、スペース区切りのロケール一覧です。一覧の先頭のロケールは、テナントで有効になっているロケールと一致している必要があります。  |

<div id="id_token_hint-parameter">
  #### id\_token\_hint パラメーター
</div>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Auth0 では、OIDC Logout エンドポイントを呼び出す際に `id_token_hint` パラメーターを使用することを推奨しています。
</Callout>

`id_token_hint` パラメーターの値には、ユーザーが認証された後に Auth0 が発行した ID トークンを指定する必要があります。

ID トークンには、検証に使用する登録済みクレームの issuer (`iss`)、<Tooltip tip="Audience: 発行されたトークンの audience の一意の識別子です。トークン内では aud という名前で、その値には ID トークンの場合はアプリケーション (Client ID)、Access Token の場合は API (API Identifier) の ID が含まれます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=audience">audience</Tooltip> (`aud`)、および Auth0 セッション ID (`sid`) が含まれます。ID トークンのクレームの詳細については、[ID Token Structure](/docs/ja-jp/secure/tokens/id-tokens/id-token-structure) を参照してください。

<div id="examples">
  ##### 例
</div>

<AuthCodeGroup>
  ```http HTTP theme={null}
  https://{yourDomain}/oidc/logout?id_token_hint={yourIdToken}&post_logout_redirect_uri={yourCallbackUrl}
  ```

  ```bash cURL theme={null}
  curl --request GET \
    --url 'https://{yourDomain}/oidc/logout' \
    --header 'content-type: application/x-www-form-urlencoded' \
    --data 'id_token_hint={yourIdToken}' \
    --data 'post_logout_redirect_uri={yourCallbackUrl}'
  ```
</AuthCodeGroup>

<div id="logout_hint-parameter">
  #### logout\_hint パラメータ
</div>

`logout_hint` パラメータの値には、ユーザーの現在の Auth0 セッションのセッション ID (`sid`) を指定する必要があります。

セッション ID (`sid`) は、ユーザーの認証後に Auth0 が発行した ID トークン内の登録済みクレームとして提供されます。

<Warning>
  現在のセッションの開始時に Auth0 が発行した ID トークンに関連付けられたセッション ID (`sid`) を使用する必要があります。Auth0 は、ランダムな値や現在のセッション データを反映していない値を含むリクエストを無視します。
</Warning>

<div id="examples">
  ##### 例
</div>

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

<div id="post_logout_redirect_uri-parameter">
  #### post\_logout\_redirect\_uri パラメーター
</div>

`post_logout_redirect_uri` パラメーターの値は、有効でエンコード済みの URL で、次のいずれかの **Allowed Logout URLs** の一覧に登録されている必要があります。

1. [アプリケーション設定](/docs/ja-jp/get-started/applications/application-settings#application-uris): `id_token_hint` パラメーター、または `logout_hint` パラメーターと `client_id` パラメーターを指定する場合。
2. [テナント設定](/docs/ja-jp/get-started/tenant-settings#login-and-logout): `logout_hint` パラメーターのみを指定する場合。

<div id="examples">
  ##### 例
</div>

<AuthCodeBlock children={codeExample4} language="http" filename="HTTP" />

<div id="update-application-allowed-logout-urls">
  ##### アプリケーションの Allowed Logout URLs を更新する
</div>

Auth0 Dashboard または Auth0 Management API を使用して、アプリケーションの **Allowed Logout URLs** のリストに URL を登録できます。

<Tabs>
  <Tab title="Auth0 Dashboard">
    Auth0 Dashboard でアプリケーションの **Allowed Logout URLs** のリストに URL を登録するには、次の手順に従います。

    1. [Auth0 Dashboard > Applications > Applications](https://manage.auth0.com/#/applications) に移動します。
    2. 対象のアプリケーションを選択します。
    3. **Application URIs** セクションを見つけます。
    4. [ガイドライン](#allowed-logout-urls-guidelines) に従って **Allowed Logout URLs** を更新します。
  </Tab>

  <Tab title="Management API">
    <Warning>
      Management API の [Update a client](https://auth0.com/docs/api/management/v2/clients/patch-clients-by-id) エンドポイントを呼び出すと、リクエスト本文で指定したフィールドの既存の設定データはすべて上書きされます。

      意図しないデータ損失を防ぐため、まず Management API の [Get a client](https://auth0.com/docs/api/management/v2/clients/get-clients-by-id) エンドポイントを呼び出して、アプリケーションの現在の設定データを取得してください。
    </Warning>

    Management API を使用してアプリケーションの **Allowed Logout URLs** のリストに URL を登録するには、次の手順に従います。

    1. `update:clients` スコープを含む [Management API アクセストークンを取得します](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)。
    2. Management API の [Update a client](https://auth0.com/docs/api/management/v2/clients/patch-clients-by-id) エンドポイントを呼び出し、リクエスト本文内の `allowed_logout_urls` フィールドの値にその URL を含めます。

    <AuthCodeBlock children={codeExample5} language="http" />
  </Tab>
</Tabs>

<div id="update-tenant-allowed-logout-urls">
  ##### テナントの Allowed Logout URLs を更新
</div>

Auth0 Dashboard または Auth0 Management API を使用して、テナントの **Allowed Logout URLs** リストに URL を登録できます。

<Tabs>
  <Tab title="Auth0 Dashboard">
    Auth0 Dashboard でテナントの **Allowed Logout URLs** リストに URL を登録するには、次の手順に従います。

    1. [Auth0 Dashboard > 設定 > Advanced](https://manage.auth0.com/#/tenant/advanced) に移動します。
    2. **Login and Logout** セクションを見つけます。
    3. [以下のガイドライン](#allowed-logout-urls-guidelines) に従って **Allowed Logout URLs** を更新します。
  </Tab>

  <Tab title="Management API">
    <Warning>
      Management API の [テナント設定を更新](https://auth0.com/docs/api/management/v2/tenants/patch-settings) エンドポイントを呼び出すと、リクエスト本文で指定したフィールドの既存の設定データはすべて上書きされます。

      誤ってデータを失わないよう、まず Management API の [Get tenant settings](https://auth0.com/docs/api/management/v2/tenants/tenant-settings-route) エンドポイントを呼び出して、現在のテナント設定データを取得してください。
    </Warning>

    Management API を使用してテナントの **Allowed Logout URLs** リストに URL を登録するには、次の手順に従います。

    1. `update:tenant_settings` スコープを含む [Management API アクセストークンを取得](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) します。
    2. Management API の [テナント設定を更新](https://auth0.com/docs/api/management/v2/tenants/patch-settings) エンドポイントを呼び出し、リクエスト本文内の `allowed_logout_urls` フィールドの値にその URL を含めるようにします。

    <AuthCodeBlock children={codeExample6} language="http" />
  </Tab>
</Tabs>

<div id="allowed-logout-urls-guidelines">
  ##### Allowed Logout URLs のガイドライン
</div>

検証エラーを避けるため、**Allowed Logout URLs** を更新する際は、以下のガイドラインに従ってください。

* 複数の URL 値はコンマ (`,`) で区切ってください。
* URL スキーム (たとえば `https://`) を含めてください。

サブドメイン用のワイルドカードとしてアスタリスク (`*`) を使用できます (たとえば `https://*.example.com`) 。ただし、本番環境ではワイルドカードを使用しないことを推奨します。詳しくは、[Subdomain URL Placeholders](/docs/ja-jp/get-started/applications/wildcards-for-subdomains#wildcard-url-placeholders) を参照してください。

<div id="add-query-string-parameters-to-post_logout_redirect_uri">
  ##### post\_logout\_redirect\_uri にクエリ文字列パラメーターを追加する
</div>

OIDC Logout エンドポイントは、`post_logout_redirect_uri` パラメーターで指定された URL のクエリ文字列パラメーターを解析します。

**Allowed Logout URLs** には、**クエリ文字列パラメーターを含む完全一致の URL** を含める必要があります。そうしないと、logout request は拒否されます。URL は、すべてのクエリパラメータ名と値を含めて、完全に一致している必要があります。

たとえば、`https://example.com/logout?myParam=1234` を `post_logout_redirect_uri` パラメーターに渡す場合 (`https%3A%2F%2Fexample.com%2Flogout%3FmyParam%3D1234` としてエンコードされます) 、完全な URL `https://example.com/logout?myParam=1234` を **Allowed Logout URLs** に含める必要があります。

<Warning>
  動的なクエリパラメータ値はサポートされていません。クエリパラメータ名と値の組み合わせごとに、**Allowed Logout URLs** に個別のエントリとして登録する必要があります。
</Warning>

<div id="ui_locales-parameter">
  #### `ui_locales` パラメーター
</div>

`ui_locales` パラメーターの値は、スペース区切りの [サポートされているロケール](/docs/ja-jp/customize/internationalization-and-localization/universal-login-internationalization#new-universal-login-experience-localization) のリストである必要があります。

リストの最初の値は、[テナントのデフォルト言語設定](/docs/ja-jp/get-started/tenant-settings#languages) と一致している必要があります。

<div id="federated-parameter">
  #### `federated` パラメーター
</div>

`federated` パラメーターには値を指定する必要はありません。

OIDC Logout エンドポイントを呼び出す際に `federated` パラメーターを含めると、Auth0 は[ユーザーをそのアイデンティティプロバイダーからログアウトさせようとします](/docs/ja-jp/authenticate/login/logout/log-users-out-of-idps)。

<div id="logout-consent-prompt">
  ## ログアウト同意プロンプト
</div>

OIDC 標準では、OpenID プロバイダーがそのリクエストがユーザー本人によるものだと確認できない場合、ユーザーに同意を求めるためにログアウト フローを中断する必要があると定められています。

Auth0 は、次のいずれかの条件を検出した場合に、ログアウト同意プロンプトを表示してこの動作を実施します。

* `id_token_hint` と `logout_hint` のパラメーターがどちらも指定されていない。
* ID トークンの `sid` クレームが、リクエスト内のブラウザーセッションに対応していない。
* `logout_hint` パラメーターの値が、現在のセッションデータと一致しない。

<Frame>
  <img src="https://mintcdn.com/translations/MV7tE-x71x8RWRES/docs/images/cdy7uua7fh8z/5Sycg1aMJ1CLZwJj19Omv4/655fa33b439217d0410fba1335c63a63/Logout_-_English.png?fit=max&auto=format&n=MV7tE-x71x8RWRES&q=85&s=d8ad7352e79214a9b64766c2f3e90dab" alt="" width="496" height="671" data-path="docs/images/cdy7uua7fh8z/5Sycg1aMJ1CLZwJj19Omv4/655fa33b439217d0410fba1335c63a63/Logout_-_English.png" />
</Frame>

ユーザーがログアウト リクエストを確認すると、Auth0 はログアウト フローを続行します。

<div id="disable-the-logout-consent-prompt">
  ### ログアウトの同意プロンプトを無効にする
</div>

ログアウトの同意プロンプトは無効にできます。無効にすると、Auth0 は異常な挙動を検出しようとせず、ログアウトリクエストを自動的に受け入れます。

Auth0 Dashboard でログアウトの同意プロンプトを無効にするには、次の手順に従います。

1. [Auth0 Dashboard > 設定 > Advanced](https://manage.auth0.com/#/tenant/advanced) に移動します。
2. **Show RP-Initiated Logout End-User Confirmation** トグルを無効にします。

   <Frame>
     <img src="https://mintcdn.com/translations/3nS3prIggmJG9TUI/docs/images/cdy7uua7fh8z/37K4hLjhSBMGvdGP9OEP7W/5ca88519a0c7b04951f880fa2fc47bd7/Login_and_Logout_-_English.png?fit=max&auto=format&n=3nS3prIggmJG9TUI&q=85&s=e141dc05f51e0d87214156e726e4eeec" alt="" width="1002" height="1124" data-path="docs/images/cdy7uua7fh8z/37K4hLjhSBMGvdGP9OEP7W/5ca88519a0c7b04951f880fa2fc47bd7/Login_and_Logout_-_English.png" />
   </Frame>

<div id="learn-more">
  ## 詳細はこちら
</div>

* [アプリケーションからユーザーをログアウトさせる](/docs/ja-jp/authenticate/login/logout/log-users-out-of-applications)
* [IDプロバイダーからユーザーをログアウトさせる](/docs/ja-jp/authenticate/login/logout/log-users-out-of-idps)
* [SAML IDプロバイダーからユーザーをログアウトさせる](/docs/ja-jp/authenticate/login/logout/log-users-out-of-saml-idps)
* [代替ログアウトを使用してユーザーをリダイレクトする](/docs/ja-jp/authenticate/login/logout/redirect-users-after-logout)
