24 lines
622 B
PHP
24 lines
622 B
PHP
<?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();
|
|
}
|
|
}
|