> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/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 [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 = `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/authenticate/identity-providers/enterprise-identity-providers/oidc)または[Okta Workforce](/docs/ja-jp/authenticate/identity-providers/enterprise-identity-providers/okta)を使用しているエンタープライズ接続では、Proof Key for Code Exchange（PKCE）や、属性・トークンのマッピングをサポートできます。

## OIDC接続のPKCEを構成する

<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/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/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)をご確認ください。

### 接続のPKCE構成を表示する

<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/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>

### 対応されているPKCEの構成値

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

| 値          | 説明                                                                                |
| ---------- | --------------------------------------------------------------------------------- |
| `auto`     | デフォルト値。最も強力なアルゴリズムを使用します。                                                         |
| `s256`     | SHA-256アルゴリズムを使用します。Auth0は現在、RS512トークンをサポートしていません。                                |
| `plain`    | [PKCE仕様](https://www.rfc-editor.org/rfc/rfc7636#section-4.2)で説明されたプレーンテキストを使用します。 |
| `disabled` | PKCEに対するサポートを無効にします。                                                              |

<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/authenticate/identity-providers/enterprise-identity-providers/azure-active-directory/v2)はPKCEに対応していません。
</Callout>

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

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

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

### マッピングテンプレートのプロパティ

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

| プロパティ            | 必須？ | 説明                                                        |
| ---------------- | --- | --------------------------------------------------------- |
| `mapping_mode`   | 必須  | 受信クレームをマッピングするために使用される方法。                                 |
| `userinfo_scope` | 任意  | 認可中にIdPにリクエストするスコープ。IdPのUserInfoエンドポイントから利用可能なクレームを決定します。 |
| `attributes`     | 必須  | 受信クレームのマッピング詳細が含まれるオブジェクト。                                |

### モードのマッピング

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

| 値          | 説明                           |
| ---------- | ---------------------------- |
| `use_map`  | 提供されたテンプレートを使用してデータをマッピングする。 |
| `bind_all` | IdPが提供したすべてのデータ要素をコピーする。     |

#### 予約済みのクレーム

一部のクレームは、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/secure/tokens/json-web-tokens/create-custom-claims)」をご確認ください。

### UserInfoのスコープ

`userinfo_scope`プロパティは、IdPへの認可リクエストに含まれる追加スコープを定義します。これらのスコープによって、IdPのUserInfoエンドポイントから利用可能なクレームが決まります。Auth0は、それらのスコープで付与されたアクセストークンを使用してUserInfoエンドポイントを呼び出します。

`userinfo_scope`は、`mapping_mode`が`use_map`に設定されている場合にのみ有効です。たとえば、認可リクエストに`groups`スコープを含めてUserInfoエンドポイントから取得し、Auth0ユーザープロファイルにマッピングする場合：

```lines theme={null}
"attribute_map": {
    . . .
    "mapping_mode": "use_map",
    "userinfo_scope": "openid email profile groups",
    "attributes": {
        "groups": "${context.userinfo.groups}"
    },
    . . .
}
```

### Attributes（属性）

`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}"
    }
}
```

#### リテラル値

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

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

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

#### コンテキストオブジェクト

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

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

| プロパティ                | 説明                                                                                                                                  |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `context.connection` | 含まれるプロパティ：<br /><br /><li> `id`：接続の一意の識別子（`con_4423423423432423`など）。</li><br /><li>`strategy`：接続戦略（`oidc`など）。</li>                  |
| `context.tokenset`   | 含まれるプロパティ：<br /><br /><li>`access_token`：IdPによって送信される検証済みアクセストークン全体。</li><br /><li>`&lt;claim name&gt;`：IdPによって送信される任意のIDトークン。</li> |
| `context.userinfo`   | 含まれるプロパティ：<br /><br /><li>`&lt;claim name&gt;`：IdPのUserInfoエンドポイントによって提供される任意の使用可能なクレーム。</li>                                       |

### 例

#### シンプルなユーザークレームマッピング

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

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

#### グループクレームマッピング

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

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

#### リテラル値とコンテキストオブジェクトの組み合わせ

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

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