Module: Twitter::REST::OAuth

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

Overview

Methods for OAuth authentication

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Instance Method Details

#invalidate_token(access_token, options = {}) ⇒ String

Revokes an issued OAuth 2 Bearer Token

Examples:

client.invalidate_token('AAAA...')

Parameters:

  • access_token (String)

    The bearer token to revoke.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (String)

    The invalidated token. token_type should be nil.

Raises:

See Also:



47
48
49
50
51
# File 'lib/twitter/rest/oauth.rb', line 47

def invalidate_token(access_token, options = {})
  options = options.dup
  options[:access_token] = access_token
  perform_post("/oauth2/invalidate_token", options).fetch(:access_token)
end

#reverse_tokenString

Returns a reverse auth token for mobile applications

Examples:

client.reverse_token

Returns:

  • (String)

    The token string.

Raises:

See Also:



63
64
65
66
67
68
# File 'lib/twitter/rest/oauth.rb', line 63

def reverse_token
  options = {x_auth_mode: "reverse_auth"}
  url = "https://api.twitter.com/oauth/request_token"
  auth_header = ::Twitter::Headers.new(self, :post, url, options).oauth_auth_header.to_s # steep:ignore ArgumentTypeMismatch
  HTTP.headers(authorization: auth_header).post(url, params: options).to_s
end

#token(options = {}) ⇒ String Also known as: bearer_token

Obtains an OAuth 2 Bearer Token for application-only auth

Examples:

client.token

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (String)

    The Bearer token.

Raises:

See Also:



21
22
23
24
25
26
27
28
29
# File 'lib/twitter/rest/oauth.rb', line 21

def token(options = {})
  options = options.dup
  options[:bearer_token_request] = true
  options[:grant_type] ||= "client_credentials"
  url = "https://api.twitter.com/oauth2/token"
  headers = ::Twitter::Headers.new(self, :post, url, options).request_headers # steep:ignore ArgumentTypeMismatch
  response = HTTP.headers(headers).post(url, form: options)
  response.parse.fetch("access_token")
end