Alister West

home is where your code is ...

HTTP OAuth

Extending Net::OAuth::Simple to work with basic_auth

It took me a while trying to extend "Net::OAuth::Simple":http://search.cpan.org/search?module=Net::OAuth::Simple before I realised it was much easier to just monkey-patch the browser arg instead.

package Local::Net::MyUA;
#-----------------------
use base 'LWP::UserAgent';
sub request {
    my ($class, $req, @args) = @_;
    if (ref $req && $req->isa('HTTP::Request') ) {
        $req->headers->authorization_basic( 'Username', 'Password');
    }
    return $class->SUPER::request($req, @args);
}

package Local::Net::MyOAuth;
#--------------------------
use strict;
use base qw(Net::OAuth::Simple);

sub new {
    my ($class, $tokens, $uls)  = @_;
    return $class->SUPER::new(
        tokens => $tokens,
        urls => $urls,
        browser => Local::Net::MyUA->new(),
    );
} 
By Alister West