View | Details | Raw Unified | Return to bug 17004
Collapse All | Expand All

(-)a/Koha/REST/V1/Auth.pm (+101 lines)
Line 0 Link Here
1
package Koha::REST::V1::Auth;
2
3
# Copyright 2016 Koha-Suomi
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Mojo::Base 'Mojolicious::Controller';
23
24
use Koha::Patrons;
25
use C4::Auth;
26
27
use CGI;
28
29
sub login {
30
    my ($c, $args, $cb) = @_;
31
32
    my $userid = $args->{userid} || $args->{cardnumber};
33
    my $password = $args->{password};
34
    my $patron;
35
36
    return $c->$cb({ error => "Either userid or cardnumber is required "
37
                             ."- neither given." }, 403) unless ($userid);
38
39
    my $cgi = CGI->new;
40
    $cgi->param(userid => $userid);
41
    $cgi->param(password => $password);
42
    my ($status, $cookie, $sessionid) = C4::Auth::check_api_auth($cgi);
43
44
    return $c->$cb({ error => "Login failed." }, 401) if $status eq "failed";
45
    return $c->$cb({ error => "Session expired." }, 401) if $status eq "expired";
46
    return $c->$cb({ error => "Database is under maintenance." }, 401) if $status eq "maintenance";
47
    return $c->$cb({ error => "Login failed." }, 401) unless $status eq "ok";
48
49
    $patron = Koha::Patrons->find({ userid => $userid }) unless $patron;
50
    $patron = Koha::Patrons->find({ cardnumber => $userid }) unless $patron;
51
52
    my $session = _swaggerize_session($sessionid, $patron);
53
54
    $c->cookie(CGISESSID => $sessionid, { path => "/" });
55
56
    return $c->$cb($session, 201);
57
}
58
59
sub logout {
60
    my ($c, $args, $cb) = @_;
61
62
    my $sessionid = $args->{session}->{sessionid};
63
    $sessionid = $c->cookie('CGISESSID') unless $sessionid;
64
65
    my ($status, $sid) = C4::Auth::check_cookie_auth($sessionid);
66
    unless ($status eq "ok") {
67
        return $c->$cb({ error => "Invalid session id."}, 401);
68
    }
69
70
    $c->cookie(CGISESSID => $sessionid, { path => "/", expires => 1 });
71
72
    my $session = C4::Auth::get_session($sessionid);
73
    $session->delete;
74
    $session->flush;
75
    return $c->$cb({}, 200);
76
}
77
78
sub _swaggerize_session {
79
    my ($sessionid, $patron) = @_;
80
81
    return unless ref($patron) eq 'Koha::Patron';
82
83
    my $rawPermissions = C4::Auth::haspermission($patron->userid); # defaults to all permissions
84
    my @permissions;
85
86
    # delete all empty permissions
87
    while ( my ($key, $val) = each %{$rawPermissions} ) {
88
        push @permissions, $key if $val;
89
    }
90
91
    return {
92
        borrowernumber => $patron->borrowernumber,
93
        firstname => $patron->firstname,
94
        surname  => $patron->surname,
95
        email     => $patron->email,
96
        sessionid => $sessionid,
97
	permissions => \@permissions,
98
    };
99
}
100
101
1;
(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 1-4 Link Here
1
{
1
{
2
  "session": {
3
    "$ref": "definitions/session.json"
4
  },
2
  "patron": {
5
  "patron": {
3
    "$ref": "definitions/patron.json"
6
    "$ref": "definitions/patron.json"
4
  },
7
  },
(-)a/api/v1/swagger/definitions/session.json (+32 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "borrowernumber": {
5
      "type": "string",
6
      "description": "internally assigned user identifier"
7
    },
8
    "email": {
9
      "type": ["string", "null"],
10
      "description": "primary email address for patron's primary address"
11
    },
12
    "surname": {
13
      "type": "string",
14
      "description": "patron's last name"
15
    },
16
    "firstname": {
17
      "type": ["string", "null"],
18
      "description": "patron's first name"
19
    },
20
    "sessionid": {
21
      "description": "Koha Session identifier",
22
      "type": "string"
23
    },
24
    "permissions": {
25
      "description": "patron's permissions",
26
      "type": "array",
27
      "items": {
28
        "type": "string"
29
      }
30
    }
31
  }
32
}
(-)a/api/v1/swagger/definitions/sessionid.json (+10 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "sessionid": {
5
      "description": "The Koha sessionid",
6
      "type": "string"
7
    }
8
  },
9
  "required": ["sessionid"]
10
}
(-)a/api/v1/swagger/parameters.json (+12 lines)
Lines 7-11 Link Here
7
  },
7
  },
8
  "holdIdPathParam": {
8
  "holdIdPathParam": {
9
    "$ref": "parameters/hold.json#/holdIdPathParam"
9
    "$ref": "parameters/hold.json#/holdIdPathParam"
10
  },
11
  "cardnumberPostParam": {
12
    "$ref": "parameters/auth.json#/cardnumberPostParam"
13
  },
14
  "passwordPostParam": {
15
   "$ref": "parameters/auth.json#/passwordPostParam"
16
  },
17
  "useridPostParam": {
18
   "$ref": "parameters/auth.json#/useridPostParam"
19
  },
20
  "sessionidBodyParam": {
21
   "$ref": "parameters/auth.json#/sessionidBodyParam"
10
  }
22
  }
11
}
23
}
(-)a/api/v1/swagger/parameters/auth.json (+31 lines)
Line 0 Link Here
1
{
2
  "cardnumberPostParam": {
3
    "name": "cardnumber",
4
    "in": "formData",
5
    "description": "Borrower's card's barcode/identifier",
6
    "required": false,
7
    "type": "string"
8
  },
9
  "passwordPostParam": {
10
    "name": "password",
11
    "in": "formData",
12
    "required": true,
13
    "type": "string"
14
  },
15
  "useridPostParam": {
16
    "name": "userid",
17
    "in": "formData",
18
    "description": "The userid of the Borrower, unique value",
19
    "required": false,
20
    "type": "string"
21
  },
22
  "sessionidBodyParam": {
23
    "name": "session",
24
    "description": "The CGISESSID Cookie used to authenticate a session",
25
    "in": "body",
26
    "required": false,
27
    "schema" : {
28
      "$ref": "../definitions/sessionid.json"
29
    }
30
  }
31
}
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 1-4 Link Here
1
{
1
{
2
  "/auth/session": {
3
    "$ref": "paths/auth.json#/~1auth~1session"
4
  },
2
  "/holds": {
5
  "/holds": {
3
    "$ref": "paths/holds.json#/~1holds"
6
    "$ref": "paths/holds.json#/~1holds"
4
  },
7
  },
(-)a/api/v1/swagger/paths/auth.json (+58 lines)
Line 0 Link Here
1
{
2
  "/auth/session": {
3
    "post": {
4
      "operationId": "loginAuth",
5
      "tags": ["auth"],
6
      "summary": "Login to Koha and get a session cookie",
7
      "description": "Makes a 'normal' username + password login to Koha, and returns the sessionid you need put to the CGISESSID-cookie. Koha uses this cookie to track a session.\nBe aware that the authenticated session most probably is IP-locked so authenticating from one IP and passing the session to another wont work.",
8
      "parameters": [
9
        { "$ref": "../parameters.json#/cardnumberPostParam" },
10
        { "$ref": "../parameters.json#/useridPostParam" },
11
        { "$ref": "../parameters.json#/passwordPostParam" }
12
      ],
13
      "produces": [
14
        "application/json"
15
      ],
16
      "responses": {
17
        "201": {
18
          "description": "A borrower with SSO-relevant fields",
19
          "schema": {
20
            "$ref": "../definitions.json#/session"
21
          }
22
        },
23
        "401": {
24
          "description": "Bad username/cardnumber and/or password",
25
          "schema": {
26
            "$ref": "../definitions.json#/error"
27
          }
28
        }
29
      }
30
    },
31
    "delete": {
32
      "operationId": "logoutAuth",
33
      "tags": ["auth"],
34
      "summary": "Logout from Koha.",
35
      "description": "Logouts user from Koha by marking session as expired. sessionid is optional, if not given, logs out currently logged in user",
36
      "parameters": [
37
        { "$ref": "../parameters.json#/sessionidBodyParam" }
38
      ],
39
      "produces": [
40
        "application/json"
41
      ],
42
      "responses": {
43
        "200": {
44
          "description": "Successfully logged out",
45
          "schema": {
46
            "type": "object"
47
          }
48
        },
49
        "401": {
50
          "description": "Bad session id",
51
          "schema": {
52
            "$ref": "../definitions.json#/error"
53
          }
54
        }
55
      }
56
    }
57
  }
58
}
(-)a/api/v1/swagger/swagger.min.json (-1 / +1 lines)
Line 1 Link Here
1
{"definitions":{"error":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"},"hold":{"properties":{"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"expirationdate":{"description":"the date the hold expires"},"reservedate":{"description":"the date the hold was placed"},"priority":{"description":"where in the queue the patron sits"},"biblionumber":{"type":"string","description":"internally assigned biblio identifier"},"branchcode":{"type":["string","null"],"description":"internally assigned branch identifier"},"reservenotes":{"description":"notes related to this hold"},"reminderdate":{"description":"currently unused"},"lowestPriority":{"description":""},"timestamp":{"description":"date and time the hold was last updated"},"cancellationdate":{"description":"the date the hold was cancelled"},"suspend":{"description":""},"itemnumber":{"type":["string","null"],"description":"internally assigned item identifier"},"suspend_until":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"notificationdate":{"description":"currently unused"}},"type":"object"},"holds":{"type":"array","items":{"type":"object","properties":{"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"expirationdate":{"description":"the date the hold expires"},"reservedate":{"description":"the date the hold was placed"},"priority":{"description":"where in the queue the patron sits"},"biblionumber":{"type":"string","description":"internally assigned biblio identifier"},"branchcode":{"type":["string","null"],"description":"internally assigned branch identifier"},"reservenotes":{"description":"notes related to this hold"},"reminderdate":{"description":"currently unused"},"lowestPriority":{"description":""},"timestamp":{"description":"date and time the hold was last updated"},"cancellationdate":{"description":"the date the hold was cancelled"},"suspend":{"description":""},"itemnumber":{"type":["string","null"],"description":"internally assigned item identifier"},"suspend_until":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"notificationdate":{"description":"currently unused"}}}},"patron":{"properties":{"gonenoaddress":{"type":["string","null"],"description":"set to 1 if library marked this patron as having an unconfirmed address"},"address":{"type":"string","description":"first address line of patron's primary address"},"streetnumber":{"description":"street number of patron's primary address","type":["string","null"]},"sort1":{"type":["string","null"],"description":"a field that can be used for any information unique to the library"},"lost":{"description":"set to 1 if library marked this patron as having lost his card","type":["string","null"]},"altcontactcountry":{"type":["string","null"],"description":"the country for the alternate contact for the patron"},"B_state":{"type":["string","null"],"description":"state or province of patron's alternate address"},"altcontactstate":{"description":"the state for the alternate contact for the patron","type":["string","null"]},"mobile":{"type":["string","null"],"description":"the other phone number for patron's primary address"},"B_address2":{"type":["string","null"],"description":"second address line of patron's alternate address"},"B_zipcode":{"description":"zip or postal code of patron's alternate address","type":["string","null"]},"fax":{"type":["string","null"],"description":"fax number for patron's primary address"},"city":{"type":"string","description":"city or town of patron's primary address"},"sex":{"type":["string","null"],"description":"patron's gender"},"categorycode":{"type":"string","description":"code of patron's category"},"relationship":{"description":"used for children to include the relationship to their guarantor","type":["string","null"]},"sort2":{"description":"a field that can be used for any information unique to the library","type":["string","null"]},"email":{"description":"primary email address for patron's primary address","type":["string","null"]},"title":{"type":["string","null"],"description":"patron's title"},"streettype":{"type":["string","null"],"description":"street type of patron's primary address"},"B_phone":{"type":["string","null"],"description":"phone number for patron's alternate address"},"contactnote":{"description":"a note related to patron's alternate address","type":["string","null"]},"password":{"description":"patron's encrypted password","type":["string","null"]},"altcontactphone":{"type":["string","null"],"description":"the phone number for the alternate contact for the patron"},"sms_provider_id":{"description":"the provider of the mobile phone number defined in smsalertnumber","type":["string","null"]},"B_country":{"type":["string","null"],"description":"country of patron's alternate address"},"dateexpiry":{"type":["string","null"],"description":"date the patron's card is set to expire"},"updated_on":{"type":"string","description":"time of last change could be useful for synchronization with external systems (among others)"},"contactfirstname":{"type":["string","null"],"description":"used for children to include first name of guarantor"},"surname":{"description":"patron's last name","type":"string"},"othernames":{"type":["string","null"],"description":"any other names associated with the patron"},"country":{"type":["string","null"],"description":"country of patron's primary address"},"B_streetnumber":{"type":["string","null"],"description":"street number of patron's alternate address"},"phonepro":{"description":"secondary phone number for patron's primary address","type":["string","null"]},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"guarantorid":{"type":["string","null"],"description":"borrowernumber used for children or professionals to link them to guarantor or organizations"},"altcontactzipcode":{"description":"the zipcode for the alternate contact for the patron","type":["string","null"]},"altcontactsurname":{"description":"surname or last name of the alternate contact for the patron","type":["string","null"]},"zipcode":{"type":["string","null"],"description":"zip or postal code of patron's primary address"},"contactname":{"type":["string","null"],"description":"used for children and professionals to include surname or last name of guarantor or organization name"},"emailpro":{"description":"secondary email address for patron's primary address","type":["string","null"]},"borrowernotes":{"type":["string","null"],"description":"a note on the patron's account"},"B_streettype":{"type":["string","null"],"description":"street type of patron's alternate address"},"smsalertnumber":{"description":"the mobile phone number where the patron would like to receive notices (if SMS turned on)","type":["string","null"]},"state":{"type":["string","null"],"description":"state or province of patron's primary address"},"altcontactfirstname":{"type":["string","null"],"description":"first name of alternate contact for the patron"},"address2":{"type":["string","null"],"description":"second address line of patron's primary address"},"debarredcomment":{"type":["string","null"],"description":"comment on the stop of the patron"},"B_email":{"type":["string","null"],"description":"email address for patron's alternate address"},"B_address":{"description":"first address line of patron's alternate address","type":["string","null"]},"branchcode":{"type":"string","description":"code of patron's home branch"},"userid":{"type":["string","null"],"description":"patron's login"},"altcontactaddress1":{"description":"the first address line for the alternate contact for the patron","type":["string","null"]},"debarred":{"type":["string","null"],"description":"until this date the patron can only check-in"},"privacy_guarantor_checkouts":{"type":"string","description":"controls if relatives can see this patron's checkouts"},"contacttitle":{"type":["string","null"],"description":"used for children to include title of guarantor"},"privacy":{"description":"patron's privacy settings related to their reading history","type":"string"},"flags":{"description":"a number associated with the patron's permissions","type":["string","null"]},"dateofbirth":{"description":"patron's date of birth","type":["string","null"]},"checkprevcheckout":{"description":"produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'","type":"string"},"initials":{"type":["string","null"],"description":"initials of the patron"},"B_city":{"type":["string","null"],"description":"city or town of patron's alternate address"},"cardnumber":{"type":["string","null"],"description":"library assigned user identifier"},"altcontactaddress3":{"description":"the city for the alternate contact for the patron","type":["string","null"]},"phone":{"description":"primary phone number for patron's primary address","type":["string","null"]},"altcontactaddress2":{"type":["string","null"],"description":"the second address line for the alternate contact for the patron"},"firstname":{"type":["string","null"],"description":"patron's first name"},"dateenrolled":{"description":"date the patron was added to Koha","type":["string","null"]},"opacnote":{"description":"a note on the patron's account visible in OPAC and staff client","type":["string","null"]}},"type":"object"}},"paths":{"\/patrons\/{borrowernumber}":{"get":{"operationId":"getPatron","tags":["patrons"],"produces":["application\/json"],"parameters":[{"description":"Internal patron identifier","type":"integer","required":true,"in":"path","name":"borrowernumber"}],"responses":{"404":{"description":"Patron not found","schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}}},"200":{"schema":{"type":"object","properties":{"gonenoaddress":{"type":["string","null"],"description":"set to 1 if library marked this patron as having an unconfirmed address"},"address":{"type":"string","description":"first address line of patron's primary address"},"streetnumber":{"description":"street number of patron's primary address","type":["string","null"]},"sort1":{"type":["string","null"],"description":"a field that can be used for any information unique to the library"},"lost":{"description":"set to 1 if library marked this patron as having lost his card","type":["string","null"]},"altcontactcountry":{"type":["string","null"],"description":"the country for the alternate contact for the patron"},"B_state":{"type":["string","null"],"description":"state or province of patron's alternate address"},"altcontactstate":{"description":"the state for the alternate contact for the patron","type":["string","null"]},"mobile":{"type":["string","null"],"description":"the other phone number for patron's primary address"},"B_address2":{"type":["string","null"],"description":"second address line of patron's alternate address"},"B_zipcode":{"description":"zip or postal code of patron's alternate address","type":["string","null"]},"fax":{"type":["string","null"],"description":"fax number for patron's primary address"},"city":{"type":"string","description":"city or town of patron's primary address"},"sex":{"type":["string","null"],"description":"patron's gender"},"categorycode":{"type":"string","description":"code of patron's category"},"relationship":{"description":"used for children to include the relationship to their guarantor","type":["string","null"]},"sort2":{"description":"a field that can be used for any information unique to the library","type":["string","null"]},"email":{"description":"primary email address for patron's primary address","type":["string","null"]},"title":{"type":["string","null"],"description":"patron's title"},"streettype":{"type":["string","null"],"description":"street type of patron's primary address"},"B_phone":{"type":["string","null"],"description":"phone number for patron's alternate address"},"contactnote":{"description":"a note related to patron's alternate address","type":["string","null"]},"password":{"description":"patron's encrypted password","type":["string","null"]},"altcontactphone":{"type":["string","null"],"description":"the phone number for the alternate contact for the patron"},"sms_provider_id":{"description":"the provider of the mobile phone number defined in smsalertnumber","type":["string","null"]},"B_country":{"type":["string","null"],"description":"country of patron's alternate address"},"dateexpiry":{"type":["string","null"],"description":"date the patron's card is set to expire"},"updated_on":{"type":"string","description":"time of last change could be useful for synchronization with external systems (among others)"},"contactfirstname":{"type":["string","null"],"description":"used for children to include first name of guarantor"},"surname":{"description":"patron's last name","type":"string"},"othernames":{"type":["string","null"],"description":"any other names associated with the patron"},"country":{"type":["string","null"],"description":"country of patron's primary address"},"B_streetnumber":{"type":["string","null"],"description":"street number of patron's alternate address"},"phonepro":{"description":"secondary phone number for patron's primary address","type":["string","null"]},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"guarantorid":{"type":["string","null"],"description":"borrowernumber used for children or professionals to link them to guarantor or organizations"},"altcontactzipcode":{"description":"the zipcode for the alternate contact for the patron","type":["string","null"]},"altcontactsurname":{"description":"surname or last name of the alternate contact for the patron","type":["string","null"]},"zipcode":{"type":["string","null"],"description":"zip or postal code of patron's primary address"},"contactname":{"type":["string","null"],"description":"used for children and professionals to include surname or last name of guarantor or organization name"},"emailpro":{"description":"secondary email address for patron's primary address","type":["string","null"]},"borrowernotes":{"type":["string","null"],"description":"a note on the patron's account"},"B_streettype":{"type":["string","null"],"description":"street type of patron's alternate address"},"smsalertnumber":{"description":"the mobile phone number where the patron would like to receive notices (if SMS turned on)","type":["string","null"]},"state":{"type":["string","null"],"description":"state or province of patron's primary address"},"altcontactfirstname":{"type":["string","null"],"description":"first name of alternate contact for the patron"},"address2":{"type":["string","null"],"description":"second address line of patron's primary address"},"debarredcomment":{"type":["string","null"],"description":"comment on the stop of the patron"},"B_email":{"type":["string","null"],"description":"email address for patron's alternate address"},"B_address":{"description":"first address line of patron's alternate address","type":["string","null"]},"branchcode":{"type":"string","description":"code of patron's home branch"},"userid":{"type":["string","null"],"description":"patron's login"},"altcontactaddress1":{"description":"the first address line for the alternate contact for the patron","type":["string","null"]},"debarred":{"type":["string","null"],"description":"until this date the patron can only check-in"},"privacy_guarantor_checkouts":{"type":"string","description":"controls if relatives can see this patron's checkouts"},"contacttitle":{"type":["string","null"],"description":"used for children to include title of guarantor"},"privacy":{"description":"patron's privacy settings related to their reading history","type":"string"},"flags":{"description":"a number associated with the patron's permissions","type":["string","null"]},"dateofbirth":{"description":"patron's date of birth","type":["string","null"]},"checkprevcheckout":{"description":"produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'","type":"string"},"initials":{"type":["string","null"],"description":"initials of the patron"},"B_city":{"type":["string","null"],"description":"city or town of patron's alternate address"},"cardnumber":{"type":["string","null"],"description":"library assigned user identifier"},"altcontactaddress3":{"description":"the city for the alternate contact for the patron","type":["string","null"]},"phone":{"description":"primary phone number for patron's primary address","type":["string","null"]},"altcontactaddress2":{"type":["string","null"],"description":"the second address line for the alternate contact for the patron"},"firstname":{"type":["string","null"],"description":"patron's first name"},"dateenrolled":{"description":"date the patron was added to Koha","type":["string","null"]},"opacnote":{"description":"a note on the patron's account visible in OPAC and staff client","type":["string","null"]}}},"description":"A patron"},"403":{"description":"Access forbidden","schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}}}}}},"\/patrons":{"get":{"tags":["patrons"],"produces":["application\/json"],"responses":{"200":{"schema":{"items":{"properties":{"gonenoaddress":{"type":["string","null"],"description":"set to 1 if library marked this patron as having an unconfirmed address"},"address":{"type":"string","description":"first address line of patron's primary address"},"streetnumber":{"description":"street number of patron's primary address","type":["string","null"]},"sort1":{"type":["string","null"],"description":"a field that can be used for any information unique to the library"},"lost":{"description":"set to 1 if library marked this patron as having lost his card","type":["string","null"]},"altcontactcountry":{"type":["string","null"],"description":"the country for the alternate contact for the patron"},"B_state":{"type":["string","null"],"description":"state or province of patron's alternate address"},"altcontactstate":{"description":"the state for the alternate contact for the patron","type":["string","null"]},"mobile":{"type":["string","null"],"description":"the other phone number for patron's primary address"},"B_address2":{"type":["string","null"],"description":"second address line of patron's alternate address"},"B_zipcode":{"description":"zip or postal code of patron's alternate address","type":["string","null"]},"fax":{"type":["string","null"],"description":"fax number for patron's primary address"},"city":{"type":"string","description":"city or town of patron's primary address"},"sex":{"type":["string","null"],"description":"patron's gender"},"categorycode":{"type":"string","description":"code of patron's category"},"relationship":{"description":"used for children to include the relationship to their guarantor","type":["string","null"]},"sort2":{"description":"a field that can be used for any information unique to the library","type":["string","null"]},"email":{"description":"primary email address for patron's primary address","type":["string","null"]},"title":{"type":["string","null"],"description":"patron's title"},"streettype":{"type":["string","null"],"description":"street type of patron's primary address"},"B_phone":{"type":["string","null"],"description":"phone number for patron's alternate address"},"contactnote":{"description":"a note related to patron's alternate address","type":["string","null"]},"password":{"description":"patron's encrypted password","type":["string","null"]},"altcontactphone":{"type":["string","null"],"description":"the phone number for the alternate contact for the patron"},"sms_provider_id":{"description":"the provider of the mobile phone number defined in smsalertnumber","type":["string","null"]},"B_country":{"type":["string","null"],"description":"country of patron's alternate address"},"dateexpiry":{"type":["string","null"],"description":"date the patron's card is set to expire"},"updated_on":{"type":"string","description":"time of last change could be useful for synchronization with external systems (among others)"},"contactfirstname":{"type":["string","null"],"description":"used for children to include first name of guarantor"},"surname":{"description":"patron's last name","type":"string"},"othernames":{"type":["string","null"],"description":"any other names associated with the patron"},"country":{"type":["string","null"],"description":"country of patron's primary address"},"B_streetnumber":{"type":["string","null"],"description":"street number of patron's alternate address"},"phonepro":{"description":"secondary phone number for patron's primary address","type":["string","null"]},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"guarantorid":{"type":["string","null"],"description":"borrowernumber used for children or professionals to link them to guarantor or organizations"},"altcontactzipcode":{"description":"the zipcode for the alternate contact for the patron","type":["string","null"]},"altcontactsurname":{"description":"surname or last name of the alternate contact for the patron","type":["string","null"]},"zipcode":{"type":["string","null"],"description":"zip or postal code of patron's primary address"},"contactname":{"type":["string","null"],"description":"used for children and professionals to include surname or last name of guarantor or organization name"},"emailpro":{"description":"secondary email address for patron's primary address","type":["string","null"]},"borrowernotes":{"type":["string","null"],"description":"a note on the patron's account"},"B_streettype":{"type":["string","null"],"description":"street type of patron's alternate address"},"smsalertnumber":{"description":"the mobile phone number where the patron would like to receive notices (if SMS turned on)","type":["string","null"]},"state":{"type":["string","null"],"description":"state or province of patron's primary address"},"altcontactfirstname":{"type":["string","null"],"description":"first name of alternate contact for the patron"},"address2":{"type":["string","null"],"description":"second address line of patron's primary address"},"debarredcomment":{"type":["string","null"],"description":"comment on the stop of the patron"},"B_email":{"type":["string","null"],"description":"email address for patron's alternate address"},"B_address":{"description":"first address line of patron's alternate address","type":["string","null"]},"branchcode":{"type":"string","description":"code of patron's home branch"},"userid":{"type":["string","null"],"description":"patron's login"},"altcontactaddress1":{"description":"the first address line for the alternate contact for the patron","type":["string","null"]},"debarred":{"type":["string","null"],"description":"until this date the patron can only check-in"},"privacy_guarantor_checkouts":{"type":"string","description":"controls if relatives can see this patron's checkouts"},"contacttitle":{"type":["string","null"],"description":"used for children to include title of guarantor"},"privacy":{"description":"patron's privacy settings related to their reading history","type":"string"},"flags":{"description":"a number associated with the patron's permissions","type":["string","null"]},"dateofbirth":{"description":"patron's date of birth","type":["string","null"]},"checkprevcheckout":{"description":"produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'","type":"string"},"initials":{"type":["string","null"],"description":"initials of the patron"},"B_city":{"type":["string","null"],"description":"city or town of patron's alternate address"},"cardnumber":{"type":["string","null"],"description":"library assigned user identifier"},"altcontactaddress3":{"description":"the city for the alternate contact for the patron","type":["string","null"]},"phone":{"description":"primary phone number for patron's primary address","type":["string","null"]},"altcontactaddress2":{"type":["string","null"],"description":"the second address line for the alternate contact for the patron"},"firstname":{"type":["string","null"],"description":"patron's first name"},"dateenrolled":{"description":"date the patron was added to Koha","type":["string","null"]},"opacnote":{"description":"a note on the patron's account visible in OPAC and staff client","type":["string","null"]}},"type":"object"},"type":"array"},"description":"A list of patrons"},"403":{"description":"Access forbidden","schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"}}},"operationId":"listPatrons"}},"\/holds":{"post":{"tags":["borrowers","holds"],"produces":["application\/json"],"parameters":[{"schema":{"properties":{"biblionumber":{"type":"integer","description":"Biblio internal identifier"},"branchcode":{"type":"string","description":"Pickup location"},"itemnumber":{"type":"integer","description":"Item internal identifier"},"expirationdate":{"type":"string","description":"Hold end date","format":"date"},"borrowernumber":{"description":"Borrower internal identifier","type":"integer"}},"type":"object"},"description":"A JSON object containing informations about the new hold","name":"body","in":"body","required":true}],"responses":{"403":{"description":"Hold not allowed","schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}}},"404":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Borrower not found"},"400":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Missing or wrong parameters"},"500":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Internal error"},"201":{"description":"Created hold","schema":{"properties":{"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"expirationdate":{"description":"the date the hold expires"},"reservedate":{"description":"the date the hold was placed"},"priority":{"description":"where in the queue the patron sits"},"biblionumber":{"type":"string","description":"internally assigned biblio identifier"},"branchcode":{"type":["string","null"],"description":"internally assigned branch identifier"},"reservenotes":{"description":"notes related to this hold"},"reminderdate":{"description":"currently unused"},"lowestPriority":{"description":""},"timestamp":{"description":"date and time the hold was last updated"},"cancellationdate":{"description":"the date the hold was cancelled"},"suspend":{"description":""},"itemnumber":{"type":["string","null"],"description":"internally assigned item identifier"},"suspend_until":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"notificationdate":{"description":"currently unused"}},"type":"object"}}},"consumes":["application\/json"],"operationId":"addHold"},"get":{"operationId":"listHolds","tags":["borrowers","holds"],"produces":["application\/json"],"parameters":[{"description":"Internal reserve identifier","type":"integer","in":"query","name":"reserve_id"},{"description":"Internal borrower identifier","type":"integer","name":"borrowernumber","in":"query"},{"type":"string","description":"Reserve date","in":"query","name":"reservedate"},{"type":"integer","description":"Internal biblio identifier","in":"query","name":"biblionumber"},{"in":"query","name":"branchcode","description":"Branch code","type":"string"},{"type":"string","description":"Notification date","in":"query","name":"notificationdate"},{"name":"reminderdate","in":"query","type":"string","description":"Reminder date"},{"in":"query","name":"cancellationdate","type":"string","description":"Cancellation date"},{"description":"Reserve notes","type":"string","in":"query","name":"reservenotes"},{"description":"Priority","type":"integer","name":"priority","in":"query"},{"description":"Found status","type":"string","name":"found","in":"query"},{"description":"Time of latest update","type":"string","in":"query","name":"timestamp"},{"type":"integer","description":"Internal item identifier","name":"itemnumber","in":"query"},{"type":"string","description":"Date the item was marked as waiting for the patron","name":"waitingdate","in":"query"},{"description":"Date the hold expires","type":"string","in":"query","name":"expirationdate"},{"description":"Lowest priority","type":"integer","in":"query","name":"lowestPriority"},{"in":"query","name":"suspend","type":"integer","description":"Suspended"},{"name":"suspend_until","in":"query","description":"Suspended until","type":"string"}],"responses":{"404":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Borrower not found"},"200":{"schema":{"type":"array","items":{"type":"object","properties":{"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"expirationdate":{"description":"the date the hold expires"},"reservedate":{"description":"the date the hold was placed"},"priority":{"description":"where in the queue the patron sits"},"biblionumber":{"type":"string","description":"internally assigned biblio identifier"},"branchcode":{"type":["string","null"],"description":"internally assigned branch identifier"},"reservenotes":{"description":"notes related to this hold"},"reminderdate":{"description":"currently unused"},"lowestPriority":{"description":""},"timestamp":{"description":"date and time the hold was last updated"},"cancellationdate":{"description":"the date the hold was cancelled"},"suspend":{"description":""},"itemnumber":{"type":["string","null"],"description":"internally assigned item identifier"},"suspend_until":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"notificationdate":{"description":"currently unused"}}}},"description":"A list of holds"}}}},"\/holds\/{reserve_id}":{"put":{"consumes":["application\/json"],"operationId":"editHold","tags":["holds"],"produces":["application\/json"],"parameters":[{"description":"Internal hold identifier","type":"integer","required":true,"in":"path","name":"reserve_id"},{"name":"body","in":"body","required":true,"schema":{"properties":{"branchcode":{"type":"string","description":"Pickup location"},"suspend_until":{"description":"Suspend until","type":"string","format":"date"},"priority":{"type":"integer","description":"Position in waiting queue","minimum":1}},"type":"object"},"description":"A JSON object containing fields to modify"}],"responses":{"404":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Hold not found"},"400":{"description":"Missing or wrong parameters","schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"}},"200":{"schema":{"type":"object","properties":{"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"},"expirationdate":{"description":"the date the hold expires"},"reservedate":{"description":"the date the hold was placed"},"priority":{"description":"where in the queue the patron sits"},"biblionumber":{"type":"string","description":"internally assigned biblio identifier"},"branchcode":{"type":["string","null"],"description":"internally assigned branch identifier"},"reservenotes":{"description":"notes related to this hold"},"reminderdate":{"description":"currently unused"},"lowestPriority":{"description":""},"timestamp":{"description":"date and time the hold was last updated"},"cancellationdate":{"description":"the date the hold was cancelled"},"suspend":{"description":""},"itemnumber":{"type":["string","null"],"description":"internally assigned item identifier"},"suspend_until":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"notificationdate":{"description":"currently unused"}}},"description":"Updated hold"}}},"delete":{"parameters":[{"description":"Internal hold identifier","type":"integer","required":true,"in":"path","name":"reserve_id"}],"responses":{"404":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Hold not found"},"200":{"description":"Successful deletion","schema":{"type":"object"}}},"tags":["holds"],"produces":["application\/json"],"operationId":"deleteHold"}}},"info":{"title":"Koha REST API","license":{"name":"GPL v3","url":"http:\/\/www.gnu.org\/licenses\/gpl.txt"},"contact":{"url":"http:\/\/koha-community.org\/","name":"Koha Team"},"version":"1"},"swagger":"2.0","parameters":{"borrowernumberPathParam":{"description":"Internal patron identifier","type":"integer","required":true,"in":"path","name":"borrowernumber"},"holdIdPathParam":{"description":"Internal hold identifier","type":"integer","required":true,"in":"path","name":"reserve_id"}},"basePath":"\/api\/v1"}
1
{"swagger":"2.0","definitions":{"session":{"type":"object","properties":{"firstname":{"type":["string","null"],"description":"patron's first name"},"surname":{"type":"string","description":"patron's last name"},"sessionid":{"description":"Koha Session identifier","type":"string"},"email":{"type":["string","null"],"description":"primary email address for patron's primary address"},"permissions":{"items":{"type":"string"},"type":"array","description":"patron's permissions"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"}}},"patron":{"type":"object","properties":{"mobile":{"type":["string","null"],"description":"the other phone number for patron's primary address"},"altcontactaddress2":{"type":["string","null"],"description":"the second address line for the alternate contact for the patron"},"gonenoaddress":{"description":"set to 1 if library marked this patron as having an unconfirmed address","type":["string","null"]},"lost":{"type":["string","null"],"description":"set to 1 if library marked this patron as having lost his card"},"othernames":{"description":"any other names associated with the patron","type":["string","null"]},"sms_provider_id":{"type":["string","null"],"description":"the provider of the mobile phone number defined in smsalertnumber"},"email":{"type":["string","null"],"description":"primary email address for patron's primary address"},"B_phone":{"description":"phone number for patron's alternate address","type":["string","null"]},"altcontactsurname":{"description":"surname or last name of the alternate contact for the patron","type":["string","null"]},"emailpro":{"type":["string","null"],"description":"secondary email address for patron's primary address"},"contacttitle":{"description":"used for children to include title of guarantor","type":["string","null"]},"B_streettype":{"type":["string","null"],"description":"street type of patron's alternate address"},"title":{"type":["string","null"],"description":"patron's title"},"zipcode":{"description":"zip or postal code of patron's primary address","type":["string","null"]},"B_address":{"description":"first address line of patron's alternate address","type":["string","null"]},"address2":{"type":["string","null"],"description":"second address line of patron's primary address"},"borrowernotes":{"description":"a note on the patron's account","type":["string","null"]},"contactnote":{"type":["string","null"],"description":"a note related to patron's alternate address"},"flags":{"description":"a number associated with the patron's permissions","type":["string","null"]},"updated_on":{"type":"string","description":"time of last change could be useful for synchronization with external systems (among others)"},"debarredcomment":{"description":"comment on the stop of the patron","type":["string","null"]},"B_email":{"type":["string","null"],"description":"email address for patron's alternate address"},"sort2":{"description":"a field that can be used for any information unique to the library","type":["string","null"]},"altcontactstate":{"type":["string","null"],"description":"the state for the alternate contact for the patron"},"initials":{"type":["string","null"],"description":"initials of the patron"},"B_state":{"type":["string","null"],"description":"state or province of patron's alternate address"},"B_country":{"description":"country of patron's alternate address","type":["string","null"]},"sort1":{"type":["string","null"],"description":"a field that can be used for any information unique to the library"},"categorycode":{"description":"code of patron's category","type":"string"},"debarred":{"type":["string","null"],"description":"until this date the patron can only check-in"},"B_streetnumber":{"type":["string","null"],"description":"street number of patron's alternate address"},"guarantorid":{"type":["string","null"],"description":"borrowernumber used for children or professionals to link them to guarantor or organizations"},"privacy":{"type":"string","description":"patron's privacy settings related to their reading history"},"B_city":{"type":["string","null"],"description":"city or town of patron's alternate address"},"firstname":{"type":["string","null"],"description":"patron's first name"},"userid":{"type":["string","null"],"description":"patron's login"},"dateofbirth":{"type":["string","null"],"description":"patron's date of birth"},"country":{"description":"country of patron's primary address","type":["string","null"]},"smsalertnumber":{"description":"the mobile phone number where the patron would like to receive notices (if SMS turned on)","type":["string","null"]},"altcontactaddress1":{"type":["string","null"],"description":"the first address line for the alternate contact for the patron"},"B_address2":{"description":"second address line of patron's alternate address","type":["string","null"]},"opacnote":{"type":["string","null"],"description":"a note on the patron's account visible in OPAC and staff client"},"cardnumber":{"type":["string","null"],"description":"library assigned user identifier"},"fax":{"description":"fax number for patron's primary address","type":["string","null"]},"altcontactfirstname":{"description":"first name of alternate contact for the patron","type":["string","null"]},"altcontactaddress3":{"description":"the city for the alternate contact for the patron","type":["string","null"]},"checkprevcheckout":{"type":"string","description":"produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'"},"relationship":{"type":["string","null"],"description":"used for children to include the relationship to their guarantor"},"contactname":{"description":"used for children and professionals to include surname or last name of guarantor or organization name","type":["string","null"]},"streetnumber":{"type":["string","null"],"description":"street number of patron's primary address"},"phone":{"type":["string","null"],"description":"primary phone number for patron's primary address"},"streettype":{"type":["string","null"],"description":"street type of patron's primary address"},"surname":{"type":"string","description":"patron's last name"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]},"contactfirstname":{"description":"used for children to include first name of guarantor","type":["string","null"]},"city":{"type":"string","description":"city or town of patron's primary address"},"altcontactzipcode":{"type":["string","null"],"description":"the zipcode for the alternate contact for the patron"},"password":{"type":["string","null"],"description":"patron's encrypted password"},"phonepro":{"description":"secondary phone number for patron's primary address","type":["string","null"]},"B_zipcode":{"description":"zip or postal code of patron's alternate address","type":["string","null"]},"altcontactcountry":{"description":"the country for the alternate contact for the patron","type":["string","null"]},"address":{"description":"first address line of patron's primary address","type":"string"},"sex":{"description":"patron's gender","type":["string","null"]},"altcontactphone":{"description":"the phone number for the alternate contact for the patron","type":["string","null"]},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"dateexpiry":{"description":"date the patron's card is set to expire","type":["string","null"]},"privacy_guarantor_checkouts":{"type":"string","description":"controls if relatives can see this patron's checkouts"},"dateenrolled":{"description":"date the patron was added to Koha","type":["string","null"]},"state":{"type":["string","null"],"description":"state or province of patron's primary address"}}},"holds":{"items":{"type":"object","properties":{"biblionumber":{"description":"internally assigned biblio identifier","type":"string"},"priority":{"description":"where in the queue the patron sits"},"reservedate":{"description":"the date the hold was placed"},"notificationdate":{"description":"currently unused"},"reservenotes":{"description":"notes related to this hold"},"suspend_until":{"description":""},"suspend":{"description":""},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"cancellationdate":{"description":"the date the hold was cancelled"},"reminderdate":{"description":"currently unused"},"itemnumber":{"description":"internally assigned item identifier","type":["string","null"]},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"lowestPriority":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"expirationdate":{"description":"the date the hold expires"},"timestamp":{"description":"date and time the hold was last updated"},"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]}}},"type":"array"},"error":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"},"hold":{"properties":{"biblionumber":{"description":"internally assigned biblio identifier","type":"string"},"priority":{"description":"where in the queue the patron sits"},"reservedate":{"description":"the date the hold was placed"},"notificationdate":{"description":"currently unused"},"reservenotes":{"description":"notes related to this hold"},"suspend_until":{"description":""},"suspend":{"description":""},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"cancellationdate":{"description":"the date the hold was cancelled"},"reminderdate":{"description":"currently unused"},"itemnumber":{"description":"internally assigned item identifier","type":["string","null"]},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"lowestPriority":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"expirationdate":{"description":"the date the hold expires"},"timestamp":{"description":"date and time the hold was last updated"},"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]}},"type":"object"}},"basePath":"\/api\/v1","paths":{"\/holds\/{reserve_id}":{"put":{"parameters":[{"in":"path","required":true,"description":"Internal hold identifier","type":"integer","name":"reserve_id"},{"name":"body","description":"A JSON object containing fields to modify","required":true,"schema":{"properties":{"priority":{"minimum":1,"description":"Position in waiting queue","type":"integer"},"suspend_until":{"type":"string","description":"Suspend until","format":"date"},"branchcode":{"description":"Pickup location","type":"string"}},"type":"object"},"in":"body"}],"produces":["application\/json"],"consumes":["application\/json"],"operationId":"editHold","tags":["holds"],"responses":{"400":{"description":"Missing or wrong parameters","schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"}},"404":{"description":"Hold not found","schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"}},"200":{"schema":{"properties":{"biblionumber":{"description":"internally assigned biblio identifier","type":"string"},"priority":{"description":"where in the queue the patron sits"},"reservedate":{"description":"the date the hold was placed"},"notificationdate":{"description":"currently unused"},"reservenotes":{"description":"notes related to this hold"},"suspend_until":{"description":""},"suspend":{"description":""},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"cancellationdate":{"description":"the date the hold was cancelled"},"reminderdate":{"description":"currently unused"},"itemnumber":{"description":"internally assigned item identifier","type":["string","null"]},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"lowestPriority":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"expirationdate":{"description":"the date the hold expires"},"timestamp":{"description":"date and time the hold was last updated"},"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]}},"type":"object"},"description":"Updated hold"}}},"delete":{"produces":["application\/json"],"operationId":"deleteHold","tags":["holds"],"responses":{"200":{"description":"Successful deletion","schema":{"type":"object"}},"404":{"description":"Hold not found","schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"}}},"parameters":[{"name":"reserve_id","required":true,"description":"Internal hold identifier","type":"integer","in":"path"}]}},"\/holds":{"post":{"parameters":[{"in":"body","schema":{"properties":{"borrowernumber":{"description":"Borrower internal identifier","type":"integer"},"biblionumber":{"description":"Biblio internal identifier","type":"integer"},"itemnumber":{"type":"integer","description":"Item internal identifier"},"expirationdate":{"format":"date","description":"Hold end date","type":"string"},"branchcode":{"description":"Pickup location","type":"string"}},"type":"object"},"required":true,"description":"A JSON object containing informations about the new hold","name":"body"}],"consumes":["application\/json"],"tags":["borrowers","holds"],"operationId":"addHold","responses":{"500":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Internal error"},"403":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Hold not allowed"},"201":{"schema":{"properties":{"biblionumber":{"description":"internally assigned biblio identifier","type":"string"},"priority":{"description":"where in the queue the patron sits"},"reservedate":{"description":"the date the hold was placed"},"notificationdate":{"description":"currently unused"},"reservenotes":{"description":"notes related to this hold"},"suspend_until":{"description":""},"suspend":{"description":""},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"cancellationdate":{"description":"the date the hold was cancelled"},"reminderdate":{"description":"currently unused"},"itemnumber":{"description":"internally assigned item identifier","type":["string","null"]},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"lowestPriority":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"expirationdate":{"description":"the date the hold expires"},"timestamp":{"description":"date and time the hold was last updated"},"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]}},"type":"object"},"description":"Created hold"},"400":{"schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"},"description":"Missing or wrong parameters"},"404":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Borrower not found"}},"produces":["application\/json"]},"get":{"parameters":[{"type":"integer","description":"Internal reserve identifier","name":"reserve_id","in":"query"},{"name":"borrowernumber","description":"Internal borrower identifier","type":"integer","in":"query"},{"in":"query","description":"Reserve date","type":"string","name":"reservedate"},{"type":"integer","description":"Internal biblio identifier","name":"biblionumber","in":"query"},{"name":"branchcode","description":"Branch code","type":"string","in":"query"},{"in":"query","name":"notificationdate","description":"Notification date","type":"string"},{"name":"reminderdate","type":"string","description":"Reminder date","in":"query"},{"in":"query","description":"Cancellation date","type":"string","name":"cancellationdate"},{"name":"reservenotes","description":"Reserve notes","type":"string","in":"query"},{"name":"priority","description":"Priority","type":"integer","in":"query"},{"type":"string","description":"Found status","name":"found","in":"query"},{"name":"timestamp","description":"Time of latest update","type":"string","in":"query"},{"name":"itemnumber","type":"integer","description":"Internal item identifier","in":"query"},{"name":"waitingdate","type":"string","description":"Date the item was marked as waiting for the patron","in":"query"},{"in":"query","name":"expirationdate","type":"string","description":"Date the hold expires"},{"name":"lowestPriority","type":"integer","description":"Lowest priority","in":"query"},{"in":"query","description":"Suspended","type":"integer","name":"suspend"},{"type":"string","description":"Suspended until","name":"suspend_until","in":"query"}],"tags":["borrowers","holds"],"operationId":"listHolds","responses":{"404":{"description":"Borrower not found","schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}}},"200":{"description":"A list of holds","schema":{"type":"array","items":{"type":"object","properties":{"biblionumber":{"description":"internally assigned biblio identifier","type":"string"},"priority":{"description":"where in the queue the patron sits"},"reservedate":{"description":"the date the hold was placed"},"notificationdate":{"description":"currently unused"},"reservenotes":{"description":"notes related to this hold"},"suspend_until":{"description":""},"suspend":{"description":""},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"cancellationdate":{"description":"the date the hold was cancelled"},"reminderdate":{"description":"currently unused"},"itemnumber":{"description":"internally assigned item identifier","type":["string","null"]},"itemtype":{"type":["string","null"],"description":"If record level hold, the optional itemtype of the item the patron is requesting"},"lowestPriority":{"description":""},"reserve_id":{"description":"Internal hold identifier"},"expirationdate":{"description":"the date the hold expires"},"timestamp":{"description":"date and time the hold was last updated"},"found":{"description":"a one letter code defining what the status of the hold is after it has been confirmed"},"waitingdate":{"description":"the date the item was marked as waiting for the patron at the library"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]}}}}}},"produces":["application\/json"]}},"\/patrons\/{borrowernumber}":{"get":{"parameters":[{"name":"borrowernumber","type":"integer","required":true,"description":"Internal patron identifier","in":"path"}],"produces":["application\/json"],"operationId":"getPatron","tags":["patrons"],"responses":{"404":{"description":"Patron not found","schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}}},"403":{"schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"},"description":"Access forbidden"},"200":{"description":"A patron","schema":{"type":"object","properties":{"mobile":{"type":["string","null"],"description":"the other phone number for patron's primary address"},"altcontactaddress2":{"type":["string","null"],"description":"the second address line for the alternate contact for the patron"},"gonenoaddress":{"description":"set to 1 if library marked this patron as having an unconfirmed address","type":["string","null"]},"lost":{"type":["string","null"],"description":"set to 1 if library marked this patron as having lost his card"},"othernames":{"description":"any other names associated with the patron","type":["string","null"]},"sms_provider_id":{"type":["string","null"],"description":"the provider of the mobile phone number defined in smsalertnumber"},"email":{"type":["string","null"],"description":"primary email address for patron's primary address"},"B_phone":{"description":"phone number for patron's alternate address","type":["string","null"]},"altcontactsurname":{"description":"surname or last name of the alternate contact for the patron","type":["string","null"]},"emailpro":{"type":["string","null"],"description":"secondary email address for patron's primary address"},"contacttitle":{"description":"used for children to include title of guarantor","type":["string","null"]},"B_streettype":{"type":["string","null"],"description":"street type of patron's alternate address"},"title":{"type":["string","null"],"description":"patron's title"},"zipcode":{"description":"zip or postal code of patron's primary address","type":["string","null"]},"B_address":{"description":"first address line of patron's alternate address","type":["string","null"]},"address2":{"type":["string","null"],"description":"second address line of patron's primary address"},"borrowernotes":{"description":"a note on the patron's account","type":["string","null"]},"contactnote":{"type":["string","null"],"description":"a note related to patron's alternate address"},"flags":{"description":"a number associated with the patron's permissions","type":["string","null"]},"updated_on":{"type":"string","description":"time of last change could be useful for synchronization with external systems (among others)"},"debarredcomment":{"description":"comment on the stop of the patron","type":["string","null"]},"B_email":{"type":["string","null"],"description":"email address for patron's alternate address"},"sort2":{"description":"a field that can be used for any information unique to the library","type":["string","null"]},"altcontactstate":{"type":["string","null"],"description":"the state for the alternate contact for the patron"},"initials":{"type":["string","null"],"description":"initials of the patron"},"B_state":{"type":["string","null"],"description":"state or province of patron's alternate address"},"B_country":{"description":"country of patron's alternate address","type":["string","null"]},"sort1":{"type":["string","null"],"description":"a field that can be used for any information unique to the library"},"categorycode":{"description":"code of patron's category","type":"string"},"debarred":{"type":["string","null"],"description":"until this date the patron can only check-in"},"B_streetnumber":{"type":["string","null"],"description":"street number of patron's alternate address"},"guarantorid":{"type":["string","null"],"description":"borrowernumber used for children or professionals to link them to guarantor or organizations"},"privacy":{"type":"string","description":"patron's privacy settings related to their reading history"},"B_city":{"type":["string","null"],"description":"city or town of patron's alternate address"},"firstname":{"type":["string","null"],"description":"patron's first name"},"userid":{"type":["string","null"],"description":"patron's login"},"dateofbirth":{"type":["string","null"],"description":"patron's date of birth"},"country":{"description":"country of patron's primary address","type":["string","null"]},"smsalertnumber":{"description":"the mobile phone number where the patron would like to receive notices (if SMS turned on)","type":["string","null"]},"altcontactaddress1":{"type":["string","null"],"description":"the first address line for the alternate contact for the patron"},"B_address2":{"description":"second address line of patron's alternate address","type":["string","null"]},"opacnote":{"type":["string","null"],"description":"a note on the patron's account visible in OPAC and staff client"},"cardnumber":{"type":["string","null"],"description":"library assigned user identifier"},"fax":{"description":"fax number for patron's primary address","type":["string","null"]},"altcontactfirstname":{"description":"first name of alternate contact for the patron","type":["string","null"]},"altcontactaddress3":{"description":"the city for the alternate contact for the patron","type":["string","null"]},"checkprevcheckout":{"type":"string","description":"produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'"},"relationship":{"type":["string","null"],"description":"used for children to include the relationship to their guarantor"},"contactname":{"description":"used for children and professionals to include surname or last name of guarantor or organization name","type":["string","null"]},"streetnumber":{"type":["string","null"],"description":"street number of patron's primary address"},"phone":{"type":["string","null"],"description":"primary phone number for patron's primary address"},"streettype":{"type":["string","null"],"description":"street type of patron's primary address"},"surname":{"type":"string","description":"patron's last name"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]},"contactfirstname":{"description":"used for children to include first name of guarantor","type":["string","null"]},"city":{"type":"string","description":"city or town of patron's primary address"},"altcontactzipcode":{"type":["string","null"],"description":"the zipcode for the alternate contact for the patron"},"password":{"type":["string","null"],"description":"patron's encrypted password"},"phonepro":{"description":"secondary phone number for patron's primary address","type":["string","null"]},"B_zipcode":{"description":"zip or postal code of patron's alternate address","type":["string","null"]},"altcontactcountry":{"description":"the country for the alternate contact for the patron","type":["string","null"]},"address":{"description":"first address line of patron's primary address","type":"string"},"sex":{"description":"patron's gender","type":["string","null"]},"altcontactphone":{"description":"the phone number for the alternate contact for the patron","type":["string","null"]},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"dateexpiry":{"description":"date the patron's card is set to expire","type":["string","null"]},"privacy_guarantor_checkouts":{"type":"string","description":"controls if relatives can see this patron's checkouts"},"dateenrolled":{"description":"date the patron was added to Koha","type":["string","null"]},"state":{"type":["string","null"],"description":"state or province of patron's primary address"}}}}}}},"\/patrons":{"get":{"produces":["application\/json"],"operationId":"listPatrons","responses":{"200":{"description":"A list of patrons","schema":{"items":{"type":"object","properties":{"mobile":{"type":["string","null"],"description":"the other phone number for patron's primary address"},"altcontactaddress2":{"type":["string","null"],"description":"the second address line for the alternate contact for the patron"},"gonenoaddress":{"description":"set to 1 if library marked this patron as having an unconfirmed address","type":["string","null"]},"lost":{"type":["string","null"],"description":"set to 1 if library marked this patron as having lost his card"},"othernames":{"description":"any other names associated with the patron","type":["string","null"]},"sms_provider_id":{"type":["string","null"],"description":"the provider of the mobile phone number defined in smsalertnumber"},"email":{"type":["string","null"],"description":"primary email address for patron's primary address"},"B_phone":{"description":"phone number for patron's alternate address","type":["string","null"]},"altcontactsurname":{"description":"surname or last name of the alternate contact for the patron","type":["string","null"]},"emailpro":{"type":["string","null"],"description":"secondary email address for patron's primary address"},"contacttitle":{"description":"used for children to include title of guarantor","type":["string","null"]},"B_streettype":{"type":["string","null"],"description":"street type of patron's alternate address"},"title":{"type":["string","null"],"description":"patron's title"},"zipcode":{"description":"zip or postal code of patron's primary address","type":["string","null"]},"B_address":{"description":"first address line of patron's alternate address","type":["string","null"]},"address2":{"type":["string","null"],"description":"second address line of patron's primary address"},"borrowernotes":{"description":"a note on the patron's account","type":["string","null"]},"contactnote":{"type":["string","null"],"description":"a note related to patron's alternate address"},"flags":{"description":"a number associated with the patron's permissions","type":["string","null"]},"updated_on":{"type":"string","description":"time of last change could be useful for synchronization with external systems (among others)"},"debarredcomment":{"description":"comment on the stop of the patron","type":["string","null"]},"B_email":{"type":["string","null"],"description":"email address for patron's alternate address"},"sort2":{"description":"a field that can be used for any information unique to the library","type":["string","null"]},"altcontactstate":{"type":["string","null"],"description":"the state for the alternate contact for the patron"},"initials":{"type":["string","null"],"description":"initials of the patron"},"B_state":{"type":["string","null"],"description":"state or province of patron's alternate address"},"B_country":{"description":"country of patron's alternate address","type":["string","null"]},"sort1":{"type":["string","null"],"description":"a field that can be used for any information unique to the library"},"categorycode":{"description":"code of patron's category","type":"string"},"debarred":{"type":["string","null"],"description":"until this date the patron can only check-in"},"B_streetnumber":{"type":["string","null"],"description":"street number of patron's alternate address"},"guarantorid":{"type":["string","null"],"description":"borrowernumber used for children or professionals to link them to guarantor or organizations"},"privacy":{"type":"string","description":"patron's privacy settings related to their reading history"},"B_city":{"type":["string","null"],"description":"city or town of patron's alternate address"},"firstname":{"type":["string","null"],"description":"patron's first name"},"userid":{"type":["string","null"],"description":"patron's login"},"dateofbirth":{"type":["string","null"],"description":"patron's date of birth"},"country":{"description":"country of patron's primary address","type":["string","null"]},"smsalertnumber":{"description":"the mobile phone number where the patron would like to receive notices (if SMS turned on)","type":["string","null"]},"altcontactaddress1":{"type":["string","null"],"description":"the first address line for the alternate contact for the patron"},"B_address2":{"description":"second address line of patron's alternate address","type":["string","null"]},"opacnote":{"type":["string","null"],"description":"a note on the patron's account visible in OPAC and staff client"},"cardnumber":{"type":["string","null"],"description":"library assigned user identifier"},"fax":{"description":"fax number for patron's primary address","type":["string","null"]},"altcontactfirstname":{"description":"first name of alternate contact for the patron","type":["string","null"]},"altcontactaddress3":{"description":"the city for the alternate contact for the patron","type":["string","null"]},"checkprevcheckout":{"type":"string","description":"produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'"},"relationship":{"type":["string","null"],"description":"used for children to include the relationship to their guarantor"},"contactname":{"description":"used for children and professionals to include surname or last name of guarantor or organization name","type":["string","null"]},"streetnumber":{"type":["string","null"],"description":"street number of patron's primary address"},"phone":{"type":["string","null"],"description":"primary phone number for patron's primary address"},"streettype":{"type":["string","null"],"description":"street type of patron's primary address"},"surname":{"type":"string","description":"patron's last name"},"branchcode":{"description":"code of patron's home branch","type":["string","null"]},"contactfirstname":{"description":"used for children to include first name of guarantor","type":["string","null"]},"city":{"type":"string","description":"city or town of patron's primary address"},"altcontactzipcode":{"type":["string","null"],"description":"the zipcode for the alternate contact for the patron"},"password":{"type":["string","null"],"description":"patron's encrypted password"},"phonepro":{"description":"secondary phone number for patron's primary address","type":["string","null"]},"B_zipcode":{"description":"zip or postal code of patron's alternate address","type":["string","null"]},"altcontactcountry":{"description":"the country for the alternate contact for the patron","type":["string","null"]},"address":{"description":"first address line of patron's primary address","type":"string"},"sex":{"description":"patron's gender","type":["string","null"]},"altcontactphone":{"description":"the phone number for the alternate contact for the patron","type":["string","null"]},"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"dateexpiry":{"description":"date the patron's card is set to expire","type":["string","null"]},"privacy_guarantor_checkouts":{"type":"string","description":"controls if relatives can see this patron's checkouts"},"dateenrolled":{"description":"date the patron was added to Koha","type":["string","null"]},"state":{"type":["string","null"],"description":"state or province of patron's primary address"}}},"type":"array"}},"403":{"description":"Access forbidden","schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"}}},"tags":["patrons"]}},"\/auth\/session":{"delete":{"parameters":[{"in":"body","name":"session","description":"The CGISESSID Cookie used to authenticate a session","required":false,"schema":{"properties":{"sessionid":{"type":"string","description":"The Koha sessionid"}},"required":["sessionid"],"type":"object"}}],"description":"Logouts user from Koha by marking session as expired. sessionid is optional, if not given, logs out currently logged in user","produces":["application\/json"],"responses":{"401":{"schema":{"properties":{"error":{"description":"Error message","type":"string"}},"type":"object"},"description":"Bad session id"},"200":{"schema":{"type":"object"},"description":"Successfully logged out"}},"operationId":"logoutAuth","tags":["auth"],"summary":"Logout from Koha."},"post":{"responses":{"201":{"description":"A borrower with SSO-relevant fields","schema":{"properties":{"firstname":{"type":["string","null"],"description":"patron's first name"},"surname":{"type":"string","description":"patron's last name"},"sessionid":{"description":"Koha Session identifier","type":"string"},"email":{"type":["string","null"],"description":"primary email address for patron's primary address"},"permissions":{"items":{"type":"string"},"type":"array","description":"patron's permissions"},"borrowernumber":{"type":"string","description":"internally assigned user identifier"}},"type":"object"}},"401":{"schema":{"type":"object","properties":{"error":{"description":"Error message","type":"string"}}},"description":"Bad username\/cardnumber and\/or password"}},"operationId":"loginAuth","tags":["auth"],"summary":"Login to Koha and get a session cookie","description":"Makes a 'normal' username + password login to Koha, and returns the sessionid you need put to the CGISESSID-cookie. Koha uses this cookie to track a session.\nBe aware that the authenticated session most probably is IP-locked so authenticating from one IP and passing the session to another wont work.","produces":["application\/json"],"parameters":[{"type":"string","required":false,"description":"Borrower's card's barcode\/identifier","name":"cardnumber","in":"formData"},{"in":"formData","type":"string","required":false,"description":"The userid of the Borrower, unique value","name":"userid"},{"in":"formData","required":true,"type":"string","name":"password"}]}}},"parameters":{"useridPostParam":{"in":"formData","name":"userid","description":"The userid of the Borrower, unique value","required":false,"type":"string"},"sessionidBodyParam":{"name":"session","schema":{"properties":{"sessionid":{"type":"string","description":"The Koha sessionid"}},"required":["sessionid"],"type":"object"},"description":"The CGISESSID Cookie used to authenticate a session","required":false,"in":"body"},"holdIdPathParam":{"in":"path","name":"reserve_id","description":"Internal hold identifier","required":true,"type":"integer"},"cardnumberPostParam":{"in":"formData","name":"cardnumber","type":"string","required":false,"description":"Borrower's card's barcode\/identifier"},"borrowernumberPathParam":{"in":"path","type":"integer","description":"Internal patron identifier","required":true,"name":"borrowernumber"},"passwordPostParam":{"in":"formData","required":true,"type":"string","name":"password"},"borrowernumberQueryParam":{"in":"query","description":"Internal borrower identifier","type":"integer","name":"borrowernumber"}},"x-primitives":{"borrowernumber":{"description":"internally assigned user identifier","type":"string"},"email":{"description":"primary email address for patron's primary address","type":["string","null"]},"cardnumber":{"description":"library assigned user identifier","type":["string","null"]},"branchcode":{"type":["string","null"],"description":"code of patron's home branch"},"surname":{"description":"patron's last name","type":"string"},"firstname":{"description":"patron's first name","type":["string","null"]},"phone":{"description":"primary phone number for patron's primary address","type":["string","null"]},"biblionumber":{"description":"internally assigned biblio identifier","type":"string"},"itemnumber":{"description":"internally assigned item identifier","type":["string","null"]},"reserve_id":{"description":"Internal hold identifier"}},"info":{"version":"1","contact":{"url":"http:\/\/koha-community.org\/","name":"Koha Team"},"title":"Koha REST API","license":{"url":"http:\/\/www.gnu.org\/licenses\/gpl.txt","name":"GPL v3"}}}
(-)a/t/db_dependent/api/v1/auth.t (-1 / +140 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# Copyright 2016 Koha-Suomi
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Test::More tests => 38;
23
use Test::Mojo;
24
25
use t::lib::TestBuilder;
26
27
use C4::Auth;
28
use C4::Context;
29
use Koha::AuthUtils;
30
31
my $builder = t::lib::TestBuilder->new();
32
33
my $dbh = C4::Context->dbh;
34
$dbh->{AutoCommit} = 0;
35
$dbh->{RaiseError} = 1;
36
37
$ENV{REMOTE_ADDR} = '127.0.0.1';
38
my $t = Test::Mojo->new('Koha::REST::V1');
39
40
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
41
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
42
my $password = "2anxious? if someone finds out";
43
44
my $borrower = $builder->build({
45
    source => 'Borrower',
46
    value => {
47
        branchcode   => $branchcode,
48
        categorycode => $categorycode,
49
        password => Koha::AuthUtils::hash_password($password),
50
    }
51
});
52
53
my $auth_by_userid = {
54
    userid => $borrower->{userid},
55
    password => $password,
56
};
57
my $auth_by_cardnumber = {
58
    cardnumber => $borrower->{cardnumber},
59
    password => $password,
60
};
61
my $invalid_login = {
62
    userid => $borrower->{userid},
63
    password => "please let me in",
64
};
65
my $invalid_login2 = {
66
    cardnumber => $borrower->{cardnumber},
67
    password => "my password is password, don't tell anyone",
68
};
69
70
my $tx = $t->ua->build_tx(POST => '/api/v1/auth/session' => form => $auth_by_userid);
71
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
72
$t->request_ok($tx)
73
  ->status_is(201)
74
  ->json_is('/firstname', $borrower->{firstname})
75
  ->json_is('/surname', $borrower->{surname})
76
  ->json_is('/borrowernumber', $borrower->{borrowernumber})
77
  ->json_is('/email', $borrower->{email})
78
  ->json_has('/sessionid');
79
80
$tx = $t->ua->build_tx(POST => '/api/v1/auth/session' => form => $auth_by_cardnumber);
81
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
82
$t->request_ok($tx)
83
  ->status_is(201)
84
  ->json_is('/firstname', $borrower->{firstname})
85
  ->json_is('/surname', $borrower->{surname})
86
  ->json_is('/borrowernumber', $borrower->{borrowernumber})
87
  ->json_is('/email', $borrower->{email})
88
  ->json_has('/sessionid');
89
my $sessionid = $tx->res->json->{sessionid};
90
91
$tx = $t->ua->build_tx(POST => '/api/v1/auth/session' => form => $invalid_login);
92
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
93
$t->request_ok($tx)
94
  ->status_is(401)
95
  ->json_is('/error', "Login failed.");
96
97
$tx = $t->ua->build_tx(POST => '/api/v1/auth/session' => form => $invalid_login2);
98
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
99
$t->request_ok($tx)
100
  ->status_is(401)
101
  ->json_is('/error', "Login failed.");
102
103
$tx = $t->ua->build_tx(DELETE => '/api/v1/auth/session' => json => { sessionid => $sessionid."123" });
104
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
105
$t->request_ok($tx)
106
  ->status_is(401)
107
  ->json_is('/error', "Invalid session id.");
108
109
my ($sess_status, $sid) = C4::Auth::check_cookie_auth($sessionid);
110
is($sess_status, "ok", "Session is valid before logging out.");
111
$tx = $t->ua->build_tx(DELETE => '/api/v1/auth/session' => json => { sessionid => $sessionid });
112
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
113
$t->request_ok($tx)
114
  ->status_is(200);
115
116
($sess_status, $sid) = C4::Auth::check_cookie_auth($sessionid);
117
isnt($sess_status, "ok", "Session is not valid after logging out.");
118
119
$tx = $t->ua->build_tx(POST => '/api/v1/auth/session' => form => $auth_by_cardnumber);
120
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
121
$t->request_ok($tx)
122
  ->status_is(201)
123
  ->json_is('/firstname', $borrower->{firstname})
124
  ->json_is('/surname', $borrower->{surname})
125
  ->json_is('/borrowernumber', $borrower->{borrowernumber})
126
  ->json_is('/email', $borrower->{email})
127
  ->json_has('/sessionid');
128
$sessionid = $tx->res->json->{sessionid};
129
130
($sess_status, $sid) = C4::Auth::check_cookie_auth($sessionid);
131
is($sess_status, "ok", "Session is valid before logging out.");
132
$tx = $t->ua->build_tx(DELETE => '/api/v1/auth/session');
133
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
134
$t->request_ok($tx)
135
  ->status_is(200);
136
137
($sess_status, $sid) = C4::Auth::check_cookie_auth($sessionid);
138
isnt($sess_status, "ok", "Session is not valid after logging out.");
139
140
$dbh->rollback;

Return to bug 17004