Permalink
Browse files

First version of reverse oauth

  • Loading branch information...
ys committed Sep 25, 2013
1 parent da2280f commit 39139c4df35b54b86fae29d1ac83a08f4aa293cd
Showing with 41 additions and 1 deletion.
  1. +20 −0 lib/twitter/rest/api/reverse_auth.rb
  2. +3 −1 lib/twitter/rest/client.rb
  3. +18 −0 spec/twitter/rest/api/reverse_auth_spec.rb
@@ -0,0 +1,20 @@
+require 'twitter/rest/api/utils'
+require 'twitter/token'
+
+module Twitter
+ module REST
+ module API
+ module ReverseAuth
+ include Twitter::REST::API::Utils
+
+ def reverse_token
+ conn = connection.dup
+ conn.builder.delete Twitter::REST::Response::ParseJson
+ conn.post('/oauth/request_token?x_auth_mode=reverse_auth') do |request|
+ request.headers[:authorization] = oauth_auth_header(:post, 'https://api.twitter.com/oauth/request_token', x_auth_mode: 'reverse_auth').to_s
+ end.body
+ end
+ end
+ end
+ end
+end
@@ -11,6 +11,7 @@
require 'twitter/rest/api/help'
require 'twitter/rest/api/lists'
require 'twitter/rest/api/oauth'
+require 'twitter/rest/api/reverse_auth'
require 'twitter/rest/api/places_and_geo'
require 'twitter/rest/api/saved_searches'
require 'twitter/rest/api/search'
@@ -38,6 +39,7 @@ class Client < Twitter::Client
include Twitter::REST::API::Help
include Twitter::REST::API::Lists
include Twitter::REST::API::OAuth
+ include Twitter::REST::API::ReverseAuth
include Twitter::REST::API::PlacesAndGeo
include Twitter::REST::API::SavedSearches
include Twitter::REST::API::Search
@@ -129,7 +131,7 @@ def connection
def request(method, path, params={}, signature_params=params)
response = connection.send(method.to_sym, path, params) do |request|
- bearer_token_request = params.delete(:bearer_token_request)
+ bearer_token_request = params.delete(:bearer_token_request)
if bearer_token_request
request.headers[:accept] = '*/*' # It is important we set this, otherwise we get an error.
request.headers[:authorization] = bearer_token_credentials_auth_header
@@ -0,0 +1,18 @@
+require 'helper'
+
+describe Twitter::REST::API::ReverseAuth do
+
+ describe "#token" do
+ #TODO MOCK ALL THE THINGS
+ it "requests the correct resource" do
+ WebMock.disable!
+ client = Twitter::REST::Client.new do |config|
+ config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
+ config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
+ end
+ pp client.reverse_token
+ end
+
+ end
+
+end

0 comments on commit 39139c4

Please sign in to comment.