From ebfb8852b42a53b42aa0bb861490ba971cc82be1 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 19 Jul 2023 16:15:13 -0300 Subject: [PATCH] Bug 34313: Add patron information in pass validation response This patch makes the password validation response return the following patron attributes to the API consumer: * cardnumber * userid This will give hints on what was used to validate in the fallback bahvior the endpoint has. To test: 1. Apply the unit tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/password_validation.t => FAIL: The endpoint doesn't return this valuable data 3. Apply this patch 4. Repeat 2 => SUCESS: Tests pass! We got the cardnumber and the userid! 5. Sign off :-D --- Koha/REST/V1/Auth/Password.pm | 10 ++++++++-- api/v1/swagger/paths/auth.yaml | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Auth/Password.pm b/Koha/REST/V1/Auth/Password.pm index 3f421a7eddc..10baa483bbf 100644 --- a/Koha/REST/V1/Auth/Password.pm +++ b/Koha/REST/V1/Auth/Password.pm @@ -65,7 +65,7 @@ sub validate { my $password = $body->{password} // ""; return try { - my ( $status, $cardnumber, $userid ) = C4::Auth::checkpw( $identifier, $password ); + my ( $status, $THE_cardnumber, $THE_userid ) = C4::Auth::checkpw( $identifier, $password ); unless ($status) { return $c->render( status => 400, @@ -73,7 +73,13 @@ sub validate { ); } - return $c->render( status => 204, openapi => '' ); + return $c->render( + status => 201, + openapi => { + cardnumber => $THE_cardnumber, + userid => $THE_userid, + } + ); } catch { if ( blessed $_ and $_->isa('Koha::Exceptions::Password') ) { diff --git a/api/v1/swagger/paths/auth.yaml b/api/v1/swagger/paths/auth.yaml index 3b61a220133..c7af578f27a 100644 --- a/api/v1/swagger/paths/auth.yaml +++ b/api/v1/swagger/paths/auth.yaml @@ -1091,8 +1091,18 @@ produces: - application/json responses: - "204": + "201": description: Validation successful + schema: + type: object + properties: + cardnumber: + type: string + description: cardnumber for the validated patron + userid: + type: string + description: userid for the validated patron + additionalProperties: false "400": description: Bad request schema: -- 2.41.0