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 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
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.
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
22 # Here is an exemple 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
34 use Authen::CAS::Client;
36 # URL Of the CAS Server
37 my $casServerUrl = 'https://localhost:8443/cas/';
38 my $cas = Authen::CAS::Client->new($casServerUrl);
41 # URL of the service we're requesting a Service Ticket for (typically this very same page)
42 my $proxy_service = $cgi->url;
45 # Callback URL (this is an URL the CAS Server will query, providing the Proxy Ticket we'll need
46 # to query the koha webservice). It can be this page or another. In this example, another page will be
48 my $pgtUrl = "https://.../proxy_cas_callback.pl";
50 print $cgi->header({-type => 'text/html'});
51 print $cgi->start_html("proxy cas");
53 # If we already have a service ticket
54 if ($cgi->param('ticket')) {
56 print "Got a ticket :" . $cgi->param('ticket') . "<br>\n";
58 # We validate it against the CAS Server, providing the callback URL
59 my $r = $cas->service_validate( $proxy_service, $cgi->param('ticket'), pgtUrl => $pgtUrl);
61 # If it is sucessful, we are authenticated
62 if( $r->is_success() ) {
63 print "User authenticated as: ", $r->user(), "<br>\n";
65 print "User authentication failed<br />\n";
68 # If we have a PGTIou ticket, the proxy validation was sucessful
69 if (defined $r->iou) {
70 print "Proxy granting ticket IOU: ", $r->iou, "<br />\n";
73 print '<a href="proxy_cas_data.pl?PGTIOU=', $r->iou, '">Next</a>';
78 print "Service validation for proxying failed\n";
81 # If we don't have a Service Ticket, we ask for one (ie : the user will be redirected to the CAS Server for authentication)
84 my $url = $cas->login_url($proxy_service);
85 print "<a href=\"$url\">Please log in</a>";