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

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2023-07-19 16:15:13 -03:00
parent eeef7839fb
commit 749783debf
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 26 additions and 5 deletions

View file

@ -71,7 +71,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,
@ -79,9 +79,17 @@ sub validate {
);
}
return $c->render( status => 204, openapi => '' );
}
catch {
my $patron = Koha::Patrons->find( { cardnumber => $THE_cardnumber } );
return $c->render(
status => 201,
openapi => {
cardnumber => $patron->cardnumber,
patron_id => $patron->id,
userid => $patron->userid,
}
);
} catch {
if ( blessed $_ and $_->isa('Koha::Exceptions::Password') ) {
return $c->render(
status => 400,

View file

@ -1091,8 +1091,21 @@
produces:
- application/json
responses:
"204":
"201":
description: Validation successful
schema:
type: object
properties:
cardnumber:
type: string
description: cardnumber for the validated patron
patron_id:
type: integer
description: Internal patron identifier
userid:
type: string
description: userid for the validated patron
additionalProperties: false
"400":
description: Bad request
schema: