A very lightweight token system for micro-services
Remove
$app->register(App\Providers\AuthServiceProvider::class);
Add
$app->register(Mathewberry\Tokenizer\TokenizerServiceProvider::class);
Remove
'auth' => App\Http\Middleware\Authenticate::class,
Add
'auth' => Mathewberry\Tokenizer\Middleware\Authenticate::class,
php artisan token:generate
Copy your generated token into a new key in your .env
called API_TOKEN
When ever your make a call just pass the header api_token
and the value is the value of the token in your .env
.
Make sure your route or controller is using the auth
middleware.
class DomainController extends Controller
{
public function __construct()
{
$this->middleware(['auth']);
}
public function index()
{
$domains = Domain::get();
return response($domains, 200);
}
}
It's that simple, your micro-service is now that little bit more secure.