Module: Teambox::OAuth

Included in:
Client
Defined in:
lib/teambox-client/teambox_oauth.rb

Overview

Methods used to authenticate with OAuth on teambox.com. Normally you won’t have to call these.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



4
5
6
# File 'lib/teambox-client/teambox_oauth.rb', line 4

def access_token
  @access_token
end

Instance Method Details

#authorize_from_accessObject

Authorizes the client from an existing OAuth token



33
34
35
# File 'lib/teambox-client/teambox_oauth.rb', line 33

def authorize_from_access
  @access_token = ::OAuth2::AccessToken.new(nil, @auth[:oauth_token])
end

#authorize_from_request(verifier) ⇒ Object



26
27
28
29
30
# File 'lib/teambox-client/teambox_oauth.rb', line 26

def authorize_from_request(verifier)
  @access_token = consumer.web_server.get_access_token(verifier, :redirect_uri => @auth[:redirect_uri], :grant_type => 'authorization_code')
  @auth[:oauth_token] = @access_token.token
  @access_token
end

#authorized?Boolean

Is the client authorized via OAuth?

Returns:

  • (Boolean)


22
23
24
# File 'lib/teambox-client/teambox_oauth.rb', line 22

def authorized?
  !@access_token.nil?
end

#consumerObject

OAuth consumer required for authentication



7
8
9
10
11
12
13
# File 'lib/teambox-client/teambox_oauth.rb', line 7

def consumer
  return nil if @auth[:oauth_app_id].nil?
  @consumer ||= OAuth2::Client.new(@auth[:oauth_app_id], @auth[:oauth_app_secret], 
                                   :site => consumer_url,
                                   :access_token_path => consumer_url+'oauth/token',
                                   :authorize_path => consumer_url+'oauth/authorize?response_type=code')
end

#consumer_urlObject



15
16
17
18
19
# File 'lib/teambox-client/teambox_oauth.rb', line 15

def consumer_url
  uri = URI.parse(self.class.base_uri)
  uri.path = '/'
  uri.to_s
end