Saturday, March 4, 2017

Using an App Token with Laravel API for extra security

I have built a RESTful API with Laravel and it's working great.

There is authentication when a user wants to create or update their records.

However, I want to add one extra level of security with an Application Token.

I have placed this token in the .env file and want to check if the request has the app_token="uniquestring" in order for my API to do anything.

Basically I don't care if the user has the correct api_token, if the request doesn't have an application_token then I want it to return false.

I have a few controllers and I'm sure I can hardcode this, but is there a good way to do it in the routes by creating a group and setting a specific rule saying if app_token != {my app token} then return Request denied or something along those lines?

Any tips are greatly appreciated. Thanks in advance!



via Samir Chahine

Advertisement