.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "LWP::Authen::OAuth 3pm" .TH LWP::Authen::OAuth 3pm "2021-01-07" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" LWP::Authen::OAuth \- generate signed OAuth requests .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& require LWP::Authen::OAuth; .Ve .SS "Google" .IX Subsection "Google" .Vb 5 \& # Google uses \*(Aqanonymous\*(Aq 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 \*(Aqrequest\*(Aq token \& my $r = $ua\->post( "https://www.google.com/accounts/OAuthGetRequestToken", \& [ \& oauth_consumer_key => \*(Aqanonymous\*(Aq, \& oauth_callback => \*(Aqhttp://example.net/oauth\*(Aq, \& xoauth_displayname => \*(AqExample Application\*(Aq, \& scope => \*(Aqhttps://docs.google.com/feeds/\*(Aq, \& ] \& ); \& 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( \*(Aqhttp:\*(Aq ); \& $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}\en"; \& \& # turn the \*(Aqrequest\*(Aq token into an \*(Aqaccess\*(Aq token with the verifier \& # returned by google \& $r = $ua\->post( "https://www.google.com/accounts/OAuthGetAccessToken", [ \& oauth_consumer_key => \*(Aqanonymous\*(Aq, \& 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 .Ve .SS "Twitter" .IX Subsection "Twitter" Sending status updates to a single account is quite easy if you create an application. The \f(CW\*(C`oauth_consumer_key\*(C'\fR and \f(CW\*(C`oauth_consumer_secret\*(C'\fR come from the 'Application Details' page and the \f(CW\*(C`oauth_token\*(C'\fR and \f(CW\*(C`oauth_token_secret\*(C'\fR from the 'My Access Token' page. .PP .Vb 6 \& my $ua = LWP::Authen::OAuth\->new( \& oauth_consumer_key => \*(Aqxxx1\*(Aq, \& oauth_consumer_secret => \*(Aqxxx2\*(Aq, \& oauth_token => \*(Aqyyy1\*(Aq, \& oauth_token_secret => \*(Aqyyy2\*(Aq, \& ); \& \& $ua\->post( \*(Aqhttp://api.twitter.com/1/statuses/update.json\*(Aq, [ \& status => \*(AqPosted this using LWP::Authen::OAuth!\*(Aq \& ]); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a sub-class of LWP::UserAgent that generates OAuth 1.0 signed requests. You should familiarise yourself with OAuth at . .PP This module only supports \s-1HMAC_SHA1\s0 signing. .PP OAuth nonces are generated using the Perl random number generator. To set a nonce manually define 'oauth_nonce' in your requests via a \s-1CGI\s0 parameter or the Authorization header \- see the OAuth documentation. .SH "METHODS" .IX Header "METHODS" .ie n .IP "$ua = LWP::Authen::OAuth\->new( ... )" 4 .el .IP "\f(CW$ua\fR = LWP::Authen::OAuth\->new( ... )" 4 .IX Item "$ua = LWP::Authen::OAuth->new( ... )" Takes the same options as \*(L"new\*(R" in LWP::UserAgent plus optionally: .Sp .Vb 4 \& oauth_consumer_key \& oauth_consumer_secret \& oauth_token \& oauth_token_secret .Ve .Sp Most services will require some or all of these to be set even if it's just 'anonymous'. .ie n .IP "$ua\->oauth_update_from_response( $r )" 4 .el .IP "\f(CW$ua\fR\->oauth_update_from_response( \f(CW$r\fR )" 4 .IX Item "$ua->oauth_update_from_response( $r )" Update the \f(CW\*(C`oauth_token\*(C'\fR and \f(CW\*(C`oauth_token_secret\*(C'\fR from an HTTP::Response object returned by a previous request e.g. when converting a request token into an access token. .ie n .IP "$key = $ua\->oauth_consumer_key( [ \s-1KEY\s0 ] )" 4 .el .IP "\f(CW$key\fR = \f(CW$ua\fR\->oauth_consumer_key( [ \s-1KEY\s0 ] )" 4 .IX Item "$key = $ua->oauth_consumer_key( [ KEY ] )" Get and optionally set the consumer key. .ie n .IP "$secret = $ua\->oauth_consumer_secret( [ \s-1SECRET\s0 ] )" 4 .el .IP "\f(CW$secret\fR = \f(CW$ua\fR\->oauth_consumer_secret( [ \s-1SECRET\s0 ] )" 4 .IX Item "$secret = $ua->oauth_consumer_secret( [ SECRET ] )" Get and optionally set the consumer secret. .ie n .IP "$token = $ua\->oauth_token( [ \s-1TOKEN\s0 ] )" 4 .el .IP "\f(CW$token\fR = \f(CW$ua\fR\->oauth_token( [ \s-1TOKEN\s0 ] )" 4 .IX Item "$token = $ua->oauth_token( [ TOKEN ] )" Get and optionally set the oauth token. .ie n .IP "$secret = $ua\->oauth_token_secret( [ \s-1SECRET\s0 ] )" 4 .el .IP "\f(CW$secret\fR = \f(CW$ua\fR\->oauth_token_secret( [ \s-1SECRET\s0 ] )" 4 .IX Item "$secret = $ua->oauth_token_secret( [ SECRET ] )" Get and optionally set the oauth token secret. .SH "SEE ALSO" .IX Header "SEE ALSO" LWP::UserAgent, MIME::Base64, Digest::SHA, \s-1URI\s0, URI::Escape .SS "Rationale" .IX Subsection "Rationale" I think the complexity in OAuth is in the parameter normalisation and message signing. What this module does is to hide that complexity without replicating the higher-level protocol chatter. .PP In Net::OAuth: .PP .Vb 10 \& $r = Net::OAuth\->request(\*(Aqrequest token\*(Aq)\->new( \& consumer_key => \*(Aqxxx\*(Aq, \& request_url => \*(Aqhttps://photos.example.net/request_token\*(Aq, \& callback => \*(Aqhttp://printer.example.com/request_token_ready\*(Aq, \& ... \& extra_params { \& scope => \*(Aqglobal\*(Aq, \& } \& ); \& $r\->sign; \& $res = $ua\->request(POST $r\->to_url); \& $res = Net::OAuth\->response(\*(Aqrequest token\*(Aq) \& \->from_post_body($res\->content); \& ... etc .Ve .PP In LWP::Authen::OAuth: .PP .Vb 10 \& $ua = LWP::Authen::OAuth\->new( \& oauth_consumer_key => \*(Aqxxx\*(Aq \& ); \& $res = $ua\->post( \*(Aqhttps://photos.example.net/request_token\*(Aq, [ \& oauth_callback => \*(Aqhttp://printer.example.com/request_token_ready\*(Aq, \& ... \& scope => \*(Aqglobal\*(Aq, \& ]); \& $ua\->oauth_update_from_response( $res ); \& ... etc .Ve .PP Net::OAuth, OAuth::Lite. .SH "AUTHOR" .IX Header "AUTHOR" Timothy D Brody .PP Copyright 2011 University of Southampton, \s-1UK\s0 .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself