Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/Http/Middleware/ApiAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function handle($request, Closure $next)
return response()->json(['error' => 'Application is not allowed to access this API version'], 403);
}

$canAccessOrganisation = $this->canAccessOrganisation($request->path(), (array) $application->rules);

if (!$canAccessOrganisation) {
return response()->json(['error' => 'Application is not allowed to access this organisation'], 403);
}

$usageLog = new UsageLog;
$usageLog->application_id = $application->id;
$usageLog->method = $request->method();
Expand Down Expand Up @@ -71,4 +77,21 @@ private function canAccessRequestedVersion(string $path, array $rules): bool

return true;
}

private function canAccessOrganisation(string $path, array $rules): bool
{
// Check if accessing org/{code}/whatnow endpoint
if (preg_match('#org/([^/]+)/whatnow#', $path, $matches)) {
$orgCode = $matches[1];

// If allowed_country_code is defined in rules, check if this org is restricted
if (isset($rules['allowed_country_code']) && is_array($rules['allowed_country_code'])) {
if (!in_array($orgCode, $rules['allowed_country_code'])) {
return false;
}
}
}

return true;
}
}
Loading