update to retrive token from header request
This commit is contained in:
parent
cc9567da27
commit
2cee2f5f06
6 changed files with 23 additions and 8 deletions
|
|
@ -65,5 +65,6 @@ class Kernel extends HttpKernel
|
|||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'htmlsanitize' => \App\Http\Middleware\HtmlSanitizer::class,
|
||||
'apiCheck' => \App\Http\Middleware\ApiCheckCredentialMiddleware::class
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class ApiCheckCredentialMiddleware
|
|||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
if ($request->token !== \config('api.key')) {
|
||||
if ($request->header('Authorization') !== \config('api.key')) {
|
||||
return response('Unauthorized', 401);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Network extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
|
|
@ -15,8 +14,7 @@ class Network extends Model
|
|||
protected $casts = [
|
||||
'cidr' => 'encrypted',
|
||||
'first_ip' => 'encrypted',
|
||||
'last_ip' => 'encrypted',
|
||||
'comments' => 'string'
|
||||
'last_ip' => 'encrypted'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +30,6 @@ class Network extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'cidr', 'first_ip', 'last_ip', 'comments'
|
||||
'cidr', 'first_ip', 'last_ip', 'commentaire'
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ class RouteServiceProvider extends ServiceProvider
|
|||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web-fo.php'));
|
||||
|
||||
Route::middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -77,9 +81,9 @@ class RouteServiceProvider extends ServiceProvider
|
|||
}
|
||||
// * Flatten if needed
|
||||
$cspReport = collect(request()->json('csp-report'))
|
||||
->flatMap(function ($v, $k) {
|
||||
return [$k => is_array($v) ? collect($v)->flatten()->implode(', ') : $v];
|
||||
})->all();
|
||||
->flatMap(function ($v, $k) {
|
||||
return [$k => is_array($v) ? collect($v)->flatten()->implode(', ') : $v];
|
||||
})->all();
|
||||
// * Filter array keys
|
||||
$cspReport = collect(array_intersect_key($cspReport, [
|
||||
'blocked-uri' => '', 'document-uri' => '', 'original-policy' => '',
|
||||
|
|
|
|||
5
config/api.php
Normal file
5
config/api.php
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'key' => env('LDC_WEB_API_KEY')
|
||||
];
|
||||
|
|
@ -1 +1,8 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\API\NetworksController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('/api')->middleware('apiCheck')->group(function () {
|
||||
Route::get('/networks', [NetworksController::class, 'index']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue