| | 97 | sub 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> |
|---|
| | 132 | SOAP |
|---|
| | 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 | |
|---|
| | 150 | sub auth_basic { |
|---|
| | 151 | my $client = shift; |
|---|
| | 152 | $client->{auth_basic} = shift if @_; |
|---|
| | 153 | $client->{auth_basic}; |
|---|
| | 154 | } |
|---|
| | 155 | |
|---|
| | 156 | |
|---|