We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35516
    • 9 Posts
    [edit] This turned out much longer than I first had in mind, so feel free to skip to the final fix part smiley [/edit]

    The following works on Vanilla 2.0.17.9 + ProxyConnect 1.9.3 combination, but I guess it will work on the whole 2.0.17.x line, hence the title.


    After reading sottwell’s little guide I was also amazed by the simpleness of the vanilla’s single sign-on integration with modx, but after failure at the first attempt I immediately got in the infamous "nothing in the life is easy/free, especially if it appears to be so at the first glance" kind of state.

    So I ventured once more on that many-times-traveled pilgrimage to knowledge which always lasts many moons just to prove myself for the umpteenth time that "the correct solution to the problem is always the simplest one" smiley



    Testing was done on the localhost but with virtual hosting setup in xampp which should emulate real server conditions.

    Two subdomains are set: one for modx the other for vanilla: http://modx.localhost.com and http://vanilla.localhost.com


    The original code was slightly changed:

    snippet:

    <?php
    if(isset($_SESSION['webInternalKey'])) {
    $output = "UniqueID=" . $_SESSION['webInternalKey'] . "\n";
    $output .= "Name=" . $_SESSION['webShortname'] . "\n";
    $output .= "Email=" . $_SESSION['webEmail'];
    return $output;
    }
    return;
    


    removed extra blank lines


    plugin:

    <?php
    $e = &$modx->Event;
    
    switch($e->name) {
        case 'OnWebLogout': // integrated logout
                setcookie('Vanilla', ' ', time() - 3600, '/', '.localhost.com');
                setcookie('Vanilla-Volatile', ' ', time() - 3600, '/', '.localhost.com');
                setcookie('VanillaProxy', ' ', time() - 3600, '/', '.localhost.com');
                unset($_COOKIE['Vanilla']);
                unset($_COOKIE['Vanilla-Volatile']);
                unset($_COOKIE['VanillaProxy']);
        break;
    }
    


    maybe at least that volatile cookie should be kept, don’t know..



    But after trying (almost) all possible combinations of vanilla versions from 2.0.3 - 2.0.17.10 and proxyconnect 1.6 - 1.9.3 I could not believe that all exhibited the same behavior:

    In spite everything was setup the correct way (and I’m also positive I won’t be clearing any more caches soon smiley ), the plugin kept creating user with the blank credentials and nothing more!


    Then after many trials and errors I ended up with the combination of the code & patches as follows, that according to the knowledge gathered should be bulletproof, but still nothing -
    (and at the end when reverting everything to default state the ONLY thing needed for my testbed was that FINAL FIX:), but I’ll share all just in case, since there are people that needed at least some of the things on their setups:



    path-to-vanilla/conf/config.php

    added (temporarily, removed at the end of the process):
    $Configuration['Garden']['Authenticator']['SyncScreen'] = TRUE;
    

    to stop blank user creation due to automatic login..



    /library/core/functions.general.php
    if (!$Success)
    return $Response;
    

    Change to:
    if ($Success)
    return $Response;
    

    to avoid vanilla bug that "eats" the first characters of the authentication resource data



    Patch /library/core/class.cookieidentity.php
    public static function GetCookiePayload($CookieName, $CookieHashMethod = NULL, $CookieSalt = NULL)
    {
       if (!self::CheckCookie($CookieName)) return FALSE;
    
          $Payload = explode('|', $_COOKIE[$CookieName]);
    
    +     array_shift($Payload);
    +     array_shift($Payload);
    +     array_shift($Payload);
    -      $Key = explode('-', $Payload[0]);
    -      $Expiration = array_pop($Key);
    -      $UserID = implode('-', $Key);
    -      
    -      $Payload = array($UserID, $Expiration);
    
          return $Payload;
    }
    

    to avoid bug that destroys the cookie content before login



    When configuring proxyconnect in vanilla select wordpress from the dropdown, wait, then select manual for java to kick in...

    Also domain setting ain’t sticking so add (change to appropriate) ".localhost.com" to Cookie Domain value in /conf/config.php
    (On some combinations authentication url, and even all setting weren’t beeing saved - but manually entering them in db showed nothing in the settings form fields, so beware!)


    - Noticed that 2.0.17.10 doesn’t like proxy 1.9.3, settings aren’t showing no metter what, and appears to be working with 1.8.4, but I choose to ditch it in favor of 1.9.3 which people are complaining less about smiley



    So after trying all of this and having read 99% of the stuff written about the issue (luckily the info was relatively "sparse") I concluded that because many are still reporting that nothing works beyond 2.0.16 (for me that lower versions were not working also:) I was just about to give up, and then..

    Then I finally checked that print cookie and noticed that vanilla is not reading the modx cookie - even though the manual for the plugin says that it should work for subdomains without a glitch!

    (Disclaimer: I know Susan Sayz that first thing to do is to check that frak^%@ cookie, but why take the easy route smiley )



    So after couple of head-banging days the solution came naturally:) - modx creates session cookie on the "base path", and to change that one needs to create the following variable in core system settings so here goes


    (finally:) THAT FINAL FIX: "session_cookie_domain" - set it to your root domain in the familiar format of ".localhost.com"


    Maybe that was not necessary for earlier versions and it worked "out of the box", but I only recently started with 2.0.8 and all tests were done on that so I wouldn’t know..



    Then proxyconnect will finally see the modx cookie, and bam: everything (?) is working!


    Bu not without:

    ..(possible) caveats:


    - if you don’t remove print_r($_COOKIE); from index.php when you try to e.g. enable plugin, theme, etc you will be greeted with the ingenious "fatal error: success" message..

    - empty user is still created - proxyconnection really likes to do that:) - if you encounter this just fill the name and mail for the blank user and switch "him" to banned, that should rectify it..

    in some cases:
    - login link don’t link back to modx - remedied by hard coding
    $Configuration['Garden']['SignIn']['Popup'] = FALSE;
    $Configuration['Garden']['Authenticator']['SignInUrl'] = enter your path ...
    


    - login works only when first attempt is done from modx side

    - ...add more here...


    I guess this covers all that matters on the troubleshooting front (I’m sure you experienced at least a thing or two), so maybe some will find it useful, and as the result won’t be breaking their computer peripherals, small furniture items, both at the same time:), etc...



    It would be great if more MODxers try this, I don’t like the fact that not everything is perfect (as someone said "it still feels wobbly"), which may lead to not so trivial problems in production environment cause maybe there are still things left to correct, but it looks like vanilla is a great companion to modx - at least till Discuss arrives in full glory smiley



    The most important 1% of the links read:

    http://rtfm.modx.com/display/revolution20/session_cookie_domain
    (this "bug" still exists http://modxcms.com/forums/index.php?topic=62299.0)
    http://modxcms.com/forums/index.php?topic=53538.0
    http://vanillaforums.org/docs/proxyconnect_sso
    http://vanillaforums.org/discussion/13698/patch-for-proxyconnect-problems
    http://vanillaforums.org/discussion/15492/manual-integration-on-2.0.17.-
      • 10638
      • 57 Posts
      Hi, thank you for doing this. I am really interested in using vanilla so will likely give this a shot over the coming weeks.
        • 11858
        • 130 Posts
        Thanks modesker, I’ve been waiting for the proxyconnect dev to correct some of these bugs for a while... Great tutorial.

        Looks like he has solved it with proxy connect 1.9.7 and vanilla 2.1.18b (important to have the beta) according to this http://vanillaforums.org/discussion/15492/manual-integration-on-2.0.17.- so while I haven’t tested it, maybe a lot of those last steps can be removed.
          • 5450
          • 3 Posts
          I followed your directions as indicated and I was still running into an issue.

          When new users are created on the modx side of the site, after authentication and everything and they go to use the forum, it doesn’t even recognize that they are already logged in.

          This was only applying to new users only.

          So what I did was go into the class.cookieidentity.php file and commented out the following lines

          protected function _ClearIdentity() {
          // Destroy the cookie.
          $this->UserID = 0;
          $this->_DeleteCookie($this->CookieName);
          }

          and I tried to run it but then I ran into a fatal error, presumably because this function was being called somewhere down the page. So I went back in and sure enough it was. so I also commented out these lines:

          if (!$this->_CheckCookie($this->CookieName)) {
          $this->_ClearIdentity();
          return 0;
          }

          Now everything works perfect!
            • 22019
            • 390 Posts
            I may be being naive, but running Vanilla 2.0.18b2 and ProxyConnect 1.9.7, with the plugin for logout as outlined above, and the Vanilla authenticator snippet from Susan (also above) it works without any further hacking.

            Just installed it all today, trying to emulate my previously working version on 2.0.16 and 1.8.4 (I think), which required at least one patch. It all works. Sometimes you have to go back and forth a few times to get everything you want into config.php (eg Force Remote URL in the EmbedVanilla plugin took a few attempts before the js fired to show the box...)

            My tips:
            1. The very first thing to do on the Vanilla side is to add this to config.php

            $Configuration['Garden']['Errors']['MasterView'] = 'deverror.master.php';
            

            To get rid of that fricking HUGELY annoying Bonk message that tells you nothing.

            2. Remember to delete your session /domain cookies before you start - preferably use a separate browser. Any time you have a problem, in fact, delete domain cookies.

            3. Make sure you have recursive 777 permissions set on your cache folder. I spent ages faffing around not realising my theme basically worked, it just couldn’t cache itself.

            It’s a really frustrating experience, because Vanilla itself is beautiful to use - they just really struggle to support the open source side of things, and the few devs that are in there are either complete propellerheads or won’t/can’t share.

              Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
              • 28042 ☆ A M B ☆
              • 24,524 Posts
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org