-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add authentication and debug package
- Loading branch information
1 parent
9af3dd4
commit 55aa815
Showing
23 changed files
with
856 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "vertexvaar/blueauth", | ||
"description": "Authentication component for bluesprints", | ||
"type": "library", | ||
"license": "GPL-3.0+", | ||
"authors": [ | ||
{ | ||
"name": "Oliver Eglseder", | ||
"email": "[email protected]", | ||
"homepage": "http://vxvr.de/", | ||
"role": "Developer" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"VerteXVaaR\\BlueAuth\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": "8.2.*", | ||
"vertexvaar/bluesprints": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use VerteXVaaR\BlueAuth\Middleware\AuthenticationMiddleware; | ||
|
||
return [ | ||
'vertexvaar/blueauth/authentication' => [ | ||
'service' => AuthenticationMiddleware::class, | ||
'before' => ['vertexvaar/bluesprints/routing'] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
|
||
VerteXVaaR\BlueAuth\: | ||
resource: '../src/*' |
51 changes: 51 additions & 0 deletions
51
packages/blueauth/src/Middleware/AuthenticationMiddleware.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueAuth\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use VerteXVaaR\BlueSprints\Environment\Config; | ||
use VerteXVaaR\BlueSprints\Environment\Paths; | ||
|
||
use function CoStack\Lib\concat_paths; | ||
use function file_exists; | ||
|
||
readonly class AuthenticationMiddleware implements MiddlewareInterface | ||
{ | ||
public function __construct( | ||
private Config $config, | ||
private Paths $paths | ||
) { | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$authenticated = false; | ||
$username = null; | ||
|
||
$cookies = $request->getCookieParams(); | ||
$cookieAuthName = $this->config->cookieAuthName ?: 'bluedist_auth'; | ||
$authCookie = $cookies[$cookieAuthName] ?? null; | ||
|
||
if (null !== $authCookie) { | ||
$authPath = concat_paths($this->paths->database, 'auth'); | ||
$cookieFile = concat_paths($authPath, $authCookie); | ||
if (file_exists($cookieFile)) { | ||
$sessionValues = require $cookieFile; | ||
if ($sessionValues['authenticated'] ?? false) { | ||
$authenticated = true; | ||
$username = $sessionValues['username'] ?? null; | ||
} | ||
} | ||
} | ||
|
||
$request = $request->withAttribute('authenticated', $authenticated); | ||
$request = $request->withAttribute('username', $username); | ||
|
||
return $handler->handle($request); | ||
} | ||
} |
Oops, something went wrong.