Note that there are some explanatory texts on larger screens.

plurals
  1. POnet::oauth return 401 unauthorized even though curl works
    primarykey
    data
    text
    <p>I am attempting to request a token from <a href="https://launchpad.net" rel="nofollow">https://launchpad.net</a>, according to the docs all it wants is a POST to /+request-token with the form encoded values of oauth_consumer_key, oauth_signature, and oauth_signature_method. Providing those items via curl works as expected:</p> <pre><code>curl --data "oauth_consumer_key=test-app&amp;oauth_signature=%26&amp;oauth_signature_method=PLAINTEXT" https://launchpad.net/+request-token </code></pre> <p>However, when i attempt to do it through my perl script it is giving me a 401 unauthorized error.</p> <pre><code>#!/usr/bin/env perl use strict; use YAML qw(DumpFile); use Log::Log4perl qw(:easy); use LWP::UserAgent; use Net::OAuth; $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; use HTTP::Request::Common; use Data::Dumper; use Browser::Open qw(open_browser); my $ua = LWP::UserAgent-&gt;new; my ($home) = glob '~'; my $cfg = "$home/.lp-auth.yml"; my $access_token_url = q[https://launchpad.net/+access-token]; my $authorize_path = q[https://launchpad.net/+authorize-token]; sub consumer_key { 'lp-ua-browser' } sub request_url {"https://launchpad.net/+request-token"} my $request = Net::OAuth-&gt;request('consumer')-&gt;new( consumer_key =&gt; consumer_key(), consumer_secret =&gt; '', request_url =&gt; request_url(), request_method =&gt; 'POST', signature_method =&gt; 'PLAINTEXT', timestamp =&gt; time, nonce =&gt; nonce(), ); $request-&gt;sign; print $request-&gt;to_url; my $res = $ua-&gt;request(POST $request-&gt;to_url, Content $request-&gt;to_post_body); my $token; my $token_secret; print Dumper($res); if ($res-&gt;is_success) { my $response = Net::OAuth-&gt;response('request token')-&gt;from_post_body($res-&gt;content); $token = $response-&gt;token; $token_secret = $response-&gt;token_secret; print "request token ", $token, "\n"; print "request token secret", $token_secret, "\n"; open_browser($authorize_path . "?oauth_token=" . $token); } else { die "something broke ($!)"; } </code></pre> <p>I tried both with <code>$request-&gt;sign</code> and without it as i dont think that is required during the request token phase. Anyway any help with this would be appreciated.</p> <p>Update, switched to LWP::UserAgent and had to pass in both POST and Content :</p> <pre><code>my $res = $ua-&gt;request(POST $request-&gt;to_url, Content $request-&gt;to_post_body); </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload