LWP::A...:OAuth(3pm)
π LWP::Authen::OAuth β generate signed OAuth requests π
okay so bestie, the man page header literally reads LWP::A...:OAuth(3pm) (they truncated it, rude, but whatever) and it lives in the User Contributed Perl Documentation corner of the world. The actual module is LWP::Authen::OAuth and it is so much less scary than the OAuth spec makes it look. let's go π¦
β¨ NAME β¨
LWP::Authen::OAuth β generate signed OAuth requests. that's it, that's the whole job. π
πΈ SYNOPSIS πΈ
require LWP::Authen::OAuth;
π Google
# Google uses 'anonymous' for unregistered Web/offline applications or the
# domain name for registered Web applications
my $ua = LWP::Authen::OAuth->new(
oauth_consumer_secret => "anonymous",
);
# request a 'request' token
my $r = $ua->post( "https://www.google.com/accounts/OAuthGetRequestToken",
[
oauth_consumer_key => 'anonymous',
oauth_callback => 'http://example.net/oauth',
xoauth_displayname => 'Example Application',
scope => 'https://docs.google.com/feeds/',
]
);
die $r->as_string if $r->is_error;
# update the token secret from the HTTP response
$ua->oauth_update_from_response( $r );
# open a browser for the user
# data are returned as form-encoded
my $uri = URI->new( 'http:' );
$uri->query( $r->content );
my %oauth_data = $uri->query_form;
# Direct the user to here to grant you access:
# https://www.google.com/accounts/OAuthAuthorizeToken?
# oauth_token=$oauth_data{oauth_token}\n";
# turn the 'request' token into an 'access' token with the verifier
# returned by google
$r = $ua->post( "https://www.google.com/accounts/OAuthGetAccessToken", [
oauth_consumer_key => 'anonymous',
oauth_token => $oauth_data{oauth_token},
oauth_verifier => $oauth_verifier,
]);
# update the token secret from the HTTP response
$ua->oauth_update_from_response( $r );
# now use the $ua to perform whatever actions you want
π¦ Twitter
Sending status updates to a single account is lowkey easy peasy if you make yourself an application. The oauth_consumer_key and oauth_consumer_secret come straight off the 'Application Details' page, and the oauth_token and oauth_token_secret come off the 'My Access Token' page. four little strings and you're done, periodt. π
my $ua = LWP::Authen::OAuth->new(
oauth_consumer_key => 'xxx1',
oauth_consumer_secret => 'xxx2',
oauth_token => 'yyy1',
oauth_token_secret => 'yyy2',
);
$ua->post( 'http://api.twitter.com/1/statuses/update.json', [
status => 'Posted this using LWP::Authen::OAuth!'
]);
π DESCRIPTION π
This module is a sub-class of LWP::UserAgent and its whole personality is generating OAuth 1.0 signed requests. Before you go anywhere, you should go familiarise yourself with OAuth over at http://oauth.net/. seriously. read it. i'll wait. π«Ά
heads up bestie: this module only supports HMAC_SHA1 signing. no other flavour. that's the whole menu.
OAuth nonces are generated using the Perl random number generator. if you want to set a nonce by hand, define 'oauth_nonce' in your requests β either via a CGI parameter or the Authorization header β see the OAuth documentation for the deets. π§
π METHODS π
$ua = LWP::Authen::OAuth->new( ... )
Takes the same options as "new" in LWP::UserAgent, <em>plus</em> optionally these four little icons:
oauth_consumer_key
oauth_consumer_secret
oauth_token
oauth_token_secret
Most services are gonna require some or all of these to be set, even if it's just 'anonymous'. don't skip this part, i'm begging. π
$ua->oauth_update_from_response( $r )
Updates the oauth_token and oauth_token_secret from an HTTP::Response object that a previous request handed back β like when you're converting a request token into an access token. this is the glow-up method fr fr. β¨
$key = $ua->oauth_consumer_key( [ KEY ] )
Get, and optionally set, the consumer key. π
$secret = $ua->oauth_consumer_secret( [ SECRET ] )
Get, and optionally set, the consumer secret. π€«
$token = $ua->oauth_token( [ TOKEN ] )
Get, and optionally set, the oauth token. β
$secret = $ua->oauth_token_secret( [ SECRET ] )
Get, and optionally set, the oauth token secret. π
π SEE ALSO π
LWP::UserAgent, MIME::Base64, Digest::SHA, URI, URI::Escape
π¦ Rationale
So like, the way i see it, all the actual complexity in OAuth lives in the parameter normalisation and the message signing. What this module does is hide that complexity β without going and replicating all the higher-level protocol chatter. it stays in its lane, and its lane is iconic. π
In Net::OAuth:
$r = Net::OAuth->request('request token')->new(
consumer_key => 'xxx',
request_url => 'https://photos.example.net/request_token',
callback => 'http://printer.example.com/request_token_ready',
...
extra_params {
scope => 'global',
}
);
$r->sign;
$res = $ua->request(POST $r->to_url);
$res = Net::OAuth->response('request token')
->from_post_body($res->content);
... etc
In LWP::Authen::OAuth:
$ua = LWP::Authen::OAuth->new(
oauth_consumer_key => 'xxx'
);
$res = $ua->post( 'https://photos.example.net/request_token', [
oauth_callback => 'http://printer.example.com/request_token_ready',
...
scope => 'global',
]);
$ua->oauth_update_from_response( $res );
... etc
Net::OAuth, OAuth::Lite.
π AUTHOR π
Timothy D Brody <tdb2@ecs.soton.ac.uk>
Copyright 2011 University of Southampton, UK
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself
and that's the whole page, bestie, you ate π«Ά this little gem was generated by perl v5.40.1 and stamped 2025-11-20, so if you're reading it any time after that, know that it's still serving looks. mwah. πβ¨π
π¦ where this page comes from
- ubuntu resolute: liblwp-authen-oauth-perl 1.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblwp-authen-oauth-perl 1.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms