SAML-Toolkits / wordpress-saml

OneLogin SAML plugin for Wordpress
MIT License
65 stars 74 forks source link

Can't get roles to sync #63

Closed adevapp closed 6 years ago

adevapp commented 6 years ago

I've followed the instructions here: https://support.onelogin.com/hc/en-us/articles/204353160-Configuring-SAML-for-WordPress

and: https://support.onelogin.com/hc/en-us/community/posts/115009793326-Mapping-Wordpress-Roles

However the roles do not sync across. I've applied the CN setting per Steve's post, and selected multiple roles (which there are).

Is there anything I have missed in the setup of role syncing with the free version of OneLogin?

pitbulk commented 6 years ago

Have you reviewed that the regex you added to the settings is correct?

Can you share your current settings and examples of the SAML Attributes?

adevapp commented 6 years ago

Create user if not exists TRUE Update user data TRUE Match Wordpress account by Username

Regular expression for multiple role values: /CN=([^,;]*)/

Mappings:

screen shot 2018-05-14 at 5 37 39 pm

Other: screen shot 2018-05-14 at 5 38 17 pm

pitbulk commented 6 years ago

What about the Attributes included on the SAMLResponse? (You can record SAMLResponse with SAML Tracer or Chrome SAML panel

adevapp commented 6 years ago

screen shot 2018-05-14 at 5 41 34 pm

I assuming you mean these mappings in OneLogin?

pitbulk commented 6 years ago

No, I need the SAMLResponse OneLogin is sending to Wordpress in order to verify that the expected "member of" attribute contains a value and verify if the regex matches that value.

adevapp commented 6 years ago

I assume I would put a var_dump($var) and then exit() somewhere in the plugin code - Then attempt the login to dump this info?

pitbulk commented 6 years ago

I suggested you to use plugins that you install on browsers (SAML Tracer or Chrome SAML Panel) that are able to record the SAMLResponse.

But you can edit the functions.php file of the SAML plugin and print the $_POST['SAMLResponse'] on the acs method.

adevapp commented 6 years ago

Response is: (Have changed name and email to xxx).

    <saml:Conditions NotBefore="2018-05-14T08:48:18Z" NotOnOrAfter="2018-05-14T08:54:18Z">
        <saml:AudienceRestriction>
            <saml:Audience>php-saml</saml:Audience>
        </saml:AudienceRestriction>
    </saml:Conditions>
    <saml:AuthnStatement AuthnInstant="2018-05-14T08:51:17Z"
        SessionIndex="xxx-3981-0136-790d-0a1b22056132" SessionNotOnOrAfter="2018-05-15T08:51:18Z">
        <saml:AuthnContext>
            <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
        </saml:AuthnContext>
    </saml:AuthnStatement>
    <saml:AttributeStatement>
        <saml:Attribute Name="memberOf" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">administrators</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="User.email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">xxx@xxx.com</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="User.FirstName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">xxx</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="User.LastName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">xxx</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="User.Username" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">xxx.xxx</saml:AttributeValue>
        </saml:Attribute>
    </saml:AttributeStatement>
</saml:Assertion>
pitbulk commented 6 years ago

As you can see in the SAMLResponse, OneLogin is right now providing as member of the value "administrators" so no regex is required at all.

So remove the regular expression value, uncheck the "Multiple role values in one saml attribute value.

adevapp commented 6 years ago

Thanks. Works now. I had to set the memberOf value using rules, so it updates when the role is set. Otherwise it comes out blank in the debug log, even though the role is active (the memberOf remains blank without the rule).