We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35964
    • 5 Posts
    Forgive me if I’m making an obvious error here, but all of my searching has come up empty.

    We are in a slow process of migrating the college website from Evolution to Revolution and have hit a snag in regards to LDAP authentication. All of the documentation that I can find for Revo in regards to LDAP and/or Login has to do with going into the Manager. What we want to do instead is secure certain areas of the website with a LDAP login.

    We currently have an entire tool set of web applications outside of Modx that we secure using LDAP, but occasionally we also need to secure certain pages hosted within our Modx site. To do this with Evolution we just created a snippet to include a copy of our external LDAP login script and added the following code to the script to access the Modx SESSION:

    require('/path/to/modx/manager/includes/config.inc.php');
    startCMSSession();


    It would seem that startCMSSession() no longer exists in Revolution. Is this correct? If so, is there another way to access the Modx session from an external PHP script? And am I correct in assuming that the Login add-on and the LDAP that documentation states is supported by Revolution is actually meant for Manager access and not securing other parts of a website hosted with Modx?

    Thanks in advance for any assistance provided. We are a bit stuck here with this.
      • 28215
      • 4,149 Posts
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 35964
        • 5 Posts
        Thanks for that, but there must be something else that I need to do. When I added that code to my external script I now get an error in the Apache error_log:
        PHP Fatal error:  Call to a member function get() on a non-object in /path/to/modx/core/components/wayfinder/wayfinder.class.php on line 40, referer: https://www.example.com/path-to/external-ldap.php


        I suppose it wasn’t as simple as copy & pasting the linked to code and modifying the paths. Not clear on why it’s throwing an error on the wayfinder - do I need to pass on the id of the ModX page that is calling my external script some how? Let me know if I need to provide any further information.
          • 28215
          • 4,149 Posts
          Yes, can you explain further on what your script does, and why it’s calling Wayfinder?
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 3749
            • 24,544 Posts
            I’m guessing somewhat, but the line that’s troubling you in Wayfinder is this one:

             'id' => $this->modx->resource->get('id'),


            This is a reference to the current page being viewed by the user in the front end. It’s set by MODX on every page request, but since you’re outside of MODX, it’s not set.

            Once you’ve initialized MODX, you might be able to pick a page (say, the page with an ID of 12) and set $modx->resource before the Wayfinder call with something like this:

            $modx->resource = $modx->getObject('modResource', 12);

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 35964
              • 5 Posts
              @splittingred

              Basically the way our php login scripts work is we include a script (call it scriptA) at the beginning of a page we want secured. scriptA checks to see if the SESSION vars are already set that would indicate that you are already logged in. If they are not set, it redirects the browser to our LDAP login page (call it scriptB), where those SESSION vars get set upon successful login and the browser redirects back to the original page.

              For Modx, we have a snippet setup with a TV that includes scriptA. With Evolution all we had to add to scriptA was a call to startCMSSession() so that we could share SESSION vars with Modx. startCMSSession() seems to be gone now in Revolution.

              @BobRay

              How would I dynamically get the id of the Modx page? The $_SERVER[’QUERY_STRING’] var looks like q=alias.html. But what you say makes sense. Since I am stealing away from Modx to handle the LDAP login and then wanting to redirect back to the Modx page after login, it makes sense that I would need the id although in Evolution the q=alias.html always worked to redirect.

              Thanks for your help both of you! If there is a better way to be doing this I’m all ears!
                • 3749
                • 24,544 Posts
                Is Wayfinder called from either script A or B, or is it just on the page you’re forwarding back to?

                It seems to me that the best solution would be to convert the LDAP page to a MODX page (if that’s possible), with the code in a snippet . Then you don’t have to leave MODX at all.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 35964
                  • 5 Posts
                  Wayfinder is not called in either scriptA or scriptB, just the Modx page that we are forwarding back to. We have never considered putting the whole of the ldap login system into Modx. Not entirely sure why we haven’t, but an intriguing thought. I will give it a try and see what I can make of it.

                  Thank you for the suggestion.
                    • 3749
                    • 24,544 Posts
                    Are you forwarding back to the page in some unusual way? Normally, $ modx-> resource would be set and Wayfinder would have no problem.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 35964
                      • 5 Posts
                      Just to let you know, I’ve finally got it working! A bit of a hybrid solution I suppose.

                      I was running into a frustrating wall of Modx holding onto an old version of an external snippet. Not really sure what was happening there, clearing the site cache didn’t help - once I made a change to the TV and saved, it seemed to fix itself. We are chalking that up to the fact that my boss (who works with Modx more than I) was watching over my shoulder.

                      I was not able to get my login form working any better within Modx, but I’m not certain if there was something else going on.

                      scriptA is a snippet being called from a TV included in the head of the template. scriptB is the login form, external to Modx but including the code that was linked earlier gets Modx to remember the SESSION vars I set there. I was struggling with getting it to forward back to the proper Modx page, but I was using the path wrong. Redirecting to index.php?q=alias.html does work as long as the path in front of index.php is to the correct Modx installation path.

                      Thanks for all of your help both of you!