Welcome Guest, Not a member yet? Register   Sign In
JWT Authentication
#1
Question 

Hello..


I followed the tutorial on JWT Authentication 


I tried to enter the wrong token like

Code:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJJc3N1ZXIgb2YgdGhlIEpXVCIsImF1ZCI6IkF1ZGllbmNlIG9mIHRoZSBKV1QiLCJzdWIiOiIxIiwiaWF0IjoxNjUzOTkxOTg5LCJleHAiOjE2NTM5OTU1ODl9.hgOYHEcT6RGHb3po1lspTcmjrylY1Cy1IvYmHOyx0CY"


response :

{

    "error": "The token is invalid."

}



when I remove one character from the token, like



Code:
"yJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJJc3N1ZXIgb2YgdGhlIEpXVCIsImF1ZCI6IkF1ZGllbmNlIG9mIHRoZSBKV1QiLCJzdWIiOiIxIiwiaWF0IjoxNjUzOTkxOTg5LCJleHAiOjE2NTM5OTU1ODl9.hgOYHEcT6RGHb3po1lspTcmjrylY1Cy1IvYmHOyx0CY"




why I don't get any false token response?



response :



Code:
<br />
<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Malformed UTF-8 characters, possibly incorrectly encoded in C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\Format\JSONFormatter.php:41
Stack trace:
#0 C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\Format\JSONFormatter.php(41): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Malformed UTF-8...')
#1 C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\API\ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter-&gt;format(Array)
#2 C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\API\ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler-&gt;format(Array)
#3 C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\Debug\ExceptionHandler.php(78): CodeIgniter\Debug\ExceptionHandler-&gt;respond(Array, 500)
#4 C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\Debug\Exceptions.php(147): CodeIgniter\Debug\ExceptionHandler-&gt;handle(Object(DomainException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions-&gt;exceptionHandler(Object(DomainException))
#6 {main}
  thrown in <b>C:\Users\telo\cijwt\vendor\codeigniter4\framework\system\Format\JSONFormatter.php</b> on line <b>41</b><br />
{
    "title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Malformed UTF-8 characters, possibly incorrectly encoded in C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php:41\nStack trace:\n#0 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php(41): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON('Malformed UTF-8...')\n#1 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\API\\ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)\n#2 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\API\\ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)\n#3 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Debug\\ExceptionHandler.php(78): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)\n#4 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Debug\\Exceptions.php(147): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(DomainException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)\n#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(DomainException))\n#6 {main}\n  thrown\n【Previous Exception】\nCodeIgniter\\Shield\\Exceptions\\LogicException\nCannot decode JWT: Syntax error, malformed JSON\n#0 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\shield\\src\\Authentication\\JWT\\JWSDecoder.php(31): CodeIgniter\\Shield\\Authentication\\JWT\\Adapters\\FirebaseAdapter->decode('yJ0eXAiOiJKV1Qi...', 'default')\n#1 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\shield\\src\\Authentication\\JWTManager.php(83): CodeIgniter\\Shield\\Authentication\\JWT\\JWSDecoder->decode('yJ0eXAiOiJKV1Qi...', 'default')\n#2 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\shield\\src\\Authentication\\Authenticators\\JWT.php(153): CodeIgniter\\Shield\\Authentication\\JWTManager->parse('yJ0eXAiOiJKV1Qi...', 'default')\n#3 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\shield\\src\\Authentication\\Authenticators\\JWT.php(73): CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT->check(Array)\n#4 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\shield\\src\\Filters\\JWTAuth.php(43): CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT->attempt(Array)\n#5 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Filters\\Filters.php(182): CodeIgniter\\Shield\\Filters\\JWTAuth->before(Object(CodeIgniter\\HTTP\\IncomingRequest), NULL)\n#6 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php(466): CodeIgniter\\Filters\\Filters->run('', 'before')\n#7 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php(353): CodeIgniter\\CodeIgniter->handleRequest(NULL, Object(Config\\Cache), false)\n#8 C:\\Users\\telo\\cijwt\\public\\index.php(79): CodeIgniter\\CodeIgniter->run()\n#9 C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Commands\\Server\\rewrite.php(47): require_once('C:\\\\Users\\\\telo\\\\c...')\n#10 {main}",
    "file": "C:\\Users\\telo\\cijwt\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php",
    "line": 41,
    "trace": [
        {
            "function": "shutdownHandler",
            "class": "CodeIgniter\\Debug\\Exceptions",
            "type": "->",
            "args": []
        }
    ]
}




[url=https://codeigniter4.github.io/shield/addons/jwt/][/url]
Reply
#2

Because the Exception is different.
Reply
#3

(09-19-2023, 12:57 AM)kenjis Wrote: Because the Exception is different.

thanks, then I should make my own filter, to check whether the jwt token format is correct
Reply
#4

However, it is not good to have a LogicException generated by an illegal token from a user, so it should be fixed.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB