Show
Ignore:
Timestamp:
10/15/07 10:48:31 (13 months ago)
Author:
lopnor
Message:

lang/perl/Apache2-AuthenOpenID: make HTML tidy, modify variable names, add configuration check

Location:
lang/perl/Apache2-AuthenOpenID/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Apache2-AuthenOpenID/trunk/Changes

    r476 r485  
    11Revision history for Perl extension Apache2::AuthenOpenID. 
     2 
     30.02  Mon Oct 15 10:40:00 2007 
     4        - made HTML tidy 
     5    - modify variable names 
     6    - add configuration check 
    27 
    380.01  Sun Oct 14 09:30:07 2007 
  • lang/perl/Apache2-AuthenOpenID/trunk/README

    r476 r485  
    66      PerlLoadModule Apache2::AuthenOpenID 
    77 
    8       AuthType OpenID 
    9       AuthName "My private documents" 
    10       return_to http://sample.com/path/to/callback 
    11       trust_root http://sample.com/your/trust_root/ 
    12       consumer_secret "your consumer secret" 
    13       require user sample.com/someidentity 
     8      AuthType          OpenID 
     9      AuthName          "My private documents" 
     10      return_to         http://sample.com/path/to/callback 
     11      trust_root        http://sample.com/your/trust_root/ 
     12      consumer_secret   "your consumer secret" 
     13      require           user sample.com/someidentity 
    1414 
    1515DESCRIPTION 
     
    1717 
    1818SEE ALSO 
    19     Net::OpenID::Consumer <http://openid.net> 
     19    Net::OpenID::Consumer <http://openid.net/> 
    2020 
    2121AUTHOR 
  • lang/perl/Apache2-AuthenOpenID/trunk/lib/Apache2/AuthenOpenID.pm

    r476 r485  
    77use Apache2::Module; 
    88use Apache2::ServerUtil; 
     9use Apache2::Log; 
    910use Apache2::Const -compile => qw( 
    1011    HTTP_UNAUTHORIZED OK DECLINED REDIRECT OR_AUTHCFG TAKE1 
     
    1617use LWPx::ParanoidAgent; 
    1718 
    18 our $VERSION = '0.01'; 
     19our $VERSION = '0.02'; 
    1920 
    2021my @directives = ( 
     
    2324        func            => __PACKAGE__ . '::AuthType', 
    2425        req_override    => Apache2::Const::OR_AUTHCFG, 
    25         args_how        => Apache2::Const::TAKE1 
     26        args_how        => Apache2::Const::TAKE1, 
    2627    }, 
    2728    { 
     
    2930        func            => __PACKAGE__ . '::return_to', 
    3031        req_override    => Apache2::Const::OR_AUTHCFG, 
    31         args_how        => Apache2::Const::TAKE1 
     32        args_how        => Apache2::Const::TAKE1, 
     33        errmsg          => 'return_to http://sample.com/trust_root/callback', 
    3234    }, 
    3335    { 
     
    3537        func            => __PACKAGE__ . '::trust_root', 
    3638        req_override    => Apache2::Const::OR_AUTHCFG, 
    37         args_how        => Apache2::Const::TAKE1 
     39        args_how        => Apache2::Const::TAKE1, 
     40        errmsg          => 'return_to http://sample.com/trust_root/', 
    3841    }, 
    3942    { 
     
    4144        func            => __PACKAGE__ . '::consumer_secret', 
    4245        req_override    => Apache2::Const::OR_AUTHCFG, 
    43         args_how        => Apache2::Const::TAKE1 
     46        args_how        => Apache2::Const::TAKE1, 
     47        errmsg          => 'consumer_secret "Your consumer secret goes here"', 
    4448    }, 
    4549); 
     
    7882 
    7983    $r->auth_type =~ m{^OpenID$}i or return Apache2::Const::DECLINED; 
    80     (my $cookie_name = __PACKAGE__."-".$r->auth_name) =~ s/::/-/g; 
    81     my $dest_cookie_name = $cookie_name.'-destination'; 
     84 
     85    my $cf = Apache2::Module::get_config(__PACKAGE__, $r->server); 
     86    unless ($cf->{'trust_root'} && $cf->{'return_to'} && $cf->{'consumer_secret'}) { 
     87        $r->log_error("You need to specify trust_root, return_to, and consumer_secret."); 
     88        die; 
     89    } 
     90 
     91    (my $cookie_name = __PACKAGE__."-".$r->auth_name) =~ s/(::|\s+)/-/g; 
     92    my $cookie_dest_name = $cookie_name.'-destination'; 
    8293    &set_custom_response($r); 
    8394 
     
    8899    ); 
    89100 
    90     my $cf = Apache2::Module::get_config(__PACKAGE__, $r->server); 
    91  
    92101    my $request_url = "http://" 
    93102        . ($r->headers_in->{'X-Forwarded-Host'} || $r->hostname) 
     
    95104 
    96105    my $q = CGI->new($r); 
    97     my %cookie = CGI::Cookie->parse($r->headers_in->{Cookie}); 
     106    my %cookie_in = CGI::Cookie->parse($r->headers_in->{Cookie}); 
    98107 
    99108    my $csr = Net::OpenID::Consumer->new( 
     
    121130            my $time = time(); 
    122131            my $token = &calc_token($url, $time, $cf->{'consumer_secret'}); 
    123             my $cookie = CGI::Cookie->new( 
     132            my $cookie_out = CGI::Cookie->new( 
    124133                -name => $cookie_name, 
    125134                -value => [ $url, $time, $token ], 
    126135            ); 
    127136            $r->user($url); 
    128             if (%cookie && (my $dest = $cookie{$dest_cookie_name})) { 
     137            if (%cookie_in && (my $dest = $cookie_in{$cookie_dest_name})) { 
    129138                $r->headers_out->set('Location' => $dest->value); 
    130139            } else { 
    131140                $r->headers_out->set('Location' => $cf->{'trust_root'}); 
    132141            } 
    133             my $erase = CGI::Cookie->new( 
    134                 -name => $dest_cookie_name, 
     142            my $cookie_dest_erase = CGI::Cookie->new( 
     143                -name => $cookie_dest_name, 
    135144                -value => 'erase', 
    136145                -expires => '-1d', 
    137146            ); 
    138             $r->err_headers_out->add('Set-Cookie' => $cookie); 
    139             $r->err_headers_out->add('Set-Cookie' => $erase); 
     147            $r->err_headers_out->add('Set-Cookie' => $cookie_out); 
     148            $r->err_headers_out->add('Set-Cookie' => $cookie_dest_erase); 
    140149            return Apache2::Const::REDIRECT; 
    141150        } 
    142151        return Apache2::Const::HTTP_UNAUTHORIZED; 
    143152    } 
    144     if (%cookie && $cookie{$cookie_name}){ 
    145         my ($url, $time, $token) = $cookie{$cookie_name}->value; 
     153    if (%cookie_in && $cookie_in{$cookie_name}){ 
     154        my ($url, $time, $token) = $cookie_in{$cookie_name}->value; 
    146155        if (&calc_token($url, $time, $cf->{'consumer_secret'}) eq $token) { 
    147156            $r->user($url); 
     
    149158        } 
    150159    } 
    151     unless (%cookie && $cookie{$dest_cookie_name}) { 
    152         my $dest_cookie = CGI::Cookie->new( 
    153             -name => $dest_cookie_name, 
     160    unless (%cookie_in && $cookie_in{$cookie_dest_name}) { 
     161        my $cookie_dest_out = CGI::Cookie->new( 
     162            -name => $cookie_dest_name, 
    154163            -value => $request_url, 
    155164            -expires => '+10m', 
    156165        ); 
    157         $r->err_headers_out->set('Set-Cookie' => $dest_cookie); 
     166        $r->err_headers_out->set('Set-Cookie' => $cookie_dest_out); 
    158167    } 
    159168    return Apache2::Const::HTTP_UNAUTHORIZED; 
     
    165174    my $auth_name = $r->auth_name; 
    166175    my $html = <<END; 
    167 <html> 
     176<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
     177<html lang="en"> 
    168178<head> 
    169179    <title>401 Unauthorized</title> 
     180    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    170181    <meta http-equiv="Content-Style-Type" content="text/css"> 
    171182    <style type="text/css"><!-- 
     
    192203        <p> 
    193204        Please enter your OpenID identifiier:<br> 
    194         <input id="identity" type="text" name="identity"> 
    195         <input type="submit" value="Login with OpenID"> 
     205        <input id="identity" type="text" name="identity" value="" tabindex="1"> 
     206        <input type="submit" value="Login with OpenID" tabindex="2"> 
    196207        </p> 
    197208    </form> 
     
    226237  PerlLoadModule Apache2::AuthenOpenID 
    227238 
    228   AuthType OpenID 
    229   AuthName "My private documents" 
    230   return_to http://sample.com/path/to/callback 
    231   trust_root http://sample.com/your/trust_root/ 
    232   consumer_secret "your consumer secret" 
    233   require user sample.com/someidentity 
     239  AuthType          OpenID 
     240  AuthName          "My private documents" 
     241  return_to         http://sample.com/path/to/callback 
     242  trust_root        http://sample.com/your/trust_root/ 
     243  consumer_secret   "your consumer secret" 
     244  require           user sample.com/someidentity 
    234245 
    235246=head1 DESCRIPTION 
     
    240251 
    241252L<Net::OpenID::Consumer> 
    242 L<http://openid.net> 
     253L<http://openid.net/> 
    243254 
    244255=head1 AUTHOR