php - How do I implement single authentication in a RESTful app? -
i can't seem grasp how authentication works rest using zend framework. want user able login once , allow him access area of site depending on user level. have working non-rest login code, copied , placed in postaction()
method of api_logincontroller
class.
class api_logincontroller extends rest_controller { public function postaction() { $request = $this->getrequest(); $form = new application_form_loginform; if ($request->ispost()) { if ($form->isvalid($request->getpost())) { $email = $form->getvalue('email'); $password = $form->getvalue('password'); $user = application_model_usermodel::getuserbyemail($email); if ( $user && $user->login($password)) { echo json_encode(array('error' => false, 'message' => 'logged in.')); } else { echo json_encode(array('error' => true, 'message' => 'login failed.')); } } } } }
how go here? should zend(1.11) able identify user in subsequent access? right now, appears can't identify same user after login.
it possible provide authentication in rest application using zend.
this idea behind it:
- a user logs in using username/password
- in application validate login credentials
- using these credentials can generate unique token, similar session token in normal application
- you send identification token user
- each subsequent request user has provide token, proof he's logged in
- your application validate token , required action
zend contains lot of stuff already, bit of searching you'll find lot of functionality might provide of these points , make them fit in application.
Comments
Post a Comment