API Service para manejo de token
This commit is contained in:
23
app/src/Service/API.php
Normal file
23
app/src/Service/API.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Exception\MissingAuthorizationHeader;
|
||||
|
||||
class API extends Ideal\Service
|
||||
{
|
||||
/**
|
||||
* @throws MissingAuthorizationHeader
|
||||
*/
|
||||
public function getKey(ServerRequestInterface $request): string
|
||||
{
|
||||
$auth_headers = $request->getHeader('Authorization');
|
||||
foreach ($auth_headers as $header) {
|
||||
if (str_contains($header, 'Bearer')) {
|
||||
return substr($header, strlen('Bearer '));
|
||||
}
|
||||
}
|
||||
throw new MissingAuthorizationHeader();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user