Bug 5630 CAS improvements
[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 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
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
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;
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