Changeset 66

Show
Ignore:
Timestamp:
03/01/06 10:09:27 (3 years ago)
Author:
miya
Message:

modify some files.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • atom_client/trunk/lib/AtomClient.pm

    r57 r66  
    2727            $api->username( $username ); 
    2828            $api->password( $password ); 
     29    } 
     30 
     31    if($c->req->param('auth_method') eq 'basic'){ 
     32        $api->auth_basic(1); 
    2933    } 
    3034 
  • atom_client/trunk/lib/My/XML/Atom/Client.pm

    r60 r66  
    44use warnings; 
    55use base qw(XML::Atom::Client); 
     6use MIME::Base64 qw( encode_base64 ); 
     7use Digest::SHA1 qw( sha1 ); 
    68 
    79sub getFeed { 
     
    9395} 
    9496 
     97sub munge_request { 
     98    my $client = shift; 
     99    my($req) = @_; 
     100    $req->header( 
     101        Accept => 'application/x.atom+xml, application/xml, text/xml, */*', 
     102    ); 
     103    my $nonce = $client->make_nonce; 
     104    my $nonce_enc = encode_base64($nonce, ''); 
     105    my $now = DateTime->now->iso8601 . 'Z'; 
     106    my $digest = encode_base64(sha1($nonce . $now . ($client->password || '')), ''); 
     107    if ($client->use_soap) { 
     108        my $xml = $req->content || ''; 
     109        $xml =~ s!^(<\?xml.*?\?>)!!; 
     110        my $method = $req->method; 
     111        $xml = ($1 || '') . <<SOAP; 
     112<soap:Envelope 
     113  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
     114  xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" 
     115  xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext"> 
     116  <soap:Header> 
     117    <wsse:Security> 
     118      <wsse:UsernameToken> 
     119        <wsse:Username>@{[ $client->username || '' ]}</wsse:Username> 
     120        <wsse:Password Type="wsse:PasswordDigest">$digest</wsse:Password> 
     121        <wsse:Nonce>$nonce_enc</wsse:Nonce> 
     122        <wsu:Created>$now</wsu:Created> 
     123      </wsse:UsernameToken> 
     124    </wsse:Security> 
     125  </soap:Header> 
     126  <soap:Body> 
     127    <$method xmlns="http://schemas.xmlsoap.org/wsdl/http/"> 
     128$xml 
     129    </$method> 
     130  </soap:Body> 
     131</soap:Envelope> 
     132SOAP 
     133        $req->content($xml); 
     134        $req->content_length(length $xml); 
     135        $req->header('SOAPAction', 'http://schemas.xmlsoap.org/wsdl/http/' . $method); 
     136        $req->method('POST'); 
     137        $req->content_type('text/xml'); 
     138    } 
     139    elsif($client->auth_basic){ 
     140        $req->header('Authorization', 'Basic ' . encode_base64($client->username . ':' . $client->password)); 
     141    } 
     142    else { 
     143        $req->header('X-WSSE', sprintf 
     144                     qq(UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"), 
     145                     $client->username || '', $digest, $nonce_enc, $now); 
     146        $req->header('Authorization', 'WSSE profile="UsernameToken"'); 
     147    } 
     148} 
     149 
     150sub auth_basic { 
     151    my $client = shift; 
     152    $client->{auth_basic} = shift if @_; 
     153    $client->{auth_basic}; 
     154} 
     155 
     156 
    951571; 
  • atom_client/trunk/root/default.tt

    r65 r66  
    3030<label>Password: </label><input type="password" name="password" size="20" /><br />  
    3131 
     32<label>Auth Method: </label> 
     33<select name="auth_method"> 
     34<option value="digest">WSSE</option> 
     35<option value="basic">Basic</option> 
     36</select> 
     37<br /> 
     38 
    3239<label>Request Method: </label> 
    3340<select name="request_method">