Skip to content

Commit

Permalink
Merge pull request #372 from terenceponce/invalidate_token
Browse files Browse the repository at this point in the history
Implement oauth2/invalidate_token
  • Loading branch information
sferik committed Mar 25, 2013
2 parents 833bc12 + 51e53fe commit b30e18c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/twitter/api/oauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'twitter/api/utils'
require 'twitter/token'

module Twitter
module API
module OAuth
include Twitter::API::Utils

# 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
# @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.
# @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)
object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'twitter/api/friends_and_followers'
require 'twitter/api/help'
require 'twitter/api/lists'
require 'twitter/api/oauth'
require 'twitter/api/places_and_geo'
require 'twitter/api/saved_searches'
require 'twitter/api/search'
Expand Down Expand Up @@ -32,6 +33,7 @@ class Client
include Twitter::API::FriendsAndFollowers
include Twitter::API::Help
include Twitter::API::Lists
include Twitter::API::OAuth
include Twitter::API::PlacesAndGeo
include Twitter::API::SavedSearches
include Twitter::API::Search
Expand Down
7 changes: 7 additions & 0 deletions lib/twitter/token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'twitter/base'

module Twitter
class Token < Twitter::Base
attr_reader :token_type, :access_token
end
end
23 changes: 23 additions & 0 deletions spec/twitter/api/oauth_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'helper'

describe Twitter::API::OAuth do

before do
@client = Twitter::Client.new
end

describe "#invalidate_token" do
before do
stub_post("/oauth2/invalidate_token").with(:body => {:access_token => "AAAA%2FAAA%3DAAAAAAAA"}).to_return(:body => '{"access_token" : "AAAA%2FAAA%3DAAAAAAAA"}', :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
expect(a_post("/oauth2/invalidate_token").with(:body => {:access_token => "AAAA%2FAAA%3DAAAAAAAA"})).to have_been_made
end
it "returns the invalidated token" do
token = @client.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
expect(token.access_token).to eq "AAAA%2FAAA%3DAAAAAAAA"
expect(token.token_type).to eq nil
end
end
end

0 comments on commit b30e18c

Please sign in to comment.