Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 81ee07f

Browse files
committed
Attach app on request if possible.
1 parent de7e358 commit 81ee07f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/API/Controller.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ abstract class Controller implements HttpServerInterface
5151
*/
5252
protected $channelManager;
5353

54+
/**
55+
* The app attached with this request.
56+
*
57+
* @var \BeyondCode\LaravelWebSockets\Apps\App|null
58+
*/
59+
protected $app;
60+
5461
/**
5562
* Initialize the request.
5663
*
@@ -176,8 +183,7 @@ protected function handleRequest(ConnectionInterface $connection)
176183

177184
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
178185

179-
$this
180-
->ensureValidAppId($laravelRequest->appId)
186+
$this->ensureValidAppId($laravelRequest->get('appId'))
181187
->ensureValidSignature($laravelRequest);
182188

183189
// Invoke the controller action
@@ -220,7 +226,7 @@ protected function sendAndClose(ConnectionInterface $connection, $response)
220226
*/
221227
public function ensureValidAppId($appId)
222228
{
223-
if (! App::findById($appId)) {
229+
if (! $appId || ! $this->app = App::findById($appId)) {
224230
throw new HttpException(401, "Unknown app id `{$appId}` provided.");
225231
}
226232

@@ -252,9 +258,7 @@ protected function ensureValidSignature(Request $request)
252258

253259
$signature = "{$request->getMethod()}\n/{$request->path()}\n".Pusher::array_implode('=', '&', $params);
254260

255-
$app = App::findById($request->get('appId'));
256-
257-
$authSignature = hash_hmac('sha256', $signature, $app->secret);
261+
$authSignature = hash_hmac('sha256', $signature, $this->app->secret);
258262

259263
if ($authSignature !== $request->get('auth_signature')) {
260264
throw new HttpException(401, 'Invalid auth signature provided.');

0 commit comments

Comments
 (0)