dazamate
Member
Hi guys.
I am upgrading to Xenforo 2 and I need to be able to remotely log into XF2 from another subdomain
my login form is on form.mywebsite.com and xf2 is on forums.mywebsite.com
As suggested I am using the Auth rest API
When I pass the login credentials, I do get a success response back...
I imagine to have a persistent login, some auth cookies would need to be set. I did a cookie clear and the only cookie being set on the api request is this one...
I also tried logging in by directly interfacing with the xf classes based off some posts here.. Here is what I had (but didn't work)
However when I refresh the forums.mywebsite.com, it still has 'login' in the header.
To make sure cookies are readable between the subdomains, I put this in my xenforo/src/config.php file
I am very very new to the xenforo API. I just need to be able to login a user from one subdomain, so when the forum subdomain loads, the user is logged in ready to go.
Please help, thank you!
I am upgrading to Xenforo 2 and I need to be able to remotely log into XF2 from another subdomain
my login form is on form.mywebsite.com and xf2 is on forums.mywebsite.com
As suggested I am using the Auth rest API
When I pass the login credentials, I do get a success response back...
Code:
Array
(
[success] => 1
[user] => Array
(
[about] =>
[activity_visible] => 1
[alert_optout] => Array
(
)
[allow_post_profile] => members
[allow_receive_news_feed] => everyone
[allow_send_personal_conversation] => members
[allow_view_identities] => everyone
[allow_view_profile] => everyone
[avatar_urls] => Array
(...
I imagine to have a persistent login, some auth cookies would need to be set. I did a cookie clear and the only cookie being set on the api request is this one...
Code:
[__cfduid] => d17392b36af1...
I also tried logging in by directly interfacing with the xf classes based off some posts here.. Here is what I had (but didn't work)
PHP:
public function loginUser(string $login, string $password): bool {
// Check credentials
$ip = $this->_xf->request->getIp();
$loginService = $this->_xf->service('XF:User\Login', $login, $ip);
$error = '';
$xfUser = $loginService->validate($password, $error) ?? false;
// No user returned, credentials failed
if( empty($xfUser) ) { return false; }
// Log the user in
$this->_xf->session->changeUser($xfUser);
\XF::setVisitor($xfUser);
$class = \XF::app()->extendClass('XF\Session\Session');
/** @var \XF\Session\Session $session */
$session = new $class(\XF::app()->container('session.public.storage'), [
'cookie' => 'session'
]);
$session->start(\XF::app()->request());
$session->changeUser($xfUser);
$cookieVal = $session->getSessionId();
$rememberRepo = $this->_xf->repository('XF:UserRemember');
$key = $rememberRepo->createRememberRecord($xfUser->user_id);
$value = $rememberRepo->getCookieValue($xfUser->user_id, $key);
$session->save();
setcookie('xf_session', $cookieVal, time() + (365 * 86400), '/');
setcookie('xf_user', $value, time() + (365 * 86400), '/');
return true;
}
To make sure cookies are readable between the subdomains, I put this in my xenforo/src/config.php file
PHP:
$config['cookie']['prefix'] = 'xf_';
$config['cookie']['path'] = '/';
$config['cookie']['domain'] = '.mywebsite.com';
I am very very new to the xenforo API. I just need to be able to login a user from one subdomain, so when the forum subdomain loads, the user is logged in ready to go.
Please help, thank you!