Bug 9978: (followup) Replace license header with the correct license (GPLv3+)
[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 exemple 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 strict;
36 use warnings;
37 binmode(STDOUT, ":utf8");
38
39 use C4::Auth qw(check_api_auth);
40 use C4::Output;
41 use C4::Context;
42 use CGI qw ( -utf8 );
43
44 my $cgi = new CGI;
45
46 print CGI::header('-type'=>'text/plain', '-charset'=>'utf-8');
47
48 # The authentication : if $cgi contains a PT parameter, and CAS is enabled (casAuthentication syspref),
49 # a CAS Proxy authentication will take place
50 my ( $status, $cookie_, $sessionID ) = check_api_auth( $cgi, {circulate => 'override_renewals'});
51
52 if ($status ne 'ok') {
53     print "Authentication failed : $status";
54 } else {
55     print "Hello World!";
56 }
57 exit 0;
58