Skip to content

Commit

Permalink
🚑 fix invalid oauth client on some clients (#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu authored Jan 30, 2024
1 parent 2250a12 commit d7531ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/Http/Controllers/API/v1/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace App\Http\Controllers\API\v1;

use App\Models\OAuthClient;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
use Throwable;

/**
* @OA\Info(
Expand Down Expand Up @@ -120,4 +123,13 @@ public function sendError(array|string $error = null, int $code = 404, array $ad
$response = $additional ? array_merge($response, ["meta" => $additional]) : $response;
return response()->json($response, $code);
}

public static function getCurrentOAuthClient(): OAuthClient|null {
try {
return request()?->user()?->token()?->client;
} catch (Throwable $throwable) {
Log::debug('Could not get current OAuth Client: ' . $throwable->getMessage());
return null;
}
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Events\StatusUpdateEvent;
use App\Exceptions\PermissionException;
use App\Exceptions\StatusAlreadyLikedException;
use App\Http\Controllers\API\v1\Controller as APIController;
use App\Http\Controllers\Backend\Support\LocationController;
use App\Models\Event;
use App\Models\Like;
Expand Down Expand Up @@ -284,7 +285,7 @@ public static function createStatus(
'business' => $business,
'visibility' => $visibility,
'event_id' => $event?->id,
'client_id' => request()?->user()?->token()?->client?->id,
'client_id' => APIController::getCurrentOAuthClient()?->id,
]);
}
}

0 comments on commit d7531ca

Please sign in to comment.