Class: OmniAuth::Strategies::Desk

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/desk.rb

Overview

An omniauth 1.0 strategy for Desk.com authorization

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



84
85
86
87
# File 'lib/omniauth/strategies/desk.rb', line 84

def callback_phase
  options.client_options.site = session[:site] if session[:site]
  super
end

#get_identifierObject



72
73
74
75
76
77
78
# File 'lib/omniauth/strategies/desk.rb', line 72

def get_identifier
  f = OmniAuth::Form.new :title => 'Desk.com Authorization'
  f.text_field 'Desk.com Site', options.site_param.to_s
  f.html '<p><strong>Hint:</strong> https://YOURSITE.desk.com'
  f.button 'Login'
  f.to_response
end

#identifierObject



51
52
53
54
55
# File 'lib/omniauth/strategies/desk.rb', line 51

def identifier
  session[:site] = options.client_options.site = options.site || validate_site(request.params[options.site_param.to_s])
  session[:site] = options.client_options.site = nil if options.client_options.site == ''
  options.client_options.site
end

#raw_infoObject

Return info gathered from the verify_credentials API call



40
41
42
43
44
# File 'lib/omniauth/strategies/desk.rb', line 40

def raw_info
  @raw_info ||= MultiJson.decode(access_token.get('/api/v2/users/me').body) if access_token
rescue ::Errno::ETIMEDOUT
  raise ::Timeout::Error
end

#request_phaseObject



80
81
82
# File 'lib/omniauth/strategies/desk.rb', line 80

def request_phase
  identifier ? super : get_identifier
end

#uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
# File 'lib/omniauth/strategies/desk.rb', line 57

def uri?(uri)
  uri = URI.parse(uri)
  uri.scheme == 'https'
rescue URI::BadURIError
  false
rescue URI::InvalidURIError
  false
end

#user_infoObject

Provide the “user” portion of the raw_info



47
48
49
# File 'lib/omniauth/strategies/desk.rb', line 47

def 
  @user_info ||= raw_info.nil? ? {} : raw_info
end

#validate_site(site) ⇒ Object



66
67
68
69
70
# File 'lib/omniauth/strategies/desk.rb', line 66

def validate_site(site)
  if site and site != ''
    uri?(site) ? site : "https://#{site}.desk.com"
  end
end