I have an application hosted on a different server, and I want to authenticate using Magento instead of maintaining two separate user lists. I've already done this for applications on the same server using the common method:

Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session');

if($session->isLoggedIn()) {
    echo "logged in";
} else {
    echo "not logged in";

How do you do this without direct access to Mage.php? I've attempted setting up a helper script that uses the above code, and making an AJAX call to it, but it always returns "not logged in".

Has anyone else ran into this issue?


Your AJAX-Request won't submit your current Sessioncookie to the remote Domain. Even if it would be submitted the remote Shop won't be able to associate your Cookie to the account given.

This is an typical Cross-Domainproblem. You could use jpillora/xdomain, CORS or mudco to solve this.

  • I forgot to mention that the application on another server is a sub-domain of my Magento store. I've set the Magento cookie domain to ".domain.com" but still can't access it from the other site at "blah.domain.com". It always returns "not logged in". I'm looking into the options you gave but was hoping there'd be a simpler way – hambone Sep 18 '13 at 17:17

Please have a look at this link where the
Session cookie management field descriptions
are, this may help with what you are looking for, I have wrote a script myself however I am using mage.app unfortunately (but on another domain).


REVISION The code is located outside of magentos scope

require_once '../../app/Mage.php'; // location of mage
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session');           


switch($_REQUEST['action']) {
    case 'login':
        try {
            $login = $session->login($_POST['username'],$_POST['password']);

        catch(Exception $e) 
            echo $message = $e->getMessage();
            echo 'Click <a href="WERE YOU WANT TO LINK">HERE</a> To login';  
        header("Location: ");  //REDIRECTS IF SUCCESSFULL

    case "logout":
        header("Location: "); // REDIRECTS WHEN YOU LOGOUT 
        # Redirect or give a status message, etc

        # If the customer is not logged in, show a login form
        # If the customer is logged in, show a logout button
        if($session->isLoggedIn()){ ?> LOGGED IN CODE <?php } else { ?> NOT LOGGED IN <?php } ?>


<form method="POST" action="index.php">
            <label for="username" >Email</label><br />
                <input type="text" name="username" size="40" /><br /><br />
            <label for="password" >Password</label><br />
                <input type="password" name="password" size="40" />
            <input type="submit" name="submit" class="button-link" value="LOGIN" />
            <input type="hidden" name="action"  value="login" />

This is basically a self submitting form, mage app will check the user supplied info run the action and create a session. Let me know how you get on :)

  • Thanks. I've tried setting the cookies to ".domain.com" since the page is a sub-domain of my Magento shop, but still haven't been able to get a "logged in" response. How did you use Mage.app from another domain? That would solve my problem – hambone Sep 18 '13 at 17:03
  • Hi Hambone, Im not currently at work, Ill send the code over to you in the morning how I logged the sessions :) – Adam Kernig Sep 18 '13 at 22:24
  • Updated answer for you – Adam Kernig Sep 19 '13 at 9:13

We have implemented two solutions for the SSO with Magento 2

1 - With the Social Engine

2 - With the WordPress

you can have a look if any of them works for you. Following are the links of those extensions :

1) http://www.ipragmatech.com/products/magento-socialengine-sso/

2) http://www.ipragmatech.com/products/magento-wordpress-sso/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.