Module: Twitter::REST::OAuth

Includes:
Utils
Included in:
API
Defined in:
lib/twitter/rest/oauth.rb

Constant Summary

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING

Instance Method Summary (collapse)

Methods included from Utils

flat_pmap, pmap

Instance Method Details

- (Twitter::Token) invalidate_token(access_token, options = {})

Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Required



42
43
44
45
46
# File 'lib/twitter/rest/oauth.rb', line 42

def invalidate_token(access_token, options = {})
  access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
  options[:access_token] = access_token
  perform_with_object(:post, '/oauth2/invalidate_token', options, Twitter::Token)
end

- (String) reverse_token

Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Required



55
56
57
58
59
60
61
62
# File 'lib/twitter/rest/oauth.rb', line 55

def reverse_token
  conn = connection.dup
  conn.builder.swap(4, Twitter::REST::Response::ParseErrorJson)
  response = conn.post('/oauth/request_token?x_auth_mode=reverse_auth') do |request|
    request.headers[:authorization] = oauth_auth_header(:post, 'https://api.twitter.com/oauth/request_token', :x_auth_mode => 'reverse_auth').to_s
  end
  response.body
end

- (Twitter::Token) token(options = {}) Also known as: bearer_token

Allows a registered application to obtain an OAuth 2 Bearer Token, which can be used to make API requests on an application's own behalf, without a user context.

Only one bearer token may exist outstanding for an application, and repeated requests to this method will yield the same already-existent token until it has been invalidated.

Examples:

Generate a Bearer Token

client = Twitter::REST::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
bearer_token = client.token

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Required



26
27
28
29
30
# File 'lib/twitter/rest/oauth.rb', line 26

def token(options = {})
  options[:bearer_token_request] = true
  options[:grant_type] ||= 'client_credentials'
  perform_with_object(:post, '/oauth2/token', options, Twitter::Token)
end