Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement oauth2/invalidate_token #372

Merged
merged 1 commit into from
Mar 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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