Uh oh!
There was an error while loading. Please reload this page.
Replies: 2 comments 2 replies
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In this regard, I agree with you. In my opinion, necessary changes should be made. Also, this issue was previously raised by @jozefrebjak in #433 . I personally followed up to make a change, but unfortunately I did not receive an answer. shield/src/Filters/TokenAuth.php Lines 51 to 53 in 84a4f31 |
@datamweb@khan-umer Here is my working filter for api routes: <?phpdeclare(strict_types=1);
namespaceModules\Api\Rest\V1\Filters;
useCodeIgniter\Exceptions\PageNotFoundException;
useCodeIgniter\Filters\FilterInterface;
useCodeIgniter\HTTP\IncomingRequest;
useCodeIgniter\HTTP\RequestInterface;
useCodeIgniter\HTTP\Response;
useCodeIgniter\HTTP\ResponseInterface;
class ApiFilter implements FilterInterface
{
/** * @param array|null $arguments * * @return Response|void */publicfunctionbefore(RequestInterface$request, $arguments = null)
{
if (! $requestinstanceof IncomingRequest) {
return;
}
if (! config('RestApi')->enabled) {
throw PageNotFoundException::forPageNotFound();
}
helper(['auth', 'setting']);
$uri = $request->getUri();
$segments = $uri->getSegments();
if (in_array('api', $segments, true)) {
$validCreds = auth('tokens')->check([
'token' => $request->getHeaderLine(setting('Auth.authenticatorHeader')['tokens'] ?? 'Authorization'),
]);
if (! $validCreds->isOK()) {
$response = service('response');
$response->setStatusCode(401, 'unauthorized');
$response->setJSON([
'status' => false,
'message' => lang('Api.invalidToken'),
]);
return$response;
}
}
}
publicfunctionafter(RequestInterface$request, ResponseInterface$response, $arguments = null): void
{
}
}it's added as alias to global filters, and then just protecting api routes like: $routes->group(
'api/rest/v1/',
[
'namespace' => 'Modules\Api\Rest\V1\Controllers',
'filter' => 'rest-api',
],
staticfunction ($routes): void {
// API ROUTES
}
); |
Uh oh!
There was an error while loading. Please reload this page.
Hello everybody,
as per the documentation Mobile Authentication with Access Tokens
I'm able to authenticate my Api using access token with postman application.
but if access token is not provided or invalid token is given then it response with status 200 with Login view.
I think for Api it should respond with error like unauthorize access or something like this.
maybe I'm missing some concept for Mobile Authentication with Access Tokens. if any please help me by leave some reference here.
if it's ok, then how to handle such case for mobile Api
All reactions