Full name mapping when using SAML

Hi there,

does anyone know how to map the full name when using SAML as login method?
My SAML response looks like this and I can map any other other attribute in my IdP if necessary:

<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" 
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Destination="https://logon.xyz.de/auth/saml/callback" ID="idLwrewprewewGG1wewe0X4VZKDDby1Htv8I" InResponseTo="_ade6fd8b-0ce0-48d0-afff-b0ad3375d8e6" IssueInstant="2018-10-18T08:05:37Z" Version="2.0">
    <saml:Issuer>https://logon.xyz.de/nidp/saml2/metadata</saml:Issuer>
    <samlp:Status>
        <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
    </samlp:Status>
    <saml:Assertion ID="id9sd5jjrejb3ererIZCJkrYjoG9_PI0" IssueInstant="2018-10-18T08:05:37Z" Version="2.0">

        ...

    <saml:AttributeStatement>
        <saml:Attribute xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xsi:type="xs:string">USERID</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="last_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xsi:type="xs:string">Surname</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="first_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xsi:type="xs:string">Givenname</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xsi:type="xs:string">mail@example.org</saml:AttributeValue>
        </saml:Attribute>
    </saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>

Regards,
Thilo

如果您还在寻找解决方案:

我们遇到了同样的问题,只在查看源代码时才找到了解决方案:

fullName 被忽略。
您必须在您的身份提供商(我们使用了 Keycloak)中为 discourse 设置 firstNamelastName 字段的映射。

2 个赞

感谢您花时间研究代码!在我看来,这似乎是一个错误——我们检查 fullName,然后用 firstName lastName 替换它。该代码片段中的第 133 行完全没用 :thinking:

无论如何,我本周一直在处理 SAML 插件,所以这是一个修复:

一旦合并,fullName 将被正确优先处理。

3 个赞

@david 感谢您快速修复!

这在我看来是个 bug——我们检查 fullName,然后用 firstName lastName 替换它。该代码片段的第 133 行完全没用。

我也有同样的看法,但我不确定,因为我不熟悉 Ruby 语法……

2 个赞