From 610690f4351acd5fc4090e6466572e64662e61d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0zni=20Burak=20Demirta=C5=9F?= Date: Sat, 3 Aug 2019 03:01:34 +0300 Subject: [PATCH] Added JWT middleware and updated services file. --- README.md | 2 +- app/Middlewares/Jwt.php | 29 +++++++++++++++++++++++++++++ config/services.php | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/Middlewares/Jwt.php diff --git a/README.md b/README.md index ca1a80e..680b9e2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ nur - simple framework for PHP - Routing system and basic Middleware support. ([PHP-Router](https://github.com/izniburak/php-router)) - Symfony Request and Response components. ([Symfony HttpFoundation](https://symfony.com/doc/current/components/http_foundation.html)) - PDOx Query Builder Class. ([PDOx](https://github.com/izniburak/pdox)) -- Authentication component. +- Authentication component. (with **JWT** and **Basic Auth**) - Some **Laravel 5.8** Packages supports. - Eloquent ORM support. ([Laravel Eloquent ORM](https://laravel.com/docs/eloquent)) - Laravel Query Builder support. ([Laravel Query Builder](https://laravel.com/docs/queries)) diff --git a/app/Middlewares/Jwt.php b/app/Middlewares/Jwt.php new file mode 100644 index 0000000..3bd6998 --- /dev/null +++ b/app/Middlewares/Jwt.php @@ -0,0 +1,29 @@ +jwt()->check(); + } catch (JwtException $e) { + return response()->json([ + 'success' => false, + 'error' => $e->getMessage(), + ], 401); + } + + return true; + } +} diff --git a/config/services.php b/config/services.php index 4edc91b..07b0124 100644 --- a/config/services.php +++ b/config/services.php @@ -27,6 +27,7 @@ Nur\Providers\Log::class, Nur\Providers\Hash::class, Nur\Providers\Validation::class, + // Nur\Providers\Jwt::class, // Nur\Providers\Pdox::class, // Nur\Providers\Html::class, // Nur\Providers\Cache::class, @@ -62,6 +63,7 @@ 'Crypt' => Nur\Facades\Crypt::class, 'Log' => Nur\Facades\Log::class, 'Validation' => Nur\Facades\Validation::class, + 'Jwt' => Nur\Facades\Jwt::class, ],