Skip to content

Commit

Permalink
Adding random generation of an API token for the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-savage committed Oct 13, 2024
1 parent 2754020 commit 8e3f4dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use AspirePress\AspireCloud\Repository\Api\V1\ApiTokenIssuanceHandler;
use AspirePress\AspireCloud\V1\CatchAll\Handlers\CatchAllHandler;
use Mezzio\Application;
use Mezzio\MiddlewareFactory;
Expand All @@ -26,5 +27,6 @@
*/

return static function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void {
$app->post('/repository/api/v1/apitoken', ApiTokenIssuanceHandler::class, 'repository.api.v1.apitoken');
$app->route('/{path:.*}', CatchAllHandler::class, ['GET', 'POST'], 'app.home');
};
4 changes: 4 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use AspirePress\AspireCloud\Data\Factories\PluginRepositoryFactory;
use AspirePress\AspireCloud\Data\Repositories\PluginRepository;
use AspirePress\AspireCloud\Repository\Api\V1\ApiTokenIssuanceHandler;
use Aura\Sql\ExtendedPdoInterface;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Laminas\Stratigility\Middleware\ErrorHandler;
Expand All @@ -20,6 +21,9 @@ public function __invoke(): array
{
return [
'dependencies' => [
'invokables' => [
ApiTokenIssuanceHandler::class => ApiTokenIssuanceHandler::class,
],
'delegators' => [
ErrorHandler::class => [LoggingListenerDelegatorFactory::class],
],
Expand Down
17 changes: 17 additions & 0 deletions src/Repository/Api/V1/ApiTokenIssuanceHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace AspirePress\AspireCloud\Repository\Api\V1;

use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Server\RequestHandlerInterface;

class ApiTokenIssuanceHandler implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new JsonResponse(['api_key' => bin2hex(random_bytes(16))]);
}
}

0 comments on commit 8e3f4dd

Please sign in to comment.