Bug 20019: use Modern::Perl in misc perl scripts
[koha.git] / docs / CAS / CASProxy / examples / koha_webservice.pl
1 #!/usr/bin/perl
2
3 # Copyright 2009 SARL BibLibre
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 =head1 DESCRIPTION
21
22 # Here is an example of a simple phony webservice, returning "Hello World" if the user is authenticated
23 # The purpose is to show how CAS Proxy can work with koha
24 # In this configuration, this page acts as a CAS Client, instead of the user's browser.
25 # This page is meant to be called from a foreign application
26
27 =head1 CGI PARAMETERS
28
29 =item PT
30 The Proxy Ticket, needed for check_api_auth, that will try to make the CAS Server validate it.
31
32 =cut 
33
34 use utf8;
35 use Modern::Perl;
36 binmode(STDOUT, ":utf8");
37
38 use C4::Auth qw(check_api_auth);
39 use C4::Output;
40 use C4::Context;
41 use CGI qw ( -utf8 );
42
43 my $cgi = new CGI;
44
45 print CGI::header('-type'=>'text/plain', '-charset'=>'utf-8');
46
47 # The authentication : if $cgi contains a PT parameter, and CAS is enabled (casAuthentication syspref),
48 # a CAS Proxy authentication will take place
49 my ( $status, $cookie_, $sessionID ) = check_api_auth( $cgi, {circulate => 'override_renewals'});
50
51 if ($status ne 'ok') {
52     print "Authentication failed : $status";
53 } else {
54     print "Hello World!";
55 }
56 exit 0;
57