简体   繁体   中英

Laravel 5.1 RESTful api authentication

I'm building RESTful backend in PHP for a mobile app.

I will need users to log in, and then all auth should be handled with tokens. My idea is: generate a token when the user's logs in (this token will be oneshot) everytime a user performs an action this token will be used to authenticate him and then "burned", the application (in the json response) will provide a new oneshot token. How can implement this in laravel 5.1? Is there some library with similar token implementatio?

Thank you in advance for your help.

I had similar situation. I came up with a middleware, which checks for a special token header (ie MyToken: asdasd) in every request, except the login request. In login request, I check provided information and if it is OK, then I will generate a token and save it to database. Every subsequent request should have this token, and it will be checked against database to be correct and also not expired.

The good thing here was the middleware, made the solution very easy-to-implement.

Read more about middlewares

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM