# I dont get proper mapping of attributes using SAML plugin

**URL:** https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312
**Category:** SSO
**Tags:** saml
**Created:** [June 18, 2021, 2:36pm UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312 "2021-06-18T14:36:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![JoreisPy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joreispy/32/224708_2.png) [@JoreisPy](https://meta.discourse.org/u/JoreisPy)
#### Post date: [June 18, 2021, 2:36pm UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/1 "2021-06-18T14:36:01Z")

</div>

Hello,

I am trying to integrate our shibboleth with our discourse instance. For now logging in works but I am getting the wrong data (name, email, etc…)

here is part of the data coming from the SSO

```plaintext
    <saml2:Attribute FriendlyName="givenName" Name="urn:oid:2.5.4.42" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
      <saml2:AttributeValue>Joao Miguel</saml2:AttributeValue>

```

here is the error log:

```plaintext
SAML Debugging: saml_auth: {:uid=>"AAdzZWNyZXQ0uudwQFYHs1n7nrvB/A4t4l6q+6aAXInZRL4XIO+mnEEEq4t8UwBnzJRh50mnTGDsQAPvWThJNaUNR6smCochT1I2oXwvyoU4lQG+5hbVmCvkkmYDPOujrvgNloXWNg==", :info=>{"name"=>nil, "email"=>nil, "first_name"=>nil, "last_name"=>nil, "nickname"=>nil}....... @attributes={............."urn:oid:2.5.4.42"=>["Joao Miguel"]

```

I would say the issue has to do with the FriendlyName, as it doesnt match any of the options in saml\_authenticator.rb:

statements = “name:name|email:email,mail|first\_name:first\_name,firstname,firstName|last\_name:last\_name,lastname,lastName|nickname:screenName”

Since friendly name repeats itself for every atribute I am not sure how to make the mapping. Has anyone an idea of how to deal with this?

Thank you

---

<div class="post-metadata">

### Author: ![Ivan.bacher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan.bacher/32/139602_2.png) [@Ivan.bacher](https://meta.discourse.org/u/Ivan.bacher)
#### Post date: [October 19, 2022, 3:28pm UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/2 "2022-10-19T15:28:55Z")

</div>

Did you manage to get this working?

---

<div class="post-metadata">

### Author: ![bizotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bizotto/32/303257_2.png) [@bizotto](https://meta.discourse.org/u/bizotto)
#### Post date: [May 3, 2023, 10:38am UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/3 "2023-05-03T10:38:09Z")

</div>

Hello @Ivan.bacher and @JoreisPy , any success in mapping the right attributes via discourse-saml configs?

I’ve been trying using this config in the plug-in but no lucky so far:

 ![Screenshot 2023-05-03 at 08.27.45](https://global.discourse-cdn.com/meta/original/4X/c/f/1/cf153dfb4090159e9de3bd6240a0285d84b4dc43.png)

Have a good one! 🙂

---

<div class="post-metadata">

### Author: ![cgratie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cgratie/32/439227_2.png) [@cgratie](https://meta.discourse.org/u/cgratie)
#### Post date: [August 9, 2024, 3:33pm UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/4 "2024-08-09T15:33:01Z")

</div>

I stumbled across the same problem while testing the SAML integration and I finally managed to get it to work. With logs enabled, check the content of `@attributes`, those are the actual keys you need for the mapping and not the friendly name. They correspond to the `Name` attribute from the XML data. For my case the mapping inside `app.yml` became:

```plaintext
DISCOURSE_SAML_REQUEST_ATTRIBUTES: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
DISCOURSE_SAML_ATTRIBUTE_STATEMENTS: "email:http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"

```

It is also important to **rebuild** after changes to the config. After doing so, it properly mapped the email value from my SAML response.

---

<div class="post-metadata">

### Author: ![Dubravko\_Penezic](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dubravko_penezic/32/451922_2.png) [@Dubravko\_Penezic](https://meta.discourse.org/u/Dubravko_Penezic)
#### Post date: [September 26, 2024, 6:45am UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/5 "2024-09-26T06:45:14Z")

</div>

Thanks for sharing example, from [discourse-saml/config/locales/server.en.yml at main · discourse/discourse-saml · GitHub](https://github.com/discourse/discourse-saml/blob/main/config/locales/server.en.yml) isn’t clear what the exact format means.  
Additionally for future SAML plugin have possibility to map more than one attribute to Discourse variable, so the format basically tells:

> ‘\<Discourse\_variable\>:\<SAML\_attribute1\>,\<SAML\_attribute2\>’

---

<div class="post-metadata">

### Author: ![Dubravko\_Penezic](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dubravko_penezic/32/451922_2.png) [@Dubravko\_Penezic](https://meta.discourse.org/u/Dubravko_Penezic)
#### Post date: [September 29, 2024, 5:30pm UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/6 "2024-09-29T17:30:23Z")

</div>

Probably isnt good place but just to add, you will need **email** , **name** , **first\_name** , **last\_name** and **uid** like Dicourse attribute to be able to use SAML plugin.

---

<div class="post-metadata">

### Author: ![Dubravko\_Penezic](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dubravko_penezic/32/451922_2.png) [@Dubravko\_Penezic](https://meta.discourse.org/u/Dubravko_Penezic)
#### Post date: [September 29, 2024, 5:45pm UTC](https://meta.discourse.org/t/i-dont-get-proper-mapping-of-attributes-using-saml-plugin/194312/7 "2024-09-29T17:45:14Z")

</div>

Additionally

```plaintext
def attribute_statements
    result = {}
    statements =
      "name:fullName,name|email:email,mail|first_name:first_name,firstname,firstName|last_name:last_name,lastname,lastName|nickname:screenName"
    custom_statements = setting(:attribute_statements)

    statements = "#{statements}|#{custom_statements}" if custom_statements.present?

    statements
      .split("|")
      .map do |statement|
        attrs = statement.split(":", 2)
        next if attrs.count != 2
        (result[attrs[0]] ||= []) << attrs[1].split(",")
        result[attrs[0]].flatten!
      end

    result
  end

```

this part of the code (have in mind I am not a Ruby programmer) suggest that you need to map all attributes to your attributes that the system may work … I will try to test that information ( I do have issue at a moment with SAML plugin and try to investigate issues).
