Bug 43375: Use Mojo json() with form-data fallback for userinfo parsing

This patch simplifies the userinfo response parsing by relying on
Mojo::Message::Response->json which decodes JSON regardless of
Content-Type header parameters. If JSON decoding fails (returns undef),
it falls back to URL-encoded form data parsing.

This fixes integration with APIs that return extra Content-Type
parameters (e.g. Microsoft Graph returns odata.metadata,
odata.streaming, and IEEE754Compatible alongside charset) which
previously caused the strict regex to fail and silently misparse
the response as form data.

Test plan:
1. Apply the regression test (previous patch)
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> FAIL: Subtest fails - Content-Type with extra params not recognized
3. Apply this patch
4. Repeat step 2
=> SUCCESS: All tests pass
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Tomás Cohen Arazi 2026-08-24 14:57:28 -03:00 committed by Pedro Amorim
parent 63ffc0b28f
commit 8b1e8f80ba
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 1 additions and 4 deletions

View File

@ -82,10 +82,7 @@ sub _get_data_and_patron {
my $code = $tx->res->code || 'No response';
return if $code ne '200';
my $claim =
$tx->res->headers->content_type =~ m!^(application/json|text/javascript)(;\s*charset=\S+)?$!
? $tx->res->json
: Mojo::Parameters->new( $tx->res->body )->to_hash;
my $claim = $tx->res->json // Mojo::Parameters->new( $tx->res->body )->to_hash;
foreach my $key ( keys %$mapping ) {
my $pkey = $mapping->{$key};