Files
ignacionelson 6e47d76ba6 ProjectSend 2.0.0
Client file sharing, rebuilt from the ground up: a private area per
client, resumable uploads, folders, groups and categories, sharing with
expiry dates and download limits, comments, file versions, an activity
log, a REST API, and sixteen languages.

This repository begins here. ProjectSend 2 was developed privately, and
that development history is not published — the previous generation
remains available, with its own history, at projectsend/legacy.

Free software under the GNU General Public License v2, or (at your
option) any later version.
2026-08-14 01:38:12 -03:00

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Api\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Modules\Audit\Action;
use App\Modules\Audit\ActivityLogger;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Laravel\Sanctum\PersonalAccessToken;
/**
* Self-revocation: an integration that is being decommissioned, or one that
* suspects it has leaked its own credential, can retire it without anyone
* logging into the web UI.
*
* Scoped to the calling token on purpose — see routes/api.php.
*/
class CurrentTokenController extends Controller
{
public function __construct(
private readonly ActivityLogger $activity,
) {}
public function __invoke(Request $request): JsonResponse
{
$user = $request->user();
assert($user !== null);
// Sanctum's own docblock types this as non-nullable, but the
// underlying property is simply unset when the request was not
// token-authenticated. Narrowing it here keeps the null branch
// honest instead of letting the analyser delete it.
/** @var PersonalAccessToken|null $token */
$token = $user->currentAccessToken();
if ($token !== null) {
// `via` and `api_token` are stamped by ActivityLogger itself.
$this->activity->log(Action::ApiTokenRevoked, $user, context: ['token_name' => $token->name]);
$token->delete();
}
return response()->json(status: 204);
}
}