Merge branch 'bug_9179' into 3.12-master
[koha.git] / docs / CAS / CASProxy / examples / proxy_cas_callback.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 callback page for a CAS Proxy
23 # This is the page the CAS server will call back with a Proxy Ticket, allowing us (the foreign application)
24 # to query koha webservices, being CAS authenticated 
25
26 =cut
27
28 use strict;
29 use warnings;
30 use CGI;
31 use Authen::CAS::Client;
32 use Storable qw(nstore_fd);
33
34 my $casServerUrl = 'https://localhost:8443/cas/';
35 my $cas = Authen::CAS::Client->new($casServerUrl);
36
37 my $cgi = new CGI;
38
39 my $proxy_service = $cgi->url;
40
41 print $cgi->header({-type  =>  'text/html'});
42 print $cgi->start_html("proxy cas callback");
43
44 # If we have a pgtId, it means the cas server called us back
45 if ($cgi->param('pgtId')) {
46     warn "Got a pgtId :" . $cgi->param('pgtId');
47     warn "Got a pgtIou :" . $cgi->param('pgtIou');
48     my $pgtIou =  $cgi->param('pgtIou');
49     my $pgtId =  $cgi->param('pgtId');
50
51     # Now we store the pgtIou and the pgtId in the application vars (in our case a storable object in a file), 
52     # so that the page requesting the webservice can retrieve the pgtId matching it's PgtIou 
53     open FILE, ">", "casSession.tmp" or die "Unable to open file";
54     nstore_fd({$pgtIou => $pgtId}, \*FILE);
55     close FILE;
56
57 } else {
58     warn "Failed to get a Proxy Ticket\n";
59 }
60
61 print $cgi->end_html;
62