You've already forked Php-Template
feat: add POST endpoint and security annotations to IndexController, implement TokenSecurity and UnauthorizedResponse
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 3m16s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Failing after 3m8s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 3m13s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m26s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m21s
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 3m16s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Failing after 3m8s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 3m13s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m26s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m21s
This commit is contained in:
@@ -71,6 +71,7 @@ class Api
|
|||||||
|
|
||||||
$this->router = new Router();
|
$this->router = new Router();
|
||||||
$this->router->get('/', IndexController::class . '::get');
|
$this->router->get('/', IndexController::class . '::get');
|
||||||
|
$this->router->post('/', IndexController::class . '::post');
|
||||||
$this->router->get('/healthz', HealthcheckController::class . '::get');
|
$this->router->get('/healthz', HealthcheckController::class . '::get');
|
||||||
|
|
||||||
$this->router->group('/.well-known', function (RouteGroup $router) {
|
$this->router->group('/.well-known', function (RouteGroup $router) {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ namespace Siteworxpro\App\Controllers;
|
|||||||
use Nyholm\Psr7\ServerRequest;
|
use Nyholm\Psr7\ServerRequest;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Siteworxpro\App\Attributes\Guards;
|
use Siteworxpro\App\Attributes\Guards;
|
||||||
|
use Siteworxpro\App\Docs\TokenSecurity;
|
||||||
|
use Siteworxpro\App\Docs\UnauthorizedResponse;
|
||||||
use Siteworxpro\App\Http\JsonResponseFactory;
|
use Siteworxpro\App\Http\JsonResponseFactory;
|
||||||
use OpenApi\Attributes as OA;
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
@@ -25,7 +27,7 @@ class IndexController extends Controller
|
|||||||
#[Guards\Jwt]
|
#[Guards\Jwt]
|
||||||
#[Guards\Scope(['get.index', 'status.check'])]
|
#[Guards\Scope(['get.index', 'status.check'])]
|
||||||
#[Guards\RequireAllScopes]
|
#[Guards\RequireAllScopes]
|
||||||
#[OA\Get(path: '/', tags: ['Examples'])]
|
#[OA\Get(path: '/', security: [new TokenSecurity()], tags: ['Examples'])]
|
||||||
#[OA\Response(
|
#[OA\Response(
|
||||||
response: '200',
|
response: '200',
|
||||||
description: 'An Example Response',
|
description: 'An Example Response',
|
||||||
@@ -34,6 +36,7 @@ class IndexController extends Controller
|
|||||||
new OA\Property('message', type: 'string'),
|
new OA\Property('message', type: 'string'),
|
||||||
])
|
])
|
||||||
)]
|
)]
|
||||||
|
#[UnauthorizedResponse]
|
||||||
public function get(ServerRequest $request): ResponseInterface
|
public function get(ServerRequest $request): ResponseInterface
|
||||||
{
|
{
|
||||||
return JsonResponseFactory::createJsonResponse(['status_code' => 200, 'message' => 'Server is running']);
|
return JsonResponseFactory::createJsonResponse(['status_code' => 200, 'message' => 'Server is running']);
|
||||||
@@ -46,7 +49,7 @@ class IndexController extends Controller
|
|||||||
*/
|
*/
|
||||||
#[Guards\Jwt]
|
#[Guards\Jwt]
|
||||||
#[Guards\Scope(['post.index'])]
|
#[Guards\Scope(['post.index'])]
|
||||||
#[OA\Post(path: '/', tags: ['Examples'])]
|
#[OA\Post(path: '/', security: [new TokenSecurity()], tags: ['Examples'])]
|
||||||
#[OA\Response(
|
#[OA\Response(
|
||||||
response: '200',
|
response: '200',
|
||||||
description: 'An Example Response',
|
description: 'An Example Response',
|
||||||
@@ -57,6 +60,7 @@ class IndexController extends Controller
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
|
#[UnauthorizedResponse]
|
||||||
public function post(ServerRequest $request): ResponseInterface
|
public function post(ServerRequest $request): ResponseInterface
|
||||||
{
|
{
|
||||||
return JsonResponseFactory::createJsonResponse(['status_code' => 200, 'message' => 'Server is running']);
|
return JsonResponseFactory::createJsonResponse(['status_code' => 200, 'message' => 'Server is running']);
|
||||||
|
|||||||
19
src/Docs/TokenSecurity.php
Normal file
19
src/Docs/TokenSecurity.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Siteworxpro\App\Docs;
|
||||||
|
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
class TokenSecurity extends OA\SecurityScheme
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
securityScheme: 'bearerAuth',
|
||||||
|
type: 'http',
|
||||||
|
description: 'JWT based authentication using Bearer tokens.',
|
||||||
|
bearerFormat: 'JWT',
|
||||||
|
scheme: 'bearer'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/Docs/UnauthorizedResponse.php
Normal file
26
src/Docs/UnauthorizedResponse.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Siteworxpro\App\Docs;
|
||||||
|
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
#[\Attribute]
|
||||||
|
class UnauthorizedResponse extends OA\Response
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
response: '401',
|
||||||
|
description: 'Unauthorized - Authentication is required and has failed or has not yet been provided.',
|
||||||
|
content: new OA\MediaType(
|
||||||
|
mediaType: 'application/json',
|
||||||
|
schema: new OA\Schema(
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'status_code', type: 'integer', example: 401),
|
||||||
|
new OA\Property(property: 'message', type: 'string', example: 'Unauthorized'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user