Skip to content

Commit a7909cb

Browse files
committed
Authorize restifyjs.
1 parent 98b32f0 commit a7909cb

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

config/config.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@
4949
'user_verify_url' => env('FRONTEND_APP_URL').'/verify/{id}/{emailHash}',
5050
],
5151

52+
/*
53+
|--------------------------------------------------------------------------
54+
| RestifyJS
55+
|--------------------------------------------------------------------------
56+
|
57+
| This configuration is used for supporting the RestifyJS
58+
|
59+
*/
60+
'restifyjs' => [
61+
/*
62+
| Token to authorize the setup endpoint.
63+
*/
64+
'token' => env('RESTIFYJS_TOKEN', 'testing'),
65+
],
66+
5267
/*
5368
|--------------------------------------------------------------------------
5469
| Restify Base Route

routes/api.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Binaryk\LaravelRestify\Http\Controllers\RepositoryUpdateBulkController;
2121
use Binaryk\LaravelRestify\Http\Controllers\RepositoryUpdateController;
2222
use Binaryk\LaravelRestify\Http\Controllers\RestifyJsSetupController;
23+
use Binaryk\LaravelRestify\Http\Middleware\RestifySanctumAuthenticate;
2324
use Illuminate\Support\Facades\Route;
2425

2526
// Global Search...
@@ -31,7 +32,9 @@
3132
Route::post('/profile/avatar', '\\'.ProfileAvatarController::class);
3233

3334
// RestifyJS
34-
Route::get('/restifyjs/setup', '\\'.RestifyJsSetupController::class);
35+
Route::get('/restifyjs/setup', '\\'.RestifyJsSetupController::class)->withoutMiddleware(
36+
RestifySanctumAuthenticate::class,
37+
);
3538

3639
// Filters
3740
Route::get('/{repository}/filters', '\\'.RepositoryFilterController::class);

src/Http/Controllers/RestifyJsSetupController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
66
use Binaryk\LaravelRestify\Repositories\Repository;
77
use Binaryk\LaravelRestify\Restify;
8+
use Illuminate\Http\Request;
89
use Illuminate\Routing\Controller;
10+
use Illuminate\Support\Facades\App;
911
use Illuminate\Support\Str;
1012

1113
class RestifyJsSetupController extends Controller
1214
{
1315
public function __invoke(RestifyRequest $request)
1416
{
17+
if (App::environment('production')) {
18+
$this->authorize($request);
19+
}
20+
1521
return response()->json([
1622
'config' => $this->config(),
1723
'repositories' => $this->repositories($request),
@@ -46,4 +52,11 @@ private function deleteFirstAndLastSlash(string $domain): string
4652

4753
return $domain;
4854
}
55+
56+
private function authorize(Request $request)
57+
{
58+
if ($request->input('token') !== config('restify.restifyjs.token')) {
59+
abort(401, 'You are not authorized to see this request.');
60+
}
61+
}
4962
}

0 commit comments

Comments
 (0)