Class: Warden::Bootic::Oauth::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/warden-bootic/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, secret, scopes, callback_url) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
# File 'lib/warden-bootic/proxy.rb', line 6

def initialize(client_id, secret, scopes, callback_url)
  @client_id, @secret, @scopes, @callback_url = client_id, secret, scopes, callback_url
end

Instance Attribute Details

#callback_urlObject

Returns the value of attribute callback_url.



5
6
7
# File 'lib/warden-bootic/proxy.rb', line 5

def callback_url
  @callback_url
end

#client_idObject

Returns the value of attribute client_id.



5
6
7
# File 'lib/warden-bootic/proxy.rb', line 5

def client_id
  @client_id
end

#scopesObject

Returns the value of attribute scopes.



5
6
7
# File 'lib/warden-bootic/proxy.rb', line 5

def scopes
  @scopes
end

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/warden-bootic/proxy.rb', line 5

def secret
  @secret
end

Instance Method Details

#access_token_for(code) ⇒ Object



27
28
29
# File 'lib/warden-bootic/proxy.rb', line 27

def access_token_for(code)
  web_server.get_access_token(code, :redirect_uri => callback_url)
end

#authorize_urlObject



31
32
33
34
35
36
# File 'lib/warden-bootic/proxy.rb', line 31

def authorize_url
  web_server.authorize_url(
    :scope        => scopes,
    :redirect_uri => callback_url
  )
end

#clientObject



19
20
21
22
23
24
25
# File 'lib/warden-bootic/proxy.rb', line 19

def client
  @client ||= OAuth2::Client.new(@client_id, @secret,
                                 :ssl               => ssl_options,
                                 :site              => Warden::Bootic::API_URL,
                                 :authorize_path    => '/oauth/authorize',
                                 :access_token_path => '/oauth/token')
end

#ssl_optionsObject



10
11
12
13
14
15
16
17
# File 'lib/warden-bootic/proxy.rb', line 10

def ssl_options
  ca_file = "/usr/lib/ssl/certs/ca-certificates.crt"
  if File.exists?(ca_file)
    { :ca_file => ca_file }
  else
    { :ca_file => ''}
  end
end

#web_serverObject



38
39
40
# File 'lib/warden-bootic/proxy.rb', line 38

def web_server
  client.web_server
end