Bug 25898: Prohibit indirect object notation
[koha.git] / docs / CAS / CASProxy / examples / proxy_cas.pl
blobc69d197f80e0c2de78d92437e88213bde4af2976
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 CAS Proxy
23 # The proxy is a foreign application that will authenticate the user against CAS
24 # Once authenticated as a proxy, the foreign application will be able to call some
25 # Koha webservices, proving authentication only by giving a proxy ticket
27 # Note: please keep in mind that all url's must be https and their certificates must be trusted
29 =cut
31 use Modern::Perl;
32 use CGI qw ( -utf8 );
33 use Authen::CAS::Client;
35 # URL Of the CAS Server
36 my $casServerUrl = 'https://localhost:8443/cas/';
37 my $cas = Authen::CAS::Client->new($casServerUrl);
38 my $cgi = CGI->new;
40 # URL of the service we're requesting a Service Ticket for (typically this very same page)
41 my $proxy_service = $cgi->url;
44 # Callback URL (this is an URL the CAS Server will query, providing the Proxy Ticket we'll need
45 # to query the koha webservice). It can be this page or another. In this example, another page will be
46 # called back
47 my $pgtUrl = "https://.../proxy_cas_callback.pl";
49 print $cgi->header({-type => 'text/html'});
50 print $cgi->start_html("proxy cas");
52 # If we already have a service ticket
53 if ($cgi->param('ticket')) {
55 print "Got a ticket :" . $cgi->param('ticket') . "<br>\n";
57 # We validate it against the CAS Server, providing the callback URL
58 my $r = $cas->service_validate( $proxy_service, $cgi->param('ticket'), pgtUrl => $pgtUrl);
60 # If it is successful, we are authenticated
61 if( $r->is_success() ) {
62 print "User authenticated as: ", $r->user(), "<br>\n";
63 } else {
64 print "User authentication failed<br />\n";
67 # If we have a PGTIou ticket, the proxy validation was successful
68 if (defined $r->iou) {
69 print "Proxy granting ticket IOU: ", $r->iou, "<br />\n";
70 my $pgtIou = $r->iou;
72 print '<a href="proxy_cas_data.pl?PGTIOU=', $r->iou, '">Next</a>';
76 } else {
77 print "Service validation for proxying failed\n";
80 # If we don't have a Service Ticket, we ask for one (ie : the user will be redirected to the CAS Server for authentication)
81 } else {
83 my $url = $cas->login_url($proxy_service);
84 print "<a href=\"$url\">Please log in</a>";
87 print $cgi->end_html;