Permalink
Browse files

Adding oath2/token method

- I had to replicate the functionality of the request method to
  accomodate for the abnormal way we have to make the request
- Configurable can supply the base64 encoded bearer token credential
  • Loading branch information...
1 parent 2ec6142 commit 54cb2c7eff574b0ddfbb3777db19bd5dd9a10039 @paracycle committed Apr 16, 2013
Showing with 22 additions and 1 deletion.
  1. +16 −1 lib/twitter/api/oauth.rb
  2. +6 −0 lib/twitter/configurable.rb
View
@@ -5,7 +5,9 @@ module Twitter
module API
module OAuth
include Twitter::API::Utils
-
+ def token
+ object_from_response(Twitter::Token, :bearer_request, "/oauth2/token", :grant_type => "client_credentials")
+ end
# Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
#
# @see https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
@@ -19,6 +21,19 @@ module OAuth
def invalidate_token(access_token)
object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
end
+
+ private
+ def bearer_request(path, params={})
+ connection.send(:post, path, params) do |request|
+ request.headers[:accept] = "*/*"
+ request.headers[:authorization] = "Basic #{encoded_bearer_token_credentials}"
+ request.headers[:content_type] = "application/x-www-form-urlencoded; charset=UTF-8"
+ end.env
+ rescue Faraday::Error::ClientError
+ raise Twitter::Error::ClientError
+ rescue MultiJson::DecodeError
+ raise Twitter::Error::DecodeError
+ end
end
end
end
@@ -1,5 +1,6 @@
require 'forwardable'
require 'twitter/error/configuration_error'
+require 'base64'
module Twitter
module Configurable
@@ -53,6 +54,11 @@ def reset!
def application_only_auth?
not @bearer_token.nil?
end
+
+ def encoded_bearer_token_credentials
+ Base64.strict_encode64("#{@consumer_key}:#{@consumer_secret}")
+ end
+
# @return [Hash]
def credentials
{

0 comments on commit 54cb2c7

Please sign in to comment.