Changeset 485 for lang/perl/Apache2-AuthenOpenID
- Timestamp:
- 10/15/07 10:48:31 (6 years ago)
- Location:
- lang/perl/Apache2-AuthenOpenID/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Apache2-AuthenOpenID/trunk/Changes
r476 r485 1 1 Revision history for Perl extension Apache2::AuthenOpenID. 2 3 0.02 Mon Oct 15 10:40:00 2007 4 - made HTML tidy 5 - modify variable names 6 - add configuration check 2 7 3 8 0.01 Sun Oct 14 09:30:07 2007 -
lang/perl/Apache2-AuthenOpenID/trunk/README
r476 r485 6 6 PerlLoadModule Apache2::AuthenOpenID 7 7 8 AuthType OpenID9 AuthName "My private documents"10 return_to http://sample.com/path/to/callback11 trust_root http://sample.com/your/trust_root/12 consumer_secret "your consumer secret"13 require user sample.com/someidentity8 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 14 14 15 15 DESCRIPTION … … 17 17 18 18 SEE ALSO 19 Net::OpenID::Consumer <http://openid.net >19 Net::OpenID::Consumer <http://openid.net/> 20 20 21 21 AUTHOR -
lang/perl/Apache2-AuthenOpenID/trunk/lib/Apache2/AuthenOpenID.pm
r476 r485 7 7 use Apache2::Module; 8 8 use Apache2::ServerUtil; 9 use Apache2::Log; 9 10 use Apache2::Const -compile => qw( 10 11 HTTP_UNAUTHORIZED OK DECLINED REDIRECT OR_AUTHCFG TAKE1 … … 16 17 use LWPx::ParanoidAgent; 17 18 18 our $VERSION = '0.0 1';19 our $VERSION = '0.02'; 19 20 20 21 my @directives = ( … … 23 24 func => __PACKAGE__ . '::AuthType', 24 25 req_override => Apache2::Const::OR_AUTHCFG, 25 args_how => Apache2::Const::TAKE1 26 args_how => Apache2::Const::TAKE1, 26 27 }, 27 28 { … … 29 30 func => __PACKAGE__ . '::return_to', 30 31 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', 32 34 }, 33 35 { … … 35 37 func => __PACKAGE__ . '::trust_root', 36 38 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/', 38 41 }, 39 42 { … … 41 44 func => __PACKAGE__ . '::consumer_secret', 42 45 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"', 44 48 }, 45 49 ); … … 78 82 79 83 $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'; 82 93 &set_custom_response($r); 83 94 … … 88 99 ); 89 100 90 my $cf = Apache2::Module::get_config(__PACKAGE__, $r->server);91 92 101 my $request_url = "http://" 93 102 . ($r->headers_in->{'X-Forwarded-Host'} || $r->hostname) … … 95 104 96 105 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}); 98 107 99 108 my $csr = Net::OpenID::Consumer->new( … … 121 130 my $time = time(); 122 131 my $token = &calc_token($url, $time, $cf->{'consumer_secret'}); 123 my $cookie = CGI::Cookie->new(132 my $cookie_out = CGI::Cookie->new( 124 133 -name => $cookie_name, 125 134 -value => [ $url, $time, $token ], 126 135 ); 127 136 $r->user($url); 128 if (%cookie && (my $dest = $cookie{$dest_cookie_name})) {137 if (%cookie_in && (my $dest = $cookie_in{$cookie_dest_name})) { 129 138 $r->headers_out->set('Location' => $dest->value); 130 139 } else { 131 140 $r->headers_out->set('Location' => $cf->{'trust_root'}); 132 141 } 133 my $ erase = CGI::Cookie->new(134 -name => $ dest_cookie_name,142 my $cookie_dest_erase = CGI::Cookie->new( 143 -name => $cookie_dest_name, 135 144 -value => 'erase', 136 145 -expires => '-1d', 137 146 ); 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); 140 149 return Apache2::Const::REDIRECT; 141 150 } 142 151 return Apache2::Const::HTTP_UNAUTHORIZED; 143 152 } 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; 146 155 if (&calc_token($url, $time, $cf->{'consumer_secret'}) eq $token) { 147 156 $r->user($url); … … 149 158 } 150 159 } 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, 154 163 -value => $request_url, 155 164 -expires => '+10m', 156 165 ); 157 $r->err_headers_out->set('Set-Cookie' => $ dest_cookie);166 $r->err_headers_out->set('Set-Cookie' => $cookie_dest_out); 158 167 } 159 168 return Apache2::Const::HTTP_UNAUTHORIZED; … … 165 174 my $auth_name = $r->auth_name; 166 175 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"> 168 178 <head> 169 179 <title>401 Unauthorized</title> 180 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 170 181 <meta http-equiv="Content-Style-Type" content="text/css"> 171 182 <style type="text/css"><!-- … … 192 203 <p> 193 204 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"> 196 207 </p> 197 208 </form> … … 226 237 PerlLoadModule Apache2::AuthenOpenID 227 238 228 AuthType OpenID229 AuthName "My private documents"230 return_to http://sample.com/path/to/callback231 trust_root http://sample.com/your/trust_root/232 consumer_secret "your consumer secret"233 require user sample.com/someidentity239 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 234 245 235 246 =head1 DESCRIPTION … … 240 251 241 252 L<Net::OpenID::Consumer> 242 L<http://openid.net >253 L<http://openid.net/> 243 254 244 255 =head1 AUTHOR
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)