Skip to content

Commit

Permalink
Merge pull request #11615 from minisbett/patch-1
Browse files Browse the repository at this point in the history
Allow Lazer replay download via client credential grant
  • Loading branch information
nanaya authored Nov 15, 2024
2 parents 9d8e380 + f62b0be commit b8f1ee6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 9 additions & 2 deletions app/Http/Controllers/ScoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Models\Solo\Score as SoloScore;
use App\Transformers\ScoreTransformer;
use App\Transformers\UserCompactTransformer;
use Illuminate\Auth\AuthenticationException;

class ScoresController extends Controller
{
Expand All @@ -22,6 +23,7 @@ public function __construct()

$this->middleware('auth', ['except' => [
'show',
'download',
]]);

$this->middleware('require-scopes:public');
Expand All @@ -42,6 +44,11 @@ private static function parseIdOrFail(string $id): int

public function download($rulesetOrSoloId, $id = null)
{
$currentUser = \Auth::user();
if (!is_api_request() && $currentUser === null) {
throw new AuthenticationException('User is not logged in.');
}

$shouldRedirect = !is_api_request() && !from_app_url();
if ($id === null) {
if ($shouldRedirect) {
Expand All @@ -68,9 +75,9 @@ public function download($rulesetOrSoloId, $id = null)
abort(404);
}

$currentUser = \Auth::user();
if (
!$currentUser->isRestricted()
$currentUser !== null
&& !$currentUser->isRestricted()
&& $currentUser->getKey() !== $score->user_id
&& ($currentUser->token()?->client->password_client ?? false)
) {
Expand Down
2 changes: 0 additions & 2 deletions tests/api_routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@
"App\\Http\\Middleware\\ThrottleRequests:1200,1,api:",
"App\\Http\\Middleware\\RequireScopes",
"App\\Http\\Middleware\\ThrottleRequests:10,1,api-scores-download:",
"Illuminate\\Auth\\Middleware\\Authenticate",
"App\\Http\\Middleware\\RequireScopes:public"
],
"scopes": [
Expand All @@ -1004,7 +1003,6 @@
"App\\Http\\Middleware\\ThrottleRequests:1200,1,api:",
"App\\Http\\Middleware\\RequireScopes",
"App\\Http\\Middleware\\ThrottleRequests:10,1,api-scores-download:",
"Illuminate\\Auth\\Middleware\\Authenticate",
"App\\Http\\Middleware\\RequireScopes:public"
],
"scopes": [
Expand Down

0 comments on commit b8f1ee6

Please sign in to comment.