From 8b1e8f80baa37cc8892d44ab10e1ea882a773ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Mon, 24 Aug 2026 14:57:28 -0300 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize Signed-off-by: Pedro Amorim --- Koha/Auth/Client/OAuth.pm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Koha/Auth/Client/OAuth.pm b/Koha/Auth/Client/OAuth.pm index 618b76162a..6ae980d398 100644 --- a/Koha/Auth/Client/OAuth.pm +++ b/Koha/Auth/Client/OAuth.pm @@ -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};