> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.generaltranslation.app/llms.txt
> Use this file to discover all available pages before exploring further.

# OIDC接続のPKCEとクレームのマッピングを構成する

> Proof Key for Code Exchange（PKCE）と、OpenID Connect・Okta Workforce接続のマッピングテンプレートを構成します。

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        let processedChildren = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          processedChildren = processedChildren.replace(new RegExp(key, "g"), value);
        }
        setProcessedChildren(processedChildren);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
      {processedChildren}
    </CodeBlock>;
};

export const codeExample1 = `curl --request POST \
--url 'https://{yourDomain}/api/v2/connections' \
--header 'authorization: Bearer MGMT_API_ACCESS_TOKEN' \
--data '{ 
  "strategy": "oidc", 
   "name": "CONNECTION_NAME", 
   "options": { 
     "type": "back_channel", 
     "discovery_url": "https://IDP_DOMAIN/.well-known/openid-configuration", 
     "client_id" : "IDP_CLIENT_ID", 
     "client_secret" : "IDP_CLIENT_SECRET", 
     "scopes": "openid profile", 
     "connection_settings": { "pkce": "auto" }
               } 
          }'`;

export const codeExample2 = `curl --request POST \
  --url 'https://{yourDomain}/api/v2/connections' \
  --header 'authorization: Bearer MGMT_API_ACCESS_TOKEN' \
  --data '{
    "strategy": "oidc",
    "name": "CONNECTION_NAME",
    "options": {
      "type": "back_channel",
      "client_id": "IDP_CLIENT_ID",
      "client_secret": "IDP_CLIENT_SECRET",
      "connection_settings": { "pkce": "auto" },
      "issuer": "https://IDP_DOMAIN",
      "authorization_endpoint": "https://IDP_DOMAIN/authorize",
      "jwks_uri": "https://IDP_DOMAIN/.well-known/jwks.json",
      "scopes": "openid profile",
      "oidc_metadata": {
        "issuer": "https://IDP_DOMAIN",
        "authorization_endpoint": "https://IDP_DOMAIN/authorize",
        "jwks_uri": "https://IDP_DOMAIN/.well-known/jwks.json",
        "token_endpoint": "https://IDP_DOMAIN/token/refresh",
        "code_challenge_methods_supported": ["plain", "S256"]
      }
    }
  }'`;

IDプロバイダーに[OpenID Connect](/docs/ja-JP/ja-jp/authenticate/identity-providers/enterprise-identity-providers/oidc)または[Okta Workforce](/docs/ja-JP/ja-jp/authenticate/identity-providers/enterprise-identity-providers/okta)を使用しているエンタープライズ接続では、Proof Key for Code Exchange（PKCE）や、属性・トークンのマッピングをサポートできます。

<div id="configure-pkce-for-oidc-connections">
  ## OIDC接続のPKCEを構成する
</div>

<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/ja-JP/ja-jp/glossary?term=openid" tip="OpenID: アプリケーションがログイン情報を収集および保存することなくにユーザーのIDを検証できるようにする認証用のオープン標準。" cta="用語集の表示">OpenID</Tooltip> Connect・Okta Workforce接続は、自動的にPKCEをサポートするよう構成されます。

OIDCのIDプロバイダー（<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-2" href="/docs/ja-JP/ja-jp/glossary?term=idp" tip="IDプロバイダー（IdP）: デジタルIDを保存および管理するサービス。" cta="用語集の表示">IdP</Tooltip>）がOIDC Discoveryメタデータを介してPKCEをサポートしている場合、Auth0のデフォルト設定では、使用可能なアルゴリズムのうち最強のものが使用されます。OIDC Discoveryメタデータの詳細については、[OpenIDのドキュメント](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata)をご確認ください。

<div id="view-pkce-configuration-for-a-connection">
  ### 接続のPKCE構成を表示する
</div>

<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/ja-JP/ja-jp/glossary?term=auth0-dashboard" tip="Auth0 Dashboard: サービスを構成するためのAuth0の主製品。" cta="用語集の表示">Auth0 Dashboard</Tooltip>では、特定の接続のPKCE構成を表示できます。

1. **［Authentication（認証）］>［Enterprise（エンタープライズ）］** に移動して、OIDCプロバイダー（OpenID ConnectまたはOkta Workforce）を選択します。
2. **［設定］** タブを選択します。
3. **［General（一般）］** セクションで、\*\* ［Connection Profile（接続プロファイル）］\*\* フィールドを見つけてください。

<Tabs>
  <Tab title="Auth0 Dashboard">
    Auth0 Dashboardでは、接続のPKCE構成を管理できます。

    1. [**［Dashboard］ > ［Authenticate（認証）］ > ［Enterprise（エンタープライズ）］** ](https://manage.auth0.com/#/connections/enterprise) に移動して、OIDCプロバイダー（OpenID ConnectまたはOkta Workforce）を選択します。
    2. **［Settings（設定）］** タブを選択して、\*\* ［Connection Profile（接続プロファイル）］\*\* フィールドを見つけてください。
    3. `PKCE`プロパティを、下のリストにある[サポート値](#supported-pkce-configuration-values)の一つに設定します。
    4. **［Save（保存）］** を選択します。
  </Tab>

  <Tab title="Management API">
    #### ディスカバリーエンドポイントの使用

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

    #### ディスカバリーエンドポイントなし

    `discovery_url` がない場合、必要なフィールドで`oidc_metadata`オブジェクトを手動で入力する必要があります。

    <AuthCodeBlock children={codeExample2} language="bash" />
  </Tab>
</Tabs>

<div id="supported-pkce-configuration-values">
  ### 対応されているPKCEの構成値
</div>

Auth0では、PKCEの構成に以下の値を使用できます。

<table class="table">
  <thead>
    <tr>
      <th>値</th>
      <th>説明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`auto`</td>
      <td>デフォルト値。最も強力なアルゴリズムを使用します。</td>
    </tr>

    <tr>
      <td>`s256`</td>
      <td>SHA-256アルゴリズムを使用します。Auth0は現在、RS512トークンをサポートしていません。</td>
    </tr>

    <tr>
      <td>`plain`</td>
      <td><a href="https://www.rfc-editor.org/rfc/rfc7636#section-4.2" title="Proof Key for Code Exchange by OAuth Public Clients - Code Challenge">PKCE仕様</a>で説明されたプレーンテキストを使用します。</td>
    </tr>

    <tr>
      <td>`disabled`</td>
      <td>PKCEに対するサポートを無効にします。</td>
    </tr>
  </tbody>
</table>

<Warning>
  `pkce`プロパティを`auto`以外の値に設定すると、選択した値がIDプロバイダーでサポートされていない場合には、接続が正常に動作しないことがあります。

  認証問題のトラブルシューティング以外の目的で、プロパティを`disabled`に設定しないでください。
</Warning>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  **Entra IDでの制限**

  Entra IDにOpenID Connect接続を使用している場合は、接続のメタデータが使用されているハッシュアルゴリズムを公開しないため、`pkce`を`s256`に設定する必要があります。現在、[Entra ID Enterprise接続](/docs/ja-JP/ja-jp/authenticate/identity-providers/enterprise-identity-providers/azure-active-directory/v2)はPKCEに対応していません。
</Callout>

<div id="map-claims-for-oidc-connections">
  ## OIDC接続のクレームをマッピングする
</div>

OpenID ConnectとOkta Workforce接続は、IDプロバイダー（IdP）から受け取ったクレームを自動的にマッピングできます。このマッピングは、Auth0提供のライブラリーテンプレートで、または、独自のテンプレートを直接入力することで構成できます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  マッピングされたクレームは、自動的にAuth0のIDトークンに追加されるわけではありません。クレームをIDトークンに追加するには、「[カスタムクレームを作成する](/docs/ja-JP/ja-jp/secure/tokens/json-web-tokens/create-custom-claims#create-custom-claims)」を参照してください。
</Callout>

<div id="mapping-template-properties">
  ### マッピングテンプレートのプロパティ
</div>

マッピングテンプレートは、以下のリストにある`options.attribute_map`オブジェクトプロパティをサポートしています。テンプレートは、有効なキー・値のペアを持つJSON形式でなくてはなりません。

<table class="table">
  <thead>
    <tr>
      <th><strong>プロパティ</strong></th>
      <th><strong>必須？</strong></th>
      <th><strong>説明</strong></th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`mapping_mode`</td>
      <td>必須</td>
      <td>受信クレームをマッピングするために使用される方法。</td>
    </tr>

    <tr>
      <td>`userinfo_scope`</td>
      <td>任意</td>
      <td>IdPのユーザー情報エンドポイントに送信するためのスコープ。</td>
    </tr>

    <tr>
      <td>`attributes`</td>
      <td>必須</td>
      <td>受信クレームのマッピング詳細が含まれるオブジェクト。</td>
    </tr>
  </tbody>
</table>

<div id="mapping-mode">
  ### モードのマッピング
</div>

`mapping_mode`プロパティは、IdPから受け取るクレームをどのような方法でAuth0のユーザープロファイルにマッピングするかを定義します。`mapping_mode`には、以下の値を使用できます。

<table class="table">
  <thead>
    <tr>
      <th><strong>値</strong></th>
      <th><strong>説明</strong></th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`use_map`</td>
      <td>提供されたテンプレートを使用してデータをマッピングする。</td>
    </tr>

    <tr>
      <td>`bind_all`</td>
      <td>IdPが提供したすべてのデータ要素をコピーする。</td>
    </tr>
  </tbody>
</table>

<div id="restricted-claims">
  #### 予約済みのクレーム
</div>

一部のクレームは、Auth0用に予約されているため、ユーザープロファイルの属性キーとして使うことはできません。

`mapping_mode`プロパティを`bind_all`に設定すると、IdPが値を予約済みのクレームにマッピングしようとする場合があります。その接続でのユーザー認証が妨げられることはありませんが、予約済みクレームに関連付けられた値は、Auth0のユーザープロファイルに**マッピングされません** 。

`mapping_mode`を`use_map`に設定すれば、受け取る予約済みクレームを有効なクレームにマッピングできます。

```lines theme={null}
"attribute_map": {
        "mapping_mode": "use_map",
        "attributes": {
            "amr": "{context.tokenset.amr}" // `amr` is a restricted claim and will not be mapped
            "federated_amr": "{context.tokenset.amr}" // `federated_amr` is not a restricted claim and will be mapped
        }
    }
```

予約済みクレームの完全なリストについては、「[カスタムクレームを作成する](/docs/ja-JP/ja-jp/secure/tokens/json-web-tokens/create-custom-claims)」をご確認ください。

<div id="userinfo-scope">
  ### UserInfoのスコープ
</div>

`userinfo_scope`プロパティは、要求時にAuth0がIdPへ送信するUserInfoエンドポイントのスコープを定義します。

たとえば、UserInfoエンドポイントの要求時に標準のOIDCスコープと`groups`スコープを送信したい場合には、次のようにします。

```lines theme={null}
"attribute_map": {
    . . .
    "mapping_mode": "bind_all",
    "userinfo_scope": "openid email profile groups",
    . . .
}
```

<div id="attributes">
  ### Attributes（属性）
</div>

`attributes`プロパティは、マッピング情報を含むオブジェクトです。この情報に基づいてAuth0がIdPからのクレームを解釈します。マッピング情報は、キー・値のペアとして入力しなければなりません。

左側のキーは、Auth0のユーザープロファイル属性に対応します。右側の値は、IdPからのクレームで、リテラル値、動的なコンテキストオブジェクト、またはその組み合わせとして表されます。動的コンテキストオブジェクトは、おなじみの`${variable}`形式で作成されたテンプレート式です。

```lines theme={null}
"attribute_map": {
    . . .
    "attributes": {
        "name": "${context.tokenset.name}",
        "email": "${context.tokenset.email}",
        "username": "${context.tokenset.preferred_username}"
    }
}
```

<div id="literal-values">
  #### リテラル値
</div>

リテラル値とは、接続の全ユーザーに対して特定のプロファイル属性にマッピングされる静的な値です。

たとえば、SalesForceのOIDC接続を構成していて、すべてのユーザープロファイルに同じSFDC Community IDを割り当てたい場合は、次のようにします。

```lines theme={null}
"attribute_map": {
    . . .
    "attributes": {
        …
        "sf_community_id": "3423409219032-32"
    }
}
```

<div id="context-object">
  #### コンテキストオブジェクト
</div>

ユーザープロファイル属性に動的な値をマッピングするには、`context`オブジェクトを使用します。全プロファイルで静的なリテラル値とは対照的に、個々のプロファイルに一意の値が保管できるようになります。

`context`オブジェクトは以下のプロパティをサポートしています。

<table class="table">
  <thead>
    <tr>
      <th>プロパティ</th>
      <th>説明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`context.connection`</td>
      <td>含まれるプロパティ：<br /><br /><li> `id`：接続の一意の識別子（`con_4423423423432423`など）。</li><br /><li>`strategy`：接続戦略（`oidc`など）。</li></td>
    </tr>

    <tr>
      <td>`context.tokenset`</td>
      <td>含まれるプロパティ：<br /><br /><li>`access_token`：IdPによって送信される検証済みアクセストークン全体。</li><br /><li>`&lt;claim name&gt;`：IdPによって送信される任意のIDトークン。</li></td>
    </tr>

    <tr>
      <td>`context.userinfo`</td>
      <td>含まれるプロパティ：<br /><br /><li>`&lt;claim name&gt;`：IdPのUserInfoエンドポイントによって提供される任意の使用可能なクレーム。</li></td>
    </tr>
  </tbody>
</table>

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

<div id="simple-user-claim-mapping">
  #### シンプルなユーザークレームマッピング
</div>

この例では、IDトークンからのデータを使用して一般的なユーザークレームをAuth0のユーザープロファイルにマッピングしています。

```lines theme={null}
"attribute_map": {
    . . .
    "attributes": {
        "name": "${context.tokenset.name}",
        "email": "${context.tokenset.email}",
        "username": "${context.tokenset.preferred_username}"
    }
}
```

<div id="group-claim-mapping">
  #### グループクレームマッピング
</div>

この例では、受信IdPからグループをAuth0のユーザープロファイルにマッピングしています。

```lines theme={null}
"attribute_map": {
    . . .
    "attributes": {
        "federated_groups": "${context.userinfo.groups}",
        "federated_locale": "${context.userinfo.locale}",
        "federated_zoneinfo": "${context.userinfo.zoneinfo}"
    }
}
```

<div id="combining-literal-values-and-context-objects">
  #### リテラル値とコンテキストオブジェクトの組み合わせ
</div>

この例では、リテラル値と動的テンプレート式を組み合わせて、複雑な値をAuth0のユーザープロファイル属性にマッピングしています。

```lines theme={null}
"attribute_map":{
    . . .
    "attributes": {
        "alt_id": "user_email|${context.tokenset.email}",
        . . .
    }
}
```
