Browse Source

token middleware

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
0dc8fe8670
3 changed files with 31 additions and 1 deletions
  1. 28
    0
      app/Http/Middleware/TokenMiddleware.php
  2. 2
    0
      app/Http/routes.php
  3. 1
    1
      bootstrap/app.php

+ 28
- 0
app/Http/Middleware/TokenMiddleware.php View File

@@ -0,0 +1,28 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 11/24/15
6
+ * Time: 1:20 AM
7
+ */
8
+
9
+namespace App\Http\Middleware;
10
+
11
+use Closure;
12
+use Illuminate\Http\Request;
13
+
14
+class TokenMiddleware
15
+{
16
+    /**
17
+     * @param $request Request
18
+     * @param Closure $next
19
+     * @return null|string
20
+     */
21
+    public function handle($request, Closure $next)
22
+    {
23
+        if ($request->headers->get("X-Token") != getenv("TOKEN")) {
24
+            abort(401);
25
+        }
26
+        return $next($request);
27
+    }
28
+}

+ 2
- 0
app/Http/routes.php View File

@@ -15,5 +15,7 @@ use Luticate\Utils\LuRoute;
15 15
 
16 16
 $route = LuRoute::getInstance();
17 17
 
18
+$route->addMiddleware('App\Http\Middleware\TokenMiddleware');
19
+
18 20
 $route->post("/commands/exec", "Commands", "exec");
19 21
 $route->post("/sensors/value", "Sensors", "getValue");

+ 1
- 1
bootstrap/app.php View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 require_once __DIR__.'/../vendor/autoload.php';
4 4
 
5
-//Dotenv::load(__DIR__.'/../');
5
+Dotenv::load(__DIR__.'/../');
6 6
 
7 7
 /*
8 8
 |--------------------------------------------------------------------------

Loading…
Cancel
Save