Permalink
Browse files

Implement oauth2/invalidate_token

  • Loading branch information...
1 parent ff76dea commit 51e53fe4abf14e6dff097eba251d20e95fb52a71 @terenceponce terenceponce committed Mar 20, 2013
Showing with 56 additions and 0 deletions.
  1. +24 −0 lib/twitter/api/oauth.rb
  2. +2 −0 lib/twitter/client.rb
  3. +7 −0 lib/twitter/token.rb
  4. +23 −0 spec/twitter/api/oauth_spec.rb
View
@@ -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
View
@@ -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'
@@ -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
View
@@ -0,0 +1,7 @@
+require 'twitter/base'
+
+module Twitter
+ class Token < Twitter::Base
+ attr_reader :token_type, :access_token
+ end
+end
@@ -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 51e53fe

Please sign in to comment.