Plack::Middleware::Auth::WebID(3pm)

Plack::Middleware::Auth::WebID3pm

Authentication middleware for webid

Usage

  use Plack::Builder;
  
  my $app   = sub { ... };
  my $cache = CHI->new( ... );
  
  sub unauthenticated
  {
    my ($self, $env) = @_;
    return [
      403,
      [ 'Content-Type' => 'text/plain' ],
      [ '403 Forbidden' ],
    ];
  }
  
  builder
  {
    enable "Auth::WebID",
        cache     => $cache,
        on_unauth => \&unauthenticated;
    $app;
  };

Overview

Plack::Middleware::Auth::WebID is a WebID handler for Plack.

If authentication is successful, then the handler sets "$env->{WEBID}" to the user's WebID URI, and sets "$env->{WEBID_OBJECT}" to a Web::ID object.

Configuration

cache

This may be set to an object that will act as a cache for Web::ID objects.

Plack::Middleware::Auth::WebID does not care what package you use for your caching needs. CHI, Cache::Cache and Cache should all work. In fact, any package that provides a similar one-argument "get" and a two-argument "set" ought to work. Which should you use? Well CHI seems to be best, however it's Moose-based, so usually too slow for CGI applications. Use Cache::Cache for CGI, and CHI otherwise.

You don't need to set a cache at all, but if there's no cache, then reauthentication (which is computationally expensive) happens for every request. Use of a cache with an expiration time of around 15 minutes should significantly speed up the responsiveness of a WebID-secured site. (For forking servers you probably want a cache that is shared between processes, such as a memcached cache.)

on_unauth

Coderef that will be called if authentication is not successful. You can use this to return a "403 Forbidden" page for example, or try an alternative authentication method.

The default coderef used will simply run the application as normal, but setting "$env->{WEBID}" to the empty string.

webid_class

Name of an alternative class to use for WebID authentication instead of Web::ID. Note that any such class would need to provide a compatible "new" constructor.

certificate_env_key

The key within $env where Plack::Middleware::Auth::WebID can find a PEM-encoded client SSL certificate.

Apache keeps this information in "$env->{'SSL_CLIENT_CERT'}", so it should be no surprise that this setting defaults to 'SSL_CLIENT_CERT'.

no_object_please

Suppresses setting "$env->{WEBID_OBJECT}". "$env->{WEBID}" will still be set as usual.

Server support

WebID is an authentication system based on the Semantic Web and HTTPS. It relies on client certificates (but not on certification authorities; self-signed certificates are OK).

So for this authentication module to work...

•

You need to be using a server which supports HTTPS.

Many web PSGI web servers (e.g. HTTP::Server::Simple, Starman, etc) do not support HTTPS natively. In some cases these are used with an HTTPS proxy in front of them.

•

Your HTTPS server needs to request a client certificate from the client.

•

Your HTTPS server needs to expose the client certificate to Plack via $env.

If you're using an HTTPS proxy in front of a non-HTTPS web server, then you might need to be creative to find a way to forward this information to your backend web server.

•

The client browser needs to have a WebID-compatible certificate installed.

Nuff said.

Apache2 (mod_perl and CGI)

The SSLVerifyClient directive can be used to tell Apache that you want it to request a certificate from the client.

Apache is able to deposit the certifcate in an environment variable called SSL_CLIENT_CERT. However by default it might not. Check out the SSLOptions directive and enable the "ExportCertData" option, or if you're using mod_perl try Plack::Middleware::Apache2::ModSSL.

Gepok

Gepok is one of a very small number of PSGI-compatible web servers that supports HTTPS natively. As of 0.20 it will request client certificates, but you will need to use Plack::Middleware::GepokX::ModSSL in order to make the certificate available in the PSGI $env hashref.

Disclaimer of warranties

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Releases

7 releases since Debian 7 (Wheezy); the text changed 4 times.

  1. 7
  2. 8–9
  3. 10
  4. 11
  5. 12–13

Bugs

Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Web-ID>.

Author

Toby Inkster <[email protected]>.

From libweb-id-perl 1.927-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.