Skip to content

Commit

Permalink
First version of reverse oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
ys committed Sep 25, 2013
1 parent da2280f commit 39139c4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/twitter/rest/api/reverse_auth.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/twitter/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/twitter/rest/api/reverse_auth_spec.rb
Original file line number Diff line number Diff line change
@@ -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.