Tom*_*Tom 6 php authentication mobile joomla2.5
编辑最初我认为Oauth2是要走的路,但也许不是.我现在就把它从这个问题中解脱出来,因为它让人感到困惑.
我正在创建一个移动应用程序(Android/iOS).我希望用户在移动设备中输入他们的凭据(用户/通行证),然后将其发送到我的服务器(Joomla CMS)以验证凭据并创建/发送令牌.我不想仅仅在令牌上存储用户/传递.
此外,此令牌需要在需要时刷新超时.凭证等已经改变.
在这一点上,我试图弄清楚它的架构会是什么样子.
有没有关于如何实现这一目标的教程(理想情况下是使用Joomla)?有人可以指点我的吗?
最终的解决方案是创建我自己的 Joomla 组件。几乎所有东西都在我的控制器中。不是最终的代码,但类似的代码可以工作。
defined('_JEXEC') or die;
jimport('joomla.application.component.controller');
class FooauthController extends JController
{
function __construct() {
// params
$jinput = JFactory::getApplication()->input;
$this->username = $jinput->get('user', '', 'STRING');
$this->password = $jinput->get('password', '', 'STRING');
$this->checkParameters();
}
private function checkParameters() {
// datatype checks
if ($this->username == '' || $this->password == '') {
header('HTTP/1.1 400 Bad Request', true, 400);
}
}
private function createToken() {
// token generation - what Joomla does (just an example)
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword($password, $salt);
$cpassword = $crypted.':'.$salt;
return $cpassword;
}
function execute() {
// Get the global JAuthentication object
jimport( 'joomla.user.authentication');
$auth = & JAuthentication::getInstance();
$credentials = array( 'username' => $this->username, 'password' => $this->password );
$options = array();
$response = $auth->authenticate($credentials, $options);
// success
if ($response->status === JAUTHENTICATE_STATUS_SUCCESS) {
$response->status = true;
echo json_encode($this->createToken());
} else {
// failed
$response->status = false;
echo json_encode($response);
}
}
Run Code Online (Sandbox Code Playgroud)
}
这代表一个名为 com_fooauth 的组件。现在本机应用程序将发送如下查询:
http://www.myhost.com/index.php?option=com_fooauth&user=username&password=pass&format=raw
Run Code Online (Sandbox Code Playgroud)
这是将所有内容放入控制器的捷径,但希望您能明白这一点。