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

# SAML属性をIdP/SAMLアドオンとしてAuth0にマッピングする

> Auth0がIDプロバイダーの場合に、SAML属性をマッピングする方法について説明します。

Auth0が<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-2" href="/docs/ja-jp/glossary?term=idp" tip="IDプロバイダー（IdP）: デジタルIDを保存および管理するサービス。" cta="用語集の表示">IdP</Tooltip>である場合には、Auth0のSAML2アドオンを使ってユーザー属性をマッピングすることができます。属性の構成に誤りがあると、エラーが発生することがあります。たとえば、ユーザーがユーザー名とパスワードを正常に入力し、<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-0" href="/docs/ja-jp/glossary?term=auth0-dashboard" tip="Auth0 Dashboard: サービスを構成するためのAuth0の主製品。" cta="用語集の表示">Auth0 Dashboard</Tooltip>のログに正常なログインイベントが記録されていても、アプリケーションへのサインインが失敗します。または、アプリケーションに名前やメールなどのユーザー情報が見つからない結果になります。

## ユースケース

以下のユーザープロファイルは、これから説明するシナリオについての例です。

```javascript lines theme={null}
//SAMPLE IdP User Profile
{
   "created_at": "2021-06-21T13:26:08.579Z",
   "email": "testuser@example.com",
...
   "fav_genre": "fiction",
   "user_metadata": {
       "fav_streaming_service": "hulu"
   }
...
}
```

#### マッピングオブジェクトの欠如

SAML2アドオンの使用では、空のマッピングオブジェクトがデフォルトで生成されます。

この例では、`fav_genre`と`user_metadata.fav_streaming_service`が未定義ですが、カスタマイズして、Auth0が送信する<Tooltip data-tooltip-id="react-containers-DefinitionTooltip-1" href="/docs/ja-jp/glossary?term=security-assertion-markup-language" tip="Security Assertion Markup Language（SAML）: パスワードなしに二者間で認証情報を交換できる標準化プロトコル。" cta="用語集の表示">SAML</Tooltip>応答にマッピングできます。

以下の例では、`"fav_genre":"fiction"`がSAML応答の[http://schemas.auth0.com/fav\_genre](http://schemas.auth0.com/fav_food)属性に`fiction`値でマッピングされ、`"user_metadata":{"fav_streaming_service":"hulu"}`がSAMLレスポンスには一切なくなります。

そのため、IdPが送信するSAML応答は以下になります。

```xml lines theme={null}
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_e30cb5f29249a82846eb" InResponseTo="_e33996d83f953ce46225185b3a1c0ad8" Version="2.0" IssueInstant="2021-11-03T21:34:42.493Z" Destination="https://example-dev-tenant.us.auth0.com/login/callback">
...
       <saml:AttributeStatement xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <saml:Attribute Name="http://schemas.auth0.com/fav_genre" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
               <saml:AttributeValue xsi:type="xs:string">
                   fiction
               </saml:AttributeValue>
           </saml:Attribute>
...
       </saml:AttributeStatement>
   </saml:Assertion>
</samlp:Response>
```

#### 標準マッピングの例

上の例では、マッピングオブジェクトをカスタマイズしなかったため、SAML応答の[http://schemas.auth0.com/fav\_genre](http://schemas.auth0.com/fav_food)属性が`"fiction"`値となる結果になりました。

今回は、SAML2アドオン設定のマッピングオブジェクトで属性をマッピングして、これに対処します。

そうすると、SAML応答にある`"fiction"`値は前回と同様ですが、属性名がデフォルトの[http://schemas.auth0.com/fav\_fiction](http://schemas.auth0.com/fav_food)から[http://schemas.auth0.com/books](http://schemas.auth0.com/dinner)に変わっています。

SAML2アドオンのマッピングオブジェクトを以下のように構成します。

```json lines theme={null}
"mappings": {
   "fav_genre": "http://schemas.auth0.com/books"
 }
```

このマッピングでは、以下のような応答になります。

```xml lines theme={null}
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_e30cb5f29249a82846eb" InResponseTo="_e33996d83f953ce46225185b3a1c0ad8" Version="2.0" IssueInstant="2021-11-03T21:34:42.493Z" Destination="https://example-dev-tenant.us.auth0.com/login/callback">
...
       <saml:AttributeStatement xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <saml:Attribute Name="http://schemas.auth0.com/books" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
               <saml:AttributeValue xsi:type="xs:string">
                   fiction
               </saml:AttributeValue>
           </saml:Attribute>
...
       </saml:AttributeStatement>
   </saml:Assertion>
</samlp:Response>
```

#### 同じ値を複数の属性にマッピングする

SAML応答を複数の属性に同じ値でマッピングしなければならないシナリオがあるかもしれません。

そのような場合には、ユーザープロファイルからの同じ値をSAML応答にある複数の属性にマッピングすることができます。

SAML2アドオンのマッピングオブジェクトを以下のように構成します。

```json lines theme={null}
"mappings": {
   "fav_genre": [
     "http://schemas.auth0.com/movies",
     "http://schemas.auth0.com/books",
     "http://schemas.auth0.com/television"
   ]
 }
```

このマッピングでは、以下のような応答になります。

```xml lines theme={null}
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_e30cb5f29249a82846eb" InResponseTo="_e33996d83f953ce46225185b3a1c0ad8" Version="2.0" IssueInstant="2021-11-03T21:34:42.493Z" Destination="https://example-dev-tenant.us.auth0.com/login/callback">
...
       <saml:AttributeStatement xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <saml:Attribute Name="http://schemas.auth0.com/movies" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
               <saml:AttributeValue xsi:type="xs:string">
                   fiction
               </saml:AttributeValue>
           </saml:Attribute>
           <saml:Attribute Name="http://schemas.auth0.com/books" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
               <saml:AttributeValue xsi:type="xs:string">
                   fiction
               </saml:AttributeValue>
           </saml:Attribute>
           <saml:Attribute Name="http://schemas.auth0.com/television" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
               <saml:AttributeValue xsi:type="xs:string">
                   fiction
               </saml:AttributeValue>
           </saml:Attribute>
...
       </saml:AttributeStatement>
   </saml:Assertion>
</samlp:Response>
```
