Toby Inkster > CGI-Auth-FOAF_SSL > CGI::Auth::FOAF_SSL

Download:
CGI-Auth-FOAF_SSL-1.002.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.002   Source  

NAME ^

CGI::Auth::FOAF_SSL - authentication using WebID (FOAF+SSL)

SYNOPSIS ^

  use CGI qw(:all);
  use CGI::Auth::FOAF_SSL;
  
  my $auth = CGI::Auth::FOAF_SSL->new_from_cgi;
  
  print header(-type=>'text/html', -cookie=>$auth->cookie);
  
  if (defined $auth && $auth->is_secure)
  {
    if (defined $auth->subject)
    {
      printf("<p>Hello <a href='%s'>%s</a>!</p>\n",
             escapeHTML($auth->subject->homepage),
             escapeHTML($auth->subject->name));
    }
    else
    {
      print "<p>Hello!</p>\n";
    }
  }
  else
  {
    print "<p>Greetings stranger!</p>\n";
  }

DESCRIPTION ^

FOAF+SSL (a.k.a. WebID) is a simple authentication scheme described at http://esw.w3.org/topic/foaf+ssl. This module implements the server end of FOAF+SSL in Perl.

It is suitable for handling authentication using FOAF+SSL over HTTPS. Your web server needs to be using HTTPS, configured to request client certificates, and make the certificate PEM available to your script. If you are using Apache, this means that you want to set the following directives in your SSL virtual host setup:

 SSLEngine on
 SSLVerifyClient optional_no_ca
 SSLVerifyDepth  1
 SSLOptions +StdEnvVars +ExportCertData

Configuration

Constructors

Public Methods

COOKIES ^

FOAF+SSL is entirely RESTful: there is no state kept between requests. This really simplifies authentication for both parties (client and server) for one-off requests. However, because FOAF+SSL requires the server to make various HTTP requests to authenticate the client, each request is slowed down significantly.

Cookies provide us with a way of speeding this up. Use of cookies is entirely optional, but greatly increases the speed of authentication for the second and subsequent requests a client makes. If your FOAF+SSL-secured service generally requires clients to make multiple requests in a short period, you should seriously consider using cookies to speed this up.

The method works like this: on the first request, authentication happens as normal. However, all RDF files relevant to authenticating the client are kept on disk (usually somewhere like '/tmp') in N-Triples format. They are associated with a session that is given a randomly generated identifier. This random identifier is sent the client as a cookie. On subsequent requests, the client includes the cookie and thus CGI::Auth::FOAF_SSL is able to retrieve the data it needs from disk in N-Triples format, rather than having to reach out onto the web for it again.

To use this feature, you must perform authentication before printing anything back to the client, use CGI::Auth::FOAF_SSL's cookie method, and then pass that to the client as part of the HTTP response header.

  use CGI qw(:all);
  use CGI::Auth::FOAF_SSL;
  
  my $auth = CGI::Auth::FOAF_SSL->new_from_cgi;
  
  if (defined $auth && $auth->is_secure)
  {
    print header('-type' => 'text/html',
                 '-cookie' => $auth->cookie);

    my $user = $auth->agent;
    # ...
  }
  else # anonymous access
  {
    print header('-type' => 'text/html');
    
    # ...
  }

Old sessions are automatically purged after an hour of inactivity.

BUGS ^

Please report any bugs to http://rt.cpan.org/.

SEE ALSO ^

Helper module: CGI::Auth::FOAF_SSL::Agent.

Advanced developer documentation: CGI::Auth::FOAF_SSL::Advanced.

Related modules: CGI, RDF::Trine, RDF::ACL.

Information about FOAF+SSL: http://lists.foaf-project.org/mailman/listinfo/foaf-protocols, http://esw.w3.org/topic/foaf+ssl.

SSL in Apache: http://httpd.apache.org/docs/2.0/mod/mod_ssl.html.

Mailing list for general Perl RDF/SemWeb discussion and support: http://www.perlrdf.org/.

AUTHOR ^

Toby Inkster, <tobyink@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2009-2011 by Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: