Class: TwitterOAuth2::Client

Inherits:
Rack::OAuth2::Client
  • Object
show all
Defined in:
lib/twitter_oauth2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
# File 'lib/twitter_oauth2/client.rb', line 5

def initialize(attributes)
  attributes_with_default = {
    host: 'api.twitter.com',
    authorization_endpoint: 'https://twitter.com/i/oauth2/authorize',
    token_endpoint: '/2/oauth2/token'
  }.merge(attributes)
  super attributes_with_default
end

Instance Attribute Details

#code_challengeObject

Returns the value of attribute code_challenge.



3
4
5
# File 'lib/twitter_oauth2/client.rb', line 3

def code_challenge
  @code_challenge
end

#code_challenge_methodObject

Returns the value of attribute code_challenge_method.



3
4
5
# File 'lib/twitter_oauth2/client.rb', line 3

def code_challenge_method
  @code_challenge_method
end

#code_verifierObject

Returns the value of attribute code_verifier.



3
4
5
# File 'lib/twitter_oauth2/client.rb', line 3

def code_verifier
  @code_verifier
end

#stateObject

Returns the value of attribute state.



3
4
5
# File 'lib/twitter_oauth2/client.rb', line 3

def state
  @state
end

Instance Method Details

#access_token!(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/twitter_oauth2/client.rb', line 23

def access_token!(*args)
  options = args.extract_options!
  super({
    # NOTE:
    #  For some reason, Twitter requires client_id duplication both in body & header for confidentail clients.
    #  Follow such behaviour for now.
    #  Hopefully, I can remove this line in near future.
    client_id: identifier,

    code_verifier: args.first || self.code_verifier
  }.merge(options))
end

#authorization_uri(params = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/twitter_oauth2/client.rb', line 14

def authorization_uri(params = {})
  authorization_session!
  super({
    code_challenge: code_challenge,
    code_challenge_method: code_challenge_method,
    state: state
  }.merge(params))
end