Replies: 3 comments 3 replies
-
Yes. This is a bug. shield/src/Authentication/Authenticators/AccessTokens.php Lines 127 to 128 in ae5ffb9
|
Beta Was this translation helpful? Give feedback.
-
@bribar @kenjis I would like to know what is the best way to check if user has provided correct API KEY, I can't find a docs about this topic. @bribar solutions looks nice, but is this a way how to handle it ? Here is my <?php
declare(strict_types=1);
namespace Modules\Api\Rest\V1\Filters;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
class ApiFilter implements FilterInterface
{
public function before(RequestInterface $request, $arguments = null): void
{
if (!config('RestApi')->enabled) {
throw PageNotFoundException::forPageNotFound();
}
helper('auth');
$uri = $request->getUri();
$segments = $uri->getSegments();
if (in_array('api', $segments)) {
$validCreds = auth('tokens')->check(['token' => $request->getHeaderLine('X-API-KEY')]);
if (!$validCreds->isOK()) {
if (ENVIRONMENT === 'development') {
throw new \Exception('Whoa buddy');
}
}
}
}
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void
{
// Do something here
}
} I would like to return to user unauthorised response. https://www.codeigniter.com/user_guide/outgoing/api_responses.html?highlight=failunauthorize |
Beta Was this translation helpful? Give feedback.
-
@kenjis we have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I get this error when requests to my API are close together.
Through a Codeigniter Filter (before) I run this to verify the api token is valid
I'm thinking if the requests are really close together the timestamps are similar, so BaseModel says there's nothing to update? If I separate the requests with time in between things work fine.
Is this a bug? Or am I not using Filters as intended?
Beta Was this translation helpful? Give feedback.
All reactions