Servizi 3 e autenticazione della sessione
Domanda
Sto creando una titanio mobile app che consuma e utilizza Drupal servizi. Sono in grado di creare un nodo, ma l'utente è sempre anonimo. Ho provato a installare le intestazioni di richiesta in modo che il Autenticazione è di base.
authstr = 'Basic ' +Titanium.Utils.base64encode('admin'+':'+'password');
xhr.setRequestHeader('Authorization', authstr);
xhr.setRequestHeader("Content-Type","application/json");
xhr.send(JSON.stringify(params));
Per alcuni motivi ancora mi dà;
Codice = 3 "Autenticazione necessaria"
Qual è il modo migliore per risolvere questo? E 'anche possibile utilizzare le sessioni in questo modo?
Soluzione
Session authentication is different than Basic authentication.
Session authentication requires that you login, by sending a POST request to ENDPOINT/user/login. It will return the session header information and you need to store that for future use and send it along with every request.
Altri suggerimenti
Thank you very much for your help. I finally manage to autenticate and retrieve files from my rpc server. Here is my syntax in case anyone needs it.
// USER LOGIN
$authenticate = xmlrpc($settings['server'], Array('user.login' => array($settings['user'] , $settings['password']),));
// CREATE HEADERS
$options['headers']['Cookie'] = $authenticate['session_name'] . '=' . $authenticate['sessid'];
//RETRIEVE FILE
$file= xmlrpc($settings['server'], Array('file.retrieve' => Array(Array("fid"=>$fid),Array("file_contents"=> 'true'),Array("image_styles"=>'true') )),$options);
EDIT: AFTER SERVICES 3.5 you should do:
// USER LOGIN
$authenticate = xmlrpc($settings['server'], Array('user.login' => array($settings['user'] , $settings['password']),));
// CREATE HEADERS
$options['headers']['Cookie'] = $authenticate['session_name'] . '=' . $authenticate['sessid'];
// GET TOKEN
$token = xmlrpc(url($this->endpoint, array('absolute' => TRUE)), array('user.token' => array()), $this->headers);
//INSERT TOKEN INTO HEADERS
$options['headers']['X-CSRF-Token'] = $token['token'];
//RETRIEVE FILE
$file= xmlrpc($settings['server'], Array('file.retrieve' => Array(Array("fid"=>$fid),Array("file_contents"=> 'true'),Array("image_styles"=>'true') )),$options);
you can use services_basic_auth module (https://drupal.org/project/services_basic_auth) to enable basic authentication for drupal services module .
After installing services_basic_auth module you need to enable it by going to, Structure-->Services-->Edit
Now you can use Basic Authorization Header to create nodes.