1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

External login without password?

Discussion in 'XenForo Development Discussions' started by EricB, Nov 27, 2013.

  1. EricB

    EricB New Member


    i want to integrate XenForo in an Intranet-Site with its own user-managemant. Now i´m able to create the user in Xenforo using it´s key from the intranet as external userid.

    But i have troubles to login the user in Xenforo. Till now i using this code an it doesn´t work. I think anything is missing... but what?

    $session = XenForo_Application::get('session');
    header("Location: forum/index.php");

    The user is allready authenticated in the portal and Xenforo doesn´t allow new user registrations. So no password is provided for the login in xenforo. It should only work with his user-id!

    Thank You
  2. EricB

    EricB New Member


    $session = XenForo_Application::get('session');
    header("Location: forum/index.php");
  3. thaihung38

    thaihung38 New Member

    Hi EricB.
    I'm currently making a project same as yours, but I don't know much about Xenforo. So could you give me the code to create, authenticate user and login from the Intranet-Site?
  4. EricB

    EricB New Member

    Hi, find below my code which is working for me. You have to do some auth-jobs in your script!

    Regards Eric

    define('XF_ROOT', '/www/docs/domain/forum'); // set this (absolute path)!
    define('TIMENOW', time());
    require_once(XF_ROOT . '/library/XenForo/Autoloader.php');

    XenForo_Autoloader::getInstance()->setupAutoloader(XF_ROOT . '/library');
    XenForo_Application::initialize(XF_ROOT . '/library', XF_ROOT);
    XenForo_Application::set('page_start_time', TIMENOW);
    $GpID = '19763';
    $visitor = XenForo_Visitor::getInstance();
    $userModel = XenForo_Model::create('XenForo_Model_User');
    $userExternalModel = XenForo_Model::create('XenForo_Model_UserExternal');
    $UserInfo = $userExternalModel->getExternalAuthAssociation('pnet', $GpID);
    if (!$UserInfo)
    $data = array(
    'username' => 'name to display',
    'email' => 'usermail@mail.com',
    'location' => 'home',
    'dob_day' => '22', // Date of Birthday
    'dob_month' => '09', // Month of Birthday
    'dob_year' => '1958',
    'timezone' => 'Europe/Amsterdam'
    $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
    $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
    $options = XenForo_Application::get('options');

    $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
    $writer->set('scheme_class', $auth->getClassName());
    $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
    $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
    $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
    $user = $writer->getMergedData();
    $UserID = $user['user_id'];

    $userExternalModel->updateExternalAuthAssociation('pnet', $GpID, $UserID);
    XenForo_Model_Ip::log($UserID, 'user', $UserID, 'register');

    } else {
    $UserID = $UserInfo['user_id'];
    $session = XenForo_Application::get('session');
    header("Location: index.php");
    thaihung38 likes this.
  5. thaihung38

    thaihung38 New Member

    Oh. Thanks thanks a lot Eric. I will try it now ....

Share This Page