NAME
LWP::Authen::OAuth - generate signed OAuth requests
SYNOPSIS
require LWP::Authen::OAuth;
# 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
Sending status updates to a single account is quite easy if you create an application. The oauth_consumer_key
and oauth_consumer_secret
come from the 'Application Details' page and the oauth_token
and oauth_token_secret
from the 'My Access Token' page.
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 provides a lightweight sub-class of LWP::UserAgent to generate OAuth signed requests. It has a utility method to populate the oauth_token
and oauth_token_secret
from OAuth request-token/access-token responses.
If you want a complete OAuth implementation look at Net::OAuth.
This module currently only supports hmac_sha1 signing.
METHODS
- $ua = LWP::Authen::OAuth->new( ... )
-
Takes the same options as "new" in LWP::UserAgent plus optionally:
oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret
Most services will require some or all of these to be set even if it's just 'anonymous'.
- $ua->oauth_update_from_response( $r )
-
Update the
oauth_token
andoauth_token_secret
from an HTTP::Response object returned by a previous request e.g. when converting a request token into an access token. - $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, Net::OAuth, MIME::Base64, Digest::SHA, URI, URI::Escape
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.