implement token for Laravel 4 RESTful API authentication
I'm learning Laravel 4 framework and PHP.
Currently, I'm trying to do a simple authentication process between client
application and server
Below is my planning approach:
1) Client login to server by a get request with username and password
2) Server will validate and return a token string if successful. The token
string will be encoded (hashed ???) with username,password and expired
time
3) The token will be sent together with requests to server for example:
/server/getProduct/ABC/para1/para2
So for all methods, the first parameter will always be the token string,
in this case is 'ABC'
4) Before processing request from client, method has to validate the token
(decode the token -> check username/password and expired time ) like
below:
public function getProduct($token,$para1,$para2)
{
if(validateToken($token)
{
.....
}
}
So for every method I have to put validateToken and obviously, it's not a
good way to go. Is there any way that I can check the token for every
requests sent from client without putting it in every methods and what is
the best way to generate the token with the parameters given.
I'm certainly open to other implemented solutions or packages as I think
this is the common approach and I prefer not to reinvent the wheel.
Thank you and appreciate for your time and help.
No comments:
Post a Comment