Bug 21395: Make perlcritic happy
[koha.git] / docs / CAS / CASProxy / examples / proxy_cas_callback.pl
blobfdda4274f0103c42f390dd20df5fdc4349a04f9a
1 #!/usr/bin/perl
3 # Copyright 2009 SARL BibLibre
5 # This file is part of Koha.
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.
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.
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>.
20 =head1 DESCRIPTION
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
26 =cut
28 use Modern::Perl;
29 use CGI qw ( -utf8 );
30 use Authen::CAS::Client;
31 use Storable qw(nstore_fd);
33 my $casServerUrl = 'https://localhost:8443/cas/';
34 my $cas = Authen::CAS::Client->new($casServerUrl);
36 my $cgi = new CGI;
38 my $proxy_service = $cgi->url;
40 print $cgi->header({-type => 'text/html'});
41 print $cgi->start_html("proxy cas callback");
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');
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;
56 } else {
57 warn "Failed to get a Proxy Ticket\n";
60 print $cgi->end_html;