[Bps-public-commit] jifty-plugin-authentication-twitter branch, master, updated. 3966574abdb1669f28ee451c7e96692f665007d3

Shawn Moore sartak at bestpractical.com
Tue Jun 8 11:31:10 EDT 2010


The branch, master has been updated
       via  3966574abdb1669f28ee451c7e96692f665007d3 (commit)
      from  06c2427398795dc9bf78c9b425ca1b455a8b757a (commit)

Summary of changes:
 .../Plugin/Authentication/Twitter/Dispatcher.pm    |   26 ++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

- Log -----------------------------------------------------------------
commit 3966574abdb1669f28ee451c7e96692f665007d3
Author: Shawn M Moore <sartak at gmail.com>
Date:   Tue Jun 8 11:31:57 2010 -0400

    Once we get a request token, trade it for an access token

diff --git a/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm b/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
index 2bf597a..0442f23 100644
--- a/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
+++ b/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
@@ -8,6 +8,8 @@ use Net::OAuth::RequestTokenRequest;
 use Net::OAuth::RequestTokenResponse;
 use Net::OAuth::UserAuthRequest;
 use Net::OAuth::UserAuthResponse;
+use Net::OAuth::AccessTokenRequest;
+use Net::OAuth::AccessTokenResponse;
 use HTTP::Request::Common ();
 
 =head1 NAME
@@ -69,8 +71,32 @@ on '/twitter/login' => run {
 };
 
 on '/twitter/callback' => run {
+    my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Authentication::Twitter');
     my $token = Jifty->web->request->argument('oauth_token');
     my $secret = Jifty::CAS->key('twitter_oauth' => $token);
+
+    my $access_token_request = Net::OAuth::AccessTokenRequest->new(
+        consumer_key     => $plugin->consumer_key,
+        consumer_secret  => $plugin->consumer_secret,
+        token            => $token,
+        token_secret     => $secret,
+        request_method   => 'POST',
+        request_url      => 'http://twitter.com/oauth/access_token',
+        signature_method => 'HMAC-SHA1',
+        timestamp        => time,
+        nonce            => $$ * rand,
+    );
+    $access_token_request->sign;
+
+    my $ua = LWP::UserAgent->new;
+
+    my $res = $ua->request(HTTP::Request::Common::POST $access_token_request->to_url);
+    if (!$res->is_success) {
+        die "Something went wrong";
+    }
+
+    my $response = Net::OAuth::AccessTokenResponse->from_post_body($res->content);
+
 };
 
 1;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list