• Resolved tsykes

    (@tsykes)


    Hi there,

    I’m trying to set up SSO with a custom IdP. I can successfully hit the IdP and login to their system. But when I’m redirected back to my site I’m still not logged in (and no user is created for me if it’s a new user).

    In my themes functions.php I’ve added the following filter (removed site/certificate information). Any ideas?.. Thanks!

    function wpsax_filter_option($value, $option_name) {
    	$spBaseUrl = 'https://my-site-url';
        $defaults = array(
            /**
             * Type of SAML connection bridge to use.
             *
             * 'internal' uses OneLogin bundled library; 'simplesamlphp' uses SimpleSAMLphp.
             *
             * Defaults to SimpleSAMLphp for backwards compatibility.
             *
             * @param string
             */
    		'connection_type' => 'internal',
    		
            /**
             * Configuration options for OneLogin library use.
             *
             * @param array
             */
            'internal_config'        => array (
    			'sp' => array (
    				'entityId' => $spBaseUrl,
    				'assertionConsumerService' => array(
    					'url' => $spBaseUrl . '/wp-login',
    				),
    				'singleLogoutService' => array(
    					'url' => $spBaseUrl . '/?sls',
    				),
    				'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:assertion:cloudemailaddress',		                   
    			),
    				'idp' => array (
    				'entityId' => 'ofis:xxx:broker:s',
    				'singleSignOnService' => array (
    					'url' => 'https://my-ipd/',
    				),
    				'singleLogoutService' => array (
    					'url' => 'https://my-ipd/SignOut.aspx',
    				),
    				'x509cert' => '*removed*',
    			),
    		),
            /**
             * Path to SimpleSAMLphp autoloader.
             *
             * Follow the standard implementation by installing SimpleSAMLphp
             * alongside the plugin, and provide the path to its autoloader.
             * Alternatively, this plugin will work if it can find the
             * <code>SimpleSAML_Auth_Simple</code> class.
             *
             * @param string
             */
            'simplesamlphp_autoload' => dirname( __FILE__ ) . '/simplesamlphp/lib/_autoload.php',
            /**
             * Authentication source to pass to SimpleSAMLphp
             *
             * This must be one of your configured identity providers in
             * SimpleSAMLphp. If the identity provider isn't configured
             * properly, the plugin will not work properly.
             *
             * @param string
             */
            'auth_source'            => 'default-sp',
            /**
             * Whether or not to automatically provision new WordPress users.
             *
             * When WordPress is presented with a SAML user without a
             * corresponding WordPress account, it can either create a new user
             * or display an error that the user needs to contact the site
             * administrator.
             *
             * @param bool
             */
            'auto_provision'         => true,
            /**
             * Whether or not to permit logging in with username and password.
             *
             * If this feature is disabled, all authentication requests will be
             * channeled through SimpleSAMLphp.
             *
             * @param bool
             */
            'permit_wp_login'        => false,
            /**
             * Attribute by which to get a WordPress user for a SAML user.
             *
             * @param string Supported options are 'email' and 'login'.
             */
            'get_user_by'            => 'cloudemailaddress',
            /**
             * SAML attribute which includes the user_login value for a user.
             *
             * @param string
             */
            'user_login_attribute'   => 'cloudemailaddress',
            /**
             * SAML attribute which includes the user_email value for a user.
             *
             * @param string
             */
            'user_email_attribute'   => 'cloudemailaddress',
            /**
             * SAML attribute which includes the display_name value for a user.
             *
             * @param string
             */
            'display_name_attribute' => 'name',
            /**
             * SAML attribute which includes the first_name value for a user.
             *
             * @param string
             */
            'first_name_attribute' => 'givenname',
            /**
             * SAML attribute which includes the last_name value for a user.
             *
             * @param string
             */
            'last_name_attribute' => 'surname',
            /**
             * Default WordPress role to grant when provisioning new users.
             *
             * @param string
             */
            'default_role'           => get_option( 'default_role' ),
        );
        $value = isset( $defaults[ $option_name ] ) ? $defaults[ $option_name ] : $value;
        return $value;
    }
    add_filter( 'wp_saml_auth_option', 'wpsax_filter_option', 10, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tsykes

    (@tsykes)

    Stripped down version of the idp response if it helps:

    <?xml version="1.0" encoding="UTF-8"?>
    <samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_61e6f0c2-f96e-49a7-96b8-80cb4000001" InResponseTo="ONELOGIN_0f6b2a83dfc0727b5c335008e82097d" Version="2.0" IssueInstant="2018-09-20T11:22:47.097Z" Destination="https://mywebsite.com/wp-login">
       <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">ofis:company:broker:s</saml:Issuer>
       <Signature xmlns="https://www.w3.org/2000/09/xmldsig#">
          <SignedInfo>
             <CanonicalizationMethod Algorithm="https://www.w3.org/2001/10/xml-exc-c14n#" />
             <SignatureMethod Algorithm="https://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
             <Reference URI="#_61e6f0c2-f96e-49a7-96b8-80cb40443631">
                <Transforms>
                   <Transform Algorithm="https://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                   <Transform Algorithm="https://www.w3.org/2001/10/xml-exc-c14n#">
                      <InclusiveNamespaces xmlns="https://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="#default samlp saml ds xs xsi" />
                   </Transform>
                </Transforms>
                <DigestMethod Algorithm="https://www.w3.org/2001/04/xmlenc#sha256" />
                <DigestValue>myDigestValue=</DigestValue>
             </Reference>
          </SignedInfo>
          <SignatureValue>mysignature</SignatureValue>
          <KeyInfo>
             <X509Data>
                <X509Certificate>mycertificate</X509Certificate>
             </X509Data>
          </KeyInfo>
       </Signature>
       <samlp:Status>
          <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
       </samlp:Status>
       <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="_0fb59bea-d901-4210-a1b1-6d60af2b54b9" IssueInstant="2018-09-20T11:22:47.097Z">
          <saml:Issuer>ofis:company:broker:s</saml:Issuer>
          <saml:Subject>
             <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">[email protected]</saml:NameID>
             <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
                <saml:SubjectConfirmationData NotOnOrAfter="2018-09-20T12:22:47.097Z" Recipient="https://mywebsite.com/wp-login" InResponseTo="ONELOGIN_0f6b2a8baac46e553dfc0727b5c335008e82097d" />
             </saml:SubjectConfirmation>
          </saml:Subject>
          <saml:Conditions NotBefore="2018-09-20T10:22:47.097Z" NotOnOrAfter="2018-09-20T12:22:47.097Z">
             <saml:AudienceRestriction>
                <saml:Audience>https://mywebsite.com</saml:Audience>
             </saml:AudienceRestriction>
          </saml:Conditions>
          <saml:AuthnStatement AuthnInstant="2018-09-20T11:22:47.097Z" SessionIndex="_0fb59bea-d901-4210-a1b1-6d60af2b54b9">
             <saml:AuthnContext>
                <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml:AuthnContextClassRef>
             </saml:AuthnContext>
          </saml:AuthnStatement>
          <saml:AttributeStatement>
             <saml:Attribute Name="https://schemas.company.com/identity/claims/authlevel">
                <saml:AttributeValue>CERT</saml:AttributeValue>
             </saml:Attribute>
             <saml:Attribute Name="https://schemas.company.com/identity/claims/cloudemailaddress">
                <saml:AttributeValue>[email protected]</saml:AttributeValue>
             </saml:Attribute>
             <saml:Attribute Name="https://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname">
                <saml:AttributeValue>John</saml:AttributeValue>
             </saml:Attribute>
             <saml:Attribute Name="https://schemas.xmlsoap.org/ws/2005/05/identity/claims/name">
                <saml:AttributeValue>John Doe</saml:AttributeValue>
             </saml:Attribute>
             <saml:Attribute Name="https://schemas.company.com/identity/claims/companyusertype">
                <saml:AttributeValue>Internal</saml:AttributeValue>
             </saml:Attribute>
             <saml:Attribute Name="https://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname">
                <saml:AttributeValue>Doe</saml:AttributeValue>
             </saml:Attribute>
             <saml:Attribute Name="https://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier">
                <saml:AttributeValue>[email protected]</saml:AttributeValue>
             </saml:Attribute>
          </saml:AttributeStatement>
       </saml:Assertion>
    </samlp:Response>
    Thread Starter tsykes

    (@tsykes)

    Solution:

    First the redirect wasn’t going to:

    ‘assertionConsumerService’ => array(
    ‘url’ => $spBaseUrl . ‘/wp-login.php?action=wp-saml-auth’,
    ),

    Without the query param it didn’t look like the plugin was starting up..

    and the otherside was the IdP response. It threw us off that the IdP was returning keys as urls.

    I.e. <saml:Attribute Name=”https://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname”&gt;
    <saml:AttributeValue>John</saml:AttributeValue>
    </saml:Attribute>

    But replacing the login attributes with:
    ‘user_email_attribute’ => ‘https://schemas.company.com/identity/claims/cloudemailaddress&#8217;,

    was actually correct.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Glad you figured it out!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘SSO connects me to the IdP, but doesn’t log me in WordPress when redirected back’ is closed to new replies.