Bug 17600: Standardize our EXPORT_OK
[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
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 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 Modern::Perl;
29 use CGI qw ( -utf8 );
30 use Authen::CAS::Client;
31 use Storable qw( nstore_fd );
32
33 my $casServerUrl = 'https://localhost:8443/cas/';
34 my $cas = Authen::CAS::Client->new($casServerUrl);
35
36 my $cgi = CGI->new;
37
38 my $proxy_service = $cgi->url;
39
40 print $cgi->header({-type  =>  'text/html'});
41 print $cgi->start_html("proxy cas callback");
42
43 # If we have a pgtId, it means the cas server called us back
44 if ($cgi->param('pgtId')) {
45     warn "Got a pgtId :" . $cgi->param('pgtId');
46     warn "Got a pgtIou :" . $cgi->param('pgtIou');
47     my $pgtIou =  $cgi->param('pgtIou');
48     my $pgtId =  $cgi->param('pgtId');
49
50     # Now we store the pgtIou and the pgtId in the application vars (in our case a storable object in a file), 
51     # so that the page requesting the webservice can retrieve the pgtId matching it's PgtIou 
52     open my $fh, ">", "casSession.tmp" or die "Unable to open file";
53     nstore_fd({$pgtIou => $pgtId}, $fh);
54     close $fh;
55
56 } else {
57     warn "Failed to get a Proxy Ticket\n";
58 }
59
60 print $cgi->end_html;
61