From 99dc13b297ed466de87e58b0b4612fcfcae0bdc2 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 17 Apr 2025 09:41:01 +1000 Subject: [PATCH] Initial implementation of API access to clrghouz with a whoami endpoint --- app/Http/Controllers/UserController.php | 5 +++++ bootstrap/app.php | 5 +++++ routes/api.php | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index bf5f656..7f5ffe9 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -72,4 +72,9 @@ class UserController extends Controller return view('user.link'); } + + public function whoami(): User + { + return Auth::user(); + } } \ No newline at end of file diff --git a/bootstrap/app.php b/bootstrap/app.php index 51687e4..ed028f6 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -13,6 +13,11 @@ return Application::configure(basePath: dirname(__DIR__)) commands: __DIR__.'/../routes/console.php', health: '/up', ) + + ->withMiddleware(function (Middleware $middleware) { + $middleware->statefulApi(); + }) + ->withMiddleware(function (Middleware $middleware) { $middleware->appendToGroup('web', [ AddUserToView::class, diff --git a/routes/api.php b/routes/api.php index 2981a25..88c030a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,7 +2,7 @@ use Illuminate\Support\Facades\Route; -use App\Http\Controllers\{DomainController,MatrixController}; +use App\Http\Controllers\{DomainController,MatrixController,UserController}; /* |-------------------------------------------------------------------------- @@ -19,4 +19,7 @@ Route::get('/domain/daily',[DomainController::class,'api_daily_stats']); Route::any('matrix/{item}',[MatrixController::class,'webhook']) ->where('item', '.*') - ->middleware('auth:matrix'); \ No newline at end of file + ->middleware('auth:matrix'); + +Route::get('/whoami',[UserController::class,'whoami']) + ->middleware(['auth:sanctum']); \ No newline at end of file