Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow use of Twitter::Token in place of bearer token string

  • Loading branch information...
commit 13596bc60db36ecaf5a1df09ecb322d85d8c2922 1 parent 0fdb7de
@sferik authored
View
3  lib/twitter/api/oauth.rb
@@ -31,11 +31,12 @@ def token
# @rate_limited No
# @authentication Required
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @param access_token [String] The value of the bearer token to revoke.
+ # @param access_token [String, Twitter::Token] The bearer token to revoke.
# @return [Twitter::Token] The invalidated token. token_type should be nil.
# @example Revoke a token
# Twitter.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
def invalidate_token(access_token)
+ access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
end
end
View
8 lib/twitter/client.rb
@@ -93,7 +93,7 @@ def request_setup(method, path, params, signature_params)
request.headers[:accept] = '*/*' # It is important we set this, otherwise we get an error.
elsif params.delete(:app_auth) || !user_token?
unless bearer_token?
- @bearer_token = token[:access_token]
+ @bearer_token = token
Twitter.client.bearer_token = @bearer_token if Twitter.client?
end
request.headers[:authorization] = bearer_auth_header
@@ -132,7 +132,11 @@ def encode_value(value)
end
def bearer_auth_header
- "Bearer #{@bearer_token}"
+ if @bearer_token.is_a?(Twitter::Token) && @bearer_token.token_type == "bearer"
+ "Bearer #{@bearer_token.access_token}"
+ else
+ "Bearer #{@bearer_token}"
+ end
end
def oauth_auth_header(method, path, params={})
View
7 spec/twitter/api/oauth_spec.rb
@@ -44,6 +44,13 @@
expect(token.access_token).to eq "AAAA%2FAAA%3DAAAAAAAA"
expect(token.token_type).to eq nil
end
+ context "with a token" do
+ it "requests the correct resource" do
+ token = Twitter::Token.new(:access_token => "AAAA%2FAAA%3DAAAAAAAA")
+ @client.invalidate_token(token)
+ expect(a_post("/oauth2/invalidate_token").with(:body => {:access_token => "AAAA%2FAAA%3DAAAAAAAA"})).to have_been_made
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.