Class: OmniAuth::Strategies::Surveymonkey

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/surveymonkey.rb

Constant Summary collapse

DEFAULT_RESPONSE_TYPE =
'code'
DEFAULT_GRANT =
'authorization_code'

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



32
33
34
35
36
37
38
# File 'lib/omniauth/strategies/surveymonkey.rb', line 32

def authorize_params
  super.tap do |params|
    params[:response_type] ||= DEFAULT_RESPONSE_TYPE
    params[:client_id] = options[:client_id]
    params[:api_key] = options[:api_key]
  end
end

#build_access_tokenObject



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

def build_access_token
  verifier = request.params['code']
  token = client.auth_code.get_token(verifier, token_params)
end

#callback_pathObject



92
93
94
95
96
97
98
99
100
# File 'lib/omniauth/strategies/surveymonkey.rb', line 92

def callback_path
  @callback_path ||= begin
    path = options[:callback_path] if options[:callback_path].is_a?(String)
    path ||= current_path if options[:callback_path].respond_to?(:call) && options[:callback_path].call(env)
    path ||= custom_path(:request_path)
    path ||= "#{path_prefix}/#{name}/callback"
    path
  end
end

#callback_phaseObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/omniauth/strategies/surveymonkey.rb', line 45

def callback_phase
  options[:client_options][:token_url] = "/oauth/token?api_key=#{options[:api_key]}"
  self.access_token = build_access_token
  self.env['omniauth.auth'] = auth_hash
  call_app!

  rescue ::OAuth2::Error, CallbackError => e
    fail!(:invalid_credentials, e)
  rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
    fail!(:timeout, e)
  rescue ::SocketError => e
    fail!(:failed_to_connect, e)
end

#callback_urlObject



68
69
70
# File 'lib/omniauth/strategies/surveymonkey.rb', line 68

def callback_url
  full_host + script_name + callback_path
end

#full_hostObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/omniauth/strategies/surveymonkey.rb', line 72

def full_host
  case OmniAuth.config.full_host
  when String
    OmniAuth.config.full_host
  when Proc
    OmniAuth.config.full_host.call(env)
  else
    if request.scheme && request.url.match(URI::ABS_URI)
      uri = URI.parse(request.url.gsub(/\?.*$/, ''))
      uri.path = ''
      uri.scheme = 'https' if ssl?
      uri.to_s
    end
  end
end

#raw_infoObject



28
29
30
# File 'lib/omniauth/strategies/surveymonkey.rb', line 28

def raw_info
  @raw_info ||= access_token.get('/v3/users/me').parsed
end

#script_nameObject



88
89
90
# File 'lib/omniauth/strategies/surveymonkey.rb', line 88

def script_name
  @env['SCRIPT_NAME'] || ''
end

#token_paramsObject



59
60
61
62
63
64
65
66
# File 'lib/omniauth/strategies/surveymonkey.rb', line 59

def token_params
  super.tap do |params|
    params[:grant_type] ||= DEFAULT_GRANT
    params[:client_id] = options[:client_id]
    params[:client_secret] = options[:client_secret]
    params[:redirect_uri] = callback_url
  end
end