3 # Copyright 2013 ByWater
5 # This file is part of Koha.
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 2 of the License, or (at your option) any later
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.
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.
22 svc/overdrive_proxy: Proxy OAuth'd requests to OverDrive
26 svc/overdrive_proxy/libraries/9001 -> https://api.overdrive.com/v1/libraries/9001
30 This service proxies incoming requests to the OverDrive OAuth API, to keep the
31 JS side from having to deal with cross-origin/authentication issues.
38 use CGI qw(-oldstyle_urls);
42 use C4::External::OverDrive;
49 if ( !IsOverDriveEnabled() || !( $token = GetOverDriveToken() ) ) {
51 -status => '400 Bad Request',
56 error => 'invalid_client',
57 error_description => 'OverDrive login failed'
63 my $request = HTTP::Request::Common::GET( "https://api.overdrive.com/v1" . $query->path_info . '?' . $query->query_string );
64 $request->header( Authorization => $token );
66 my $ua = LWP::UserAgent->new( "Koha " . C4::Context->KOHAVERSION );
68 my $response = $ua->request( $request ) ;
69 if ( $response->code eq '500' ) {
71 -status => '500 Internal Server Error'
74 warn "OverDrive request failed: " . $response->message;
76 error => 'invalid_client',
77 error_description => 'OverDrive request failed'
83 output_with_http_headers $query, undef, $response->content, 'json', $response->status_line;