Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Greetings, So what? Neither Net::OAuth nor Net::OAuth::Simple include POSTDATA in the signing process, as far as I can tell.

Well, https://metacpan.org/source/SIMONW/Net-OAuth-Simple-1.5/examples/twitter appears like it would work, like the author used it and tested it

So the way Net::OAuth::Simple does things doesn't match the way you try to do it

Is it supposed to sign POSTDATA? I don't know, but I do know there is stuff in your code that doesn't make sense, and doesn't do anything, see

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use Net::OAuth; use HTTP::Request; my $content = '$content'; my $oauth = Net::OAuth->request('protected resource')->new( consumer_key => '...', consumer_secret => '...', token => '...', token_secret => '...', protocol_version => Net::OAuth::PROTOCOL_VERSION_1_0A, signature_method => 'HMAC-SHA1', timestamp => time, nonce => int( rand( 2**32 ) ), request_url => 'https://api.tradeking.com/v1/accounts/3861910 +5/orders.json', request_method => 'POST', extra_params => { POSTDATA => $content }, ); dd( $oauth ); $oauth->signature_elements( [ @{ $oauth->signature_elements }, $conten +t ] ); dd( $oauth ); my $request = HTTP::Request->new( $oauth->request_method, $oauth->request_url, [ 'Authorization' => $oauth->to_authorization_header, 'Content-Type' => 'application/x-www-form-urlencoded', 'TKI_TRADEPASS' => 'myPass', 'TKI_OVERRIDE' => 'true', ], $content, ); dd( $request->as_string ); print( $request->as_string ); __END__ bless({ consumer_key => "...", consumer_secret => "...", extra_params => { POSTDATA => "\$content" }, nonce => 3692298240, protocol_version => 1.001, request_method => "POST", request_url => "https://api.tradeking.com/v1/accounts/38619105/ +orders.json", signature_method => "HMAC-SHA1", timestamp => 1429313493.23438, token => "...", token_secret => "...", version => "1.0", }, "Net::OAuth::ProtectedResourceRequest") bless({ consumer_key => "...", consumer_secret => "...", extra_params => { POSTDATA => "\$content" }, nonce => 3692298240, protocol_version => 1.001, request_method => "POST", request_url => "https://api.tradeking.com/v1/accounts/38619105/ +orders.json", signature_method => "HMAC-SHA1", timestamp => 1429313493.23438, token => "...", token_secret => "...", version => "1.0", }, "Net::OAuth::ProtectedResourceRequest") "POST https://api.tradeking.com/v1/accounts/38619105/orders.json\nAuth +orization: OAuth oauth_consumer_key=\"...\",oauth_nonce=\"3692298240\ +",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1429313493.2 +3438\",oauth_token=\"...\",oauth_version=\"1.0\"\nContent-Type: appli +cation/x-www-form-urlencoded\nTKI-OVERRIDE: true\nTKI-TRADEPASS: myPa +ss\n\n\$content\n" POST https://api.tradeking.com/v1/accounts/38619105/orders.json Authorization: OAuth oauth_consumer_key="...",oauth_nonce="3692298240" +,oauth_signature_method="HMAC-SHA1",oauth_timestamp="1429313493.23438 +",oauth_token="...",oauth_version="1.0" Content-Type: application/x-www-form-urlencoded TKI-OVERRIDE: true TKI-TRADEPASS: myPass $content

do you see that? before/after is no change in the object

Also, if you try to ->sign just like ::Simple you get an error  Can't locate object method "$content" via package "Net::OAuth::ProtectedResourceRequest" at Net/OAuth/Message.pm line 162.

update: removing  $oauth->signature_elements( [ @{ $oauth->signature_elements }, $content ] ); no death, and apparently POSTDATA is taken into account somehow (signature is different)

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use Net::OAuth; use HTTP::Request; my $content = '$content'; my @oargs = ( consumer_key => '...', consumer_secret => '...', token => '...', token_secret => '...', protocol_version => Net::OAuth::PROTOCOL_VERSION_1_0A, signature_method => 'HMAC-SHA1', #~ timestamp => time, #~ nonce => int( rand( 2**32 ) ), timestamp => '1429313655.625', nonce => '2009333760', request_url => 'https://api.tradeking.com/v1/accounts/3861910 +5/orders.json', request_method => 'POST', ); my $oauth = Net::OAuth->request('protected resource')->new( @oargs, ); my $oauthPOST = Net::OAuth->request('protected resource')->new( @oargs, extra_params => { POSTDATA => $content }, ); dd( $oauth ); $_->sign, $_->verify for $oauth, $oauthPOST; dd( $oauth , $oauthPOST ); my $request = HTTP::Request->new( $oauthPOST->request_method, $oauthPOST->request_url, [ 'Authorization' => $oauthPOST->to_authorization_header, 'Content-Type' => 'application/x-www-form-urlencoded', 'TKI_TRADEPASS' => 'myPass', 'TKI_OVERRIDE' => 'true', ], $content, ); dd( $request->as_string ); print( $request->as_string ); __END__ bless({ consumer_key => "...", consumer_secret => "...", extra_params => {}, nonce => 2009333760, protocol_version => 1.001, request_method => "POST", request_url => "https://api.tradeking.com/v1/accounts/38619105/ +orders.json", signature_method => "HMAC-SHA1", timestamp => 1429313655.625, token => "...", token_secret => "...", version => "1.0", }, "Net::OAuth::ProtectedResourceRequest") ( bless({ consumer_key => "...", consumer_secret => "...", extra_params => {}, nonce => 2009333760, protocol_version => 1.001, request_method => "POST", request_url => "https://api.tradeking.com/v1/accounts/3861910 +5/orders.json", signature => "VtlaK9KL6t5I5tWfRPo+lFz/VJU=", signature_method => "HMAC-SHA1", timestamp => 1429313655.625, token => "...", token_secret => "...", version => "1.0", }, "Net::OAuth::ProtectedResourceRequest"), bless({ consumer_key => "...", consumer_secret => "...", extra_params => { POSTDATA => "\$content" }, nonce => 2009333760, protocol_version => 1.001, request_method => "POST", request_url => "https://api.tradeking.com/v1/accounts/3861910 +5/orders.json", signature => "IH21VXqfWRaRFeR+vYC2/kMQtyk=", signature_method => "HMAC-SHA1", timestamp => 1429313655.625, token => "...", token_secret => "...", version => "1.0", }, "Net::OAuth::ProtectedResourceRequest"), ) "POST https://api.tradeking.com/v1/accounts/38619105/orders.json\nAuth +orization: OAuth oauth_consumer_key=\"...\",oauth_nonce=\"2009333760\ +",oauth_signature=\"IH21VXqfWRaRFeR%2BvYC2%2FkMQtyk%3D\",oauth_signat +ure_method=\"HMAC-SHA1\",oauth_timestamp=\"1429313655.625\",oauth_tok +en=\"...\",oauth_version=\"1.0\"\nContent-Type: application/x-www-for +m-urlencoded\nTKI-OVERRIDE: true\nTKI-TRADEPASS: myPass\n\n\$content\ +n" POST https://api.tradeking.com/v1/accounts/38619105/orders.json Authorization: OAuth oauth_consumer_key="...",oauth_nonce="2009333760" +,oauth_signature="IH21VXqfWRaRFeR%2BvYC2%2FkMQtyk%3D",oauth_signature +_method="HMAC-SHA1",oauth_timestamp="1429313655.625",oauth_token="... +",oauth_version="1.0" Content-Type: application/x-www-form-urlencoded TKI-OVERRIDE: true TKI-TRADEPASS: myPass $content

So what next? I dont know :)


In reply to Re^3: Net::OAuth and POST data by Anonymous Monk
in thread Net::OAuth and POST data by gryphon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2020-12-03 01:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (49 votes). Check out past polls.

      Notices?