Showing posts with label Tech. Show all posts
Showing posts with label Tech. Show all posts

Thursday, October 17, 2013

Authentication Restful Web Service with ZfcUser in Zend Framework 2

I'm a beginner to Zend Framework 2, so it take me like 4 days to create a module that do authentication service for my Android app. It's kind of painful for me because I cannot find any clear tutorial or example on doing those thing, maybe because it's too easy that no developer care to share it.
Luckily I found an issue thread in ZfcUser Git Project, and with some tutorial, I come to a solution that work for me. I know it's not the best way, but I want to share for anyone, beginner like me, find a simple way to do authentication and move on to more complex Zend stuff later.

Update: after a while of working with Zend, then I realized that I need not to use Restful for my authentication, I just need to use normal action that will get the POST and return a json file.
use Zend\View\Model\JsonModel;
// Your class 
// ...
public function jsonAction(){  
     // Your code  
     return new JsonModel(array(  
             'tag' => 'login',  
             'success' => 0,  
             'error' => 1,  
             'error_msg' => 0,//$this->failedLoginMessage,  
           ));  
   }  

Update 2: If you are thinking about Restful WS, you should investigate some about it first here . As I did from the beginning, trying to use Restful to do authentication is totally wrong. :)