-
-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error while decoding from JSON #681
Comments
That usually happens when your input string is not JSON: jwt/src/Encoding/JoseEncoder.php Lines 25 to 43 in f7c9bb1
The library is correctly throwing an exception here. |
Ok but my JSON didn't change 🤨 |
@cyrilbosson can the string you are trying to encode (with 3.x) be posted here (as in no NDA'd secrets)? Can you perhaps provide a full JWT token string? Can you try looking at it on https://jwt.io/ ? Also, I wonder if some of the fields you are trying to encode contain non-utf8 characters (which leads to |
The JSON response : { |
@cyrilbosson I cannot reproduce your issue using the latest version of the lib and the token in the <?php
declare(strict_types=1);
use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Token\Parser;
use Lcobucci\JWT\UnencryptedToken;
require 'vendor/autoload.php';
$token = (new Parser(new JoseEncoder()))->parse(
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiNDIyZDUyNTRkNWZjZTM5OWFhNThhYWU5ZGJmZDBmNTUwM2JiOWQ4OTgwYTcwNzJjZDk5NTcyMTg1NzcwODYyZjZhNDUwNTQ2ZTIyNjk4ZjUiLCJpYXQiOjE2MTM1ODE2OTQsIm5iZiI6MTYxMzU4MTY5NCwiZXhwIjoxNjQ1MTE3Njk0LCJzdWIiOiI1OSIsInNjb3BlcyI6W119.nNA0Uz9uLptDAJ57rmnYnoP80bp2eGlqPbv3jkANGgXLPm1W8GxibEyKMivzgg_7U5I4D5_IB19OR9ESTg_tNUztBydFSNsYnmsxuQxiH3cKt-1-JzeVyYORUhk1cPPlKp7g_s3hZxSWjCwtmeYdfitpvA7MvVhZfLCZG1UC5ukrrCrsM84_itdb5QFNGL6RwXPwBDGzdVHLX9MaBgB4oL6K_QtfauW6ki2TracqzTYtzCbTGSnVVSR5yFBnnzXd_uyx0schZneLSEQRUOlfI1P4LRhvn_dfzMfHQ8GMZEpuoHrPPnioQym8EV5lXmWzfC2TKi0nV1W89e-_W8apWchFtIDeg6wpRCNiGgMUomz4bPpCxUH13XSJIzELFSWCehH4dZcvnAW-K9788H3UExgCc5hQlcKdIONlWLUlAvWLNR58huaFA1TAcLfiuv3Xjjv4G9ihmdo47dtDlyWpsXlCZE56HycKZwwCC0_F49ws9C4ZsrbCYk1Cq5-gY_55ruqfTURk0pNVwFg9bxiHQrHcxDChvnotmWi9NYmBBYrETYGP4DYrOH4_k1CHJwn3GRpW9ma8XTL75M3Ejl5DWduZnS1Yk_d59g-d5EmS6862_giyWMATuStufnpibgLT8jaViuQ2TfcEVArijS07KKk7IJADavXgPh6ZAFECDC8'
);
var_dump($token instanceof UnencryptedToken); // bool(true) Can you provide more information or check if your application is sending the JWT properly to the parser? |
I am facing similar error. Its working fine in other dedicated server but not in Shared Hosting. My Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOiIxNjIwNjIxMjY4LjI2Mzc3MCIsImV4cCI6IjE2MjA2MjEzMjguMjYzNzcwIiwiaWQiOjEsInJvbGUiOiJhZG1pbiJ9.K2VEqI5XnHMf-Je4iYh857GgXhs2z9AmlnvvJhjbRUw Error
My Code to parse the token.
can you help me ? |
I can see this in your trace:
json_decode('ZXlKMGVYQWlPaUp
You aren't decoding JSON there?
…On Mon, May 10, 2021, 08:54 Amrish Kakadiya ***@***.***> wrote:
I am facing similar error. Its working fine in other dedicated server but
not in Shared Hosting.
Code and even project is same in both server.
My Token:
*eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOiIxNjIwNjIxMjY4LjI2Mzc3MCIsImV4cCI6IjE2MjA2MjEzMjguMjYzNzcwIiwiaWQiOjEsInJvbGUiOiJhZG1pbiJ9.K2VEqI5XnHMf-Je4iYh857GgXhs2z9AmlnvvJhjbRUw*
*Error*
throwable JsonException: Syntax error in /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Encoding/JoseEncoder.php:39
Stack trace:
#0 /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Encoding/JoseEncoder.php(39): json_decode('ZXlKMGVYQWlPaUp...', true, 512, 4194304)
#1 /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Token/Parser.php(67): Lcobucci\JWT\Encoding\JoseEncoder->jsonDecode('ZXlKMGVYQWlPaUp...')
#2 /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Token/Parser.php(30): Lcobucci\JWT\Token\Parser->parseHeader('eyJ0eXAiOiJKV1Q...')
#3 /home/smartmpsco/public_html/cust/rms/api/app/Http/Middleware/ParseToken.php(41): Lcobucci\JWT\Token\Parser->parse('eyJ0eXAiOiJKV1Q...')
#4 /home/smartmpsco/public_html/cust/rms/api/vendor/illuminate/pipeline/Pipeline.php(167): App\Http\Middleware\ParseToken->handle(Object(Laravel\Lumen\Http\Request), Object(Closure))
#5 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Laravel\Lumen\Http\Request))
#6 /home/smartmpsco/public_html/cust/rms/api/app/Http/Middleware/CorsMiddleware.php(60): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Laravel\Lumen\Http\Request))
#7 /home/smartmpsco/public_html/cust/rms/api/vendor/illuminate/pipeline/Pipeline.php(167): App\Http\Middleware\CorsMiddleware->handle(Object(Laravel\Lumen\Http\Request), Object(Closure))
#8 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Laravel\Lumen\Http\Request))
#9 /home/smartmpsco/public_html/cust/rms/api/vendor/illuminate/pipeline/Pipeline.php(103): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Laravel\Lumen\Http\Request))
#10 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(423): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(172): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#12 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(109): Laravel\Lumen\Application->dispatch(NULL)
#13 /home/smartmpsco/public_html/cust/rms/api/public/index.php(28): Laravel\Lumen\Application->run()
#14 {main}
Next Lcobucci\JWT\Encoding\CannotDecodeContent: Error while decoding from JSON in /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Encoding/CannotDecodeContent.php:14
Stack trace:
#0 /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Encoding/JoseEncoder.php(41): Lcobucci\JWT\Encoding\CannotDecodeContent::jsonIssues(Object(JsonException))
#1 /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Token/Parser.php(67): Lcobucci\JWT\Encoding\JoseEncoder->jsonDecode('ZXlKMGVYQWlPaUp...')
#2 /home/smartmpsco/public_html/cust/rms/api/vendor/lcobucci/jwt/src/Token/Parser.php(30): Lcobucci\JWT\Token\Parser->parseHeader('eyJ0eXAiOiJKV1Q...')
#3 /home/smartmpsco/public_html/cust/rms/api/app/Http/Middleware/ParseToken.php(41): Lcobucci\JWT\Token\Parser->parse('eyJ0eXAiOiJKV1Q...')
#4 /home/smartmpsco/public_html/cust/rms/api/vendor/illuminate/pipeline/Pipeline.php(167): App\Http\Middleware\ParseToken->handle(Object(Laravel\Lumen\Http\Request), Object(Closure))
#5 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Laravel\Lumen\Http\Request))
#6 /home/smartmpsco/public_html/cust/rms/api/app/Http/Middleware/CorsMiddleware.php(60): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Laravel\Lumen\Http\Request))
#7 /home/smartmpsco/public_html/cust/rms/api/vendor/illuminate/pipeline/Pipeline.php(167): App\Http\Middleware\CorsMiddleware->handle(Object(Laravel\Lumen\Http\Request), Object(Closure))
#8 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Laravel\Lumen\Http\Request))
#9 /home/smartmpsco/public_html/cust/rms/api/vendor/illuminate/pipeline/Pipeline.php(103): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Laravel\Lumen\Http\Request))
#10 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(423): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(172): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#12 /home/smartmpsco/public_html/cust/rms/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(109): Laravel\Lumen\Application->dispatch(NULL)
#13 /home/smartmpsco/public_html/cust/rms/api/public/index.php(28): Laravel\Lumen\Application->run()
#14 {main}
My Code to parse the token.
$aToken =
$aConfig->parser()->parse(Crypt::decrypt($req->header('x-token')));
can you help me ?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#681 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABFVEBWRT3PB3Q27SANRBTTM57JBANCNFSM4XYW2RJA>
.
|
no, its working in other server(nginx). I am passing raw string to parse which is stated in Documentation. |
I can clearly see this:
That means that gibberish is passed to JSON decoding logic :-) The exception is just the symptom. Locking this thread: please do write an integration test about your use-case, before reporting a new issue with a reproducible scenario. |
Is it possible that a bug in libsodium is the thing to blame here? That's the only explanation I have for it to fail on specific servers only. @Slamdunk have you experienced something like this? |
@amrishkakadiya can you run the following code on both the new and old servers: <?php
$headers = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9';
var_dump(
base64_decode(strtr($headers, '-_', '+/'), true),
sodium_base642bin($headers, 7, '')
); |
Dedicated server response and Shared Server respone So is it because of Sodium extenstion? |
|
Is there any way to install in Shared Hosting usign Cpanel without terminal access? |
@amrishkakadiya sorry but I can't help you with that, it's been ages since I last used shared hosting. Try contacting them. It's also important to note that copying |
Locking here as we discovered it's not related to the lib itself but the environment in which the library runs. |
Hello,
I had this issue on my hosting server so I upgraded to 4.1.1 but now I have this error:
Error while decoding from JSON
Stacktrace
/home/clients/9ec8ad5583918ce55944b1cc6bdd9057/web/releases/95/vendor/lcobucci/jwt/src/Encoding/JoseEncoder.php:41 /home/clients/9ec8ad5583918ce55944b1cc6bdd9057/web/releases/95/vendor/lcobucci/jwt/src/Token/Parser.php:67 /home/clients/9ec8ad5583918ce55944b1cc6bdd9057/web/releases/95/vendor/lcobucci/jwt/src/Token/Parser.php:30
I use it with Laravel 8.28.1 & Telescope 10.1.0
PHP 7.4.15
Thanks !
The text was updated successfully, but these errors were encountered: