diff --git a/src/Apps/App.php b/src/Apps/App.php index 92922ab..9d14cb8 100644 --- a/src/Apps/App.php +++ b/src/Apps/App.php @@ -36,7 +36,7 @@ class App public static function findBySecret(string $appSecret): ?App { - return app(AppProvider::class)->findByKey($appSecret); + return app(AppProvider::class)->findBySecret($appSecret); } public function __construct($appId, string $appKey, string $appSecret) diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index 6d3ed2e..b859fde 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -6,7 +6,8 @@ use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboar use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard; -use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize; +use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize as AuthorizeDashboard; +use BeyondCode\LaravelWebSockets\Statistics\Http\Middleware\Authorize as AuthorizeStatistics; use BeyondCode\LaravelWebSockets\Server\Router; use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; @@ -62,14 +63,16 @@ class WebSocketsServiceProvider extends ServiceProvider protected function registerRoutes() { Route::prefix(config('websockets.path'))->group(function() { - Route::middleware(Authorize::class)->group(function() { + Route::middleware(AuthorizeDashboard::class)->group(function() { Route::get('/', ShowDashboard::class); Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); Route::post('auth', AuthenticateDashboard::class); Route::post('event', SendMessage::class); }); - Route::post('statistics', [WebSocketStatisticsEntriesController::class, 'store']); + Route::middleware(AuthorizeStatistics::class)->group(function() { + Route::post('statistics', [WebSocketStatisticsEntriesController::class, 'store']); + }); }); return $this; diff --git a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php index a3a566d..a38f6a8 100644 --- a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php +++ b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php @@ -13,7 +13,9 @@ class WebSocketsStatisticsControllerTest extends TestCase { $this->post( action([WebSocketStatisticsEntriesController::class, 'store']), - $this->payload() + array_merge($this->payload(), [ + 'secret' => config('websockets.apps.0.secret'), + ]) ); $entries = WebSocketsStatisticsEntry::get();