-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from terenceponce/invalidate_token
Implement oauth2/invalidate_token
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |