Bug 16447: Remove occurrence of the borrow permission which does no longer exist
[koha.git] / opac / svc / login
1 #!/usr/bin/perl
2
3 # Copyright chris@bigballofwax.co.nz 2013
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 CGI qw ( -utf8 );
21 use strict;
22 use warnings;
23 use C4::Auth;
24 use C4::Context;
25
26 use LWP::UserAgent;
27 use HTTP::Request::Common qw{ POST };
28 use JSON qw( decode_json );
29
30 my $url  = 'https://verifier.login.persona.org/verify';
31
32 my $query = CGI->new();
33
34 my $host = C4::Context->preference('OPACBaseURL');
35
36 my $assertion = $query->param('assertion');
37
38 my $ua = LWP::UserAgent->new();
39 my $response =
40   $ua->post( $url, [ 'assertion' => $assertion, 'audience' => $host ] );
41
42 if ( $response->is_success ) {
43     my $content      = $response->decoded_content();
44     my $decoded_json = decode_json($content);
45     my ( $userid, $cookie, $sessionID ) =
46       checkauth( $query, 1,  {}, 'opac', $decoded_json->{'email'} );
47     if ($userid) { # a valid user has logged in
48         print $query->header( -cookie => $cookie );
49         print $decoded_json;
50     }
51     else {
52 # logged in with an email that isn't associated with a borrower
53         die "Email not associated with a borrower";
54     }
55 }
56 else {
57     warn $response->status_line, "\n";
58 }