Changeset 15866

Show
Ignore:
Timestamp:
07/16/08 00:04:29 (6 years ago)
Author:
lopnor
Message:

lang/perl/Apache2-AuthenOpenID: merged per_dir_config branch to trunk

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Apache2-AuthenOpenID/trunk/lib/Apache2/AuthenOpenID.pm

    r11424 r15866  
    6060sub return_to { 
    6161    my ($self, $params, $arg) = @_; 
    62     my $class = ref $self; 
    63     my $i = Apache2::Module::get_config($class, $params->server); 
    64     $i->{'return_to'} = $arg; 
     62    $self->{'return_to'} = $arg; 
    6563} 
    6664 
    6765sub trust_root { 
    6866    my ($self, $params, $arg) = @_; 
    69     my $class = ref $self; 
    70     my $i = Apache2::Module::get_config($class, $params->server); 
    71     $i->{'trust_root'} = $arg; 
     67    $self->{'trust_root'} = $arg; 
    7268} 
    7369 
    7470sub consumer_secret { 
    7571    my ($self, $params, $arg) = @_; 
    76     my $class = ref $self; 
    77     my $i = Apache2::Module::get_config($class, $params->server); 
    78     $i->{'consumer_secret'} = $arg; 
     72    $self->{'consumer_secret'} = $arg; 
    7973} 
    8074 
     
    8276    my ($self, $r) = @_; 
    8377    lc $r->auth_type eq lc $self->auth_type or return Apache2::Const::DECLINED; 
    84     my $cf = Apache2::Module::get_config($self, $r->server); 
     78 
     79    my $cf = Apache2::Module::get_config($self, $r->server, $r->per_dir_config); 
     80    $r->log->debug( 
     81       sprintf "tr=%s rt=%s cs=%s", $cf->{'trust_root'}, $cf->{'return_to'}, $cf->{'consumer_secret'} 
     82    ); 
    8583    unless ($cf->{'trust_root'} && $cf->{'return_to'} && $cf->{'consumer_secret'}) { 
    8684        $r->log_error("You need to specify trust_root, return_to, and consumer_secret."); 
     
    10199        . $r->uri; 
    102100 
    103     my $q = CGI->new($r); 
    104101    my %cookie_in = CGI::Cookie->parse($r->headers_in->{Cookie}); 
    105102 
    106     my $csr = Net::OpenID::Consumer->new( 
    107         args => $q, 
    108         ua => LWPx::ParanoidAgent->new, 
    109         consumer_secret => $cf->{'consumer_secret'}, 
    110     ); 
    111103    if ($request_url eq $cf->{'return_to'}) { 
     104        my $q = CGI->new($r); 
     105        my $csr = Net::OpenID::Consumer->new( 
     106            args            => $q, 
     107            ua              => LWPx::ParanoidAgent->new, 
     108            consumer_secret => $cf->{'consumer_secret'}, 
     109        ); 
     110 
     111        $r->log->debug("$request_url is return_to"); 
    112112        if (my $identity = $q->param('identity')) { 
    113113            my $claimed_identity = $csr->claimed_identity($identity) 
     
    117117                trust_root => $cf->{'trust_root'}, 
    118118            ); 
     119            $r->log->debug("clamed_identity=$claimed_identity  check_url=$check_url"); 
    119120            $r->err_headers_out->set(Location => $check_url); 
    120121            return Apache2::Const::REDIRECT; 
    121122        } elsif (my $setup_url = $csr->user_setup_url) { 
     123            $r->log->debug("setup_url=$setup_url"); 
    122124            $r->err_headers_out->set(Location => $setup_url); 
    123125            return Apache2::Const::REDIRECT; 
    124126        } elsif ($csr->user_cancel) { 
     127            $r->log->debug("user_canceled."); 
    125128            return Apache2::Const::HTTP_UNAUTHORIZED; 
    126129        } elsif (my $vident = $csr->verified_identity) { 
     130            $r->log->debug('verified_identity'); 
    127131            my $url = $vident->url; 
    128132            $url =~ s{(^https?://|/$)}{}g; 
     
    136140            if (%cookie_in && (my $dest = $cookie_in{$cookie_dest_name})) { 
    137141                $r->headers_out->set('Location' => $dest->value); 
     142                $r->log->debug('return to cookie_dest='. $dest->value); 
    138143            } else { 
    139144                $r->headers_out->set('Location' => $cf->{'trust_root'}); 
     145                $r->log->debug('redirect to trust_root'); 
    140146            } 
    141147            my $cookie_dest_erase = CGI::Cookie->new( 
     
    148154            return Apache2::Const::REDIRECT; 
    149155        } 
     156 
     157        $r->log_error("Error validating identity: " . $csr->err); 
    150158        return Apache2::Const::HTTP_UNAUTHORIZED; 
    151159    } 
     
    170178sub set_custom_response { 
    171179    my ($self, $r) = @_; 
    172     my $cf = Apache2::Module::get_config($self, $r->server); 
     180    my $cf = Apache2::Module::get_config($self, $r->server, $r->per_dir_config); 
    173181    my $auth_name = $r->auth_name; 
    174182    my $html = <<END;