mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Fixed api token endpoint documentation
This commit is contained in:
committed by
Constantin Graf
parent
4ea55e5867
commit
69a8c8bb2b
@@ -59,11 +59,13 @@ class ApiTokenController extends Controller
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function revoke(string $apiTokenId): JsonResponse
|
||||
public function revoke(Token $apiToken): JsonResponse
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$apiToken = $user->tokens()->where('id', $apiTokenId)->firstOrFail();
|
||||
if ($apiToken->user_id !== $user->getKey()) {
|
||||
throw new AuthorizationException('API token does not belong to user');
|
||||
}
|
||||
|
||||
$apiToken->revoke();
|
||||
|
||||
@@ -77,11 +79,13 @@ class ApiTokenController extends Controller
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function destroy(string $apiTokenId): JsonResponse
|
||||
public function destroy(Token $apiToken): JsonResponse
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$apiToken = $user->tokens()->where('id', $apiTokenId)->firstOrFail();
|
||||
if ($apiToken->user_id !== $user->getKey()) {
|
||||
throw new AuthorizationException('API token does not belong to user');
|
||||
}
|
||||
|
||||
$apiToken->delete();
|
||||
|
||||
|
||||
@@ -21,11 +21,17 @@ class ApiTokenResource extends BaseResource
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
/** @var string $id ID of the API token, this ID is NOT a UUID */
|
||||
'id' => $this->resource->id,
|
||||
/** @var string $name Name of the API token */
|
||||
'name' => $this->resource->name,
|
||||
/** @var bool $revoked Whether the API token is revoked */
|
||||
'revoked' => $this->resource->revoked,
|
||||
/** @var array<string> $scopes List of scopes that the API token has */
|
||||
'scopes' => $this->resource->scopes,
|
||||
/** @var string $created_at When the API token was created (ISO 8601 format, UTC timezone, example: 2024-02-26T17:17:17Z) */
|
||||
'created_at' => $this->formatDateTime($this->resource->created_at),
|
||||
/** @var string|null $expires_at At what time the API token expires (ISO 8601 format, UTC timezone, example: 2024-02-26T17:17:17Z) */
|
||||
'expires_at' => $this->formatDateTime($this->resource->expires_at),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\V1\ApiToken;
|
||||
|
||||
use App\Http\Resources\V1\BaseResource;
|
||||
use App\Models\Passport\Token;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* @property-read Token $resource
|
||||
*/
|
||||
class ApiTokenWithAccessTokenResource extends ApiTokenResource
|
||||
class ApiTokenWithAccessTokenResource extends BaseResource
|
||||
{
|
||||
private string $accessToken;
|
||||
|
||||
@@ -27,9 +28,21 @@ class ApiTokenWithAccessTokenResource extends ApiTokenResource
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$parent = parent::toArray($request);
|
||||
|
||||
return $parent + [
|
||||
return [
|
||||
/** @var string $id ID of the API token, this ID is NOT a UUID */
|
||||
'id' => $this->resource->id,
|
||||
/** @var string $name Name of the API token */
|
||||
'name' => $this->resource->name,
|
||||
/** @var bool $revoked Whether the API token is revoked */
|
||||
'revoked' => $this->resource->revoked,
|
||||
/** @var array<string> $scopes List of scopes that the API token has */
|
||||
'scopes' => $this->resource->scopes,
|
||||
/** @var string $created_at When the API token was created (ISO 8601 format, UTC timezone, example: 2024-02-26T17:17:17Z) */
|
||||
'created_at' => $this->formatDateTime($this->resource->created_at),
|
||||
/** @var string|null $expires_at At what time the API token expires (ISO 8601 format, UTC timezone, example: 2024-02-26T17:17:17Z) */
|
||||
'expires_at' => $this->formatDateTime($this->resource->expires_at),
|
||||
// Additional fields
|
||||
/** @var string $access_token Access token that can be used to authenticate requests */
|
||||
'access_token' => $this->accessToken,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\FailedJob;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\OrganizationInvitation;
|
||||
use App\Models\Passport\Token;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
use App\Models\Tag;
|
||||
@@ -100,5 +101,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
// Routing
|
||||
Route::model('member', Member::class);
|
||||
Route::model('invitation', OrganizationInvitation::class);
|
||||
Route::model('apiToken', Token::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user