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

Auth0がIdPである場合には、Auth0のSAML2アドオンを使ってユーザー属性をマッピングすることができます。属性の構成に誤りがあると、エラーが発生することがあります。たとえば、ユーザーがユーザー名とパスワードを正常に入力し、Auth0 Dashboardのログに正常なログインイベントが記録されていても、アプリケーションへのサインインが失敗します。または、アプリケーションに名前やメールなどのユーザー情報が見つからない結果になります。

ユースケース

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

//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"
   }
...
}

Was this helpful?

/

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

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

この例では、fav_genreuser_metadata.fav_streaming_serviceが未定義ですが、カスタマイズして、Auth0が送信するSAML応答にマッピングできます。

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

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

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

Was this helpful?

/

標準マッピングの例

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

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

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

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

"mappings": {
   "fav_genre": "http://schemas.auth0.com/books"
 }

Was this helpful?

/

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

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

Was this helpful?

/

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

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

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

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

"mappings": {
   "fav_genre": [
     "http://schemas.auth0.com/movies",
     "http://schemas.auth0.com/books",
     "http://schemas.auth0.com/television"
   ]
 }

Was this helpful?

/

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

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

Was this helpful?

/