Class: OmniAuth::Strategies::Zendesk

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/zendesk.rb

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



45
46
47
48
# File 'lib/omniauth/strategies/zendesk.rb', line 45

def callback_phase
  return fail!(:invalid_credentials) if not identity or identity.email == '[email protected]'
  super
end

#identityObject



50
51
52
53
54
55
56
57
58
# File 'lib/omniauth/strategies/zendesk.rb', line 50

def identity
  return unless site && username && password
  client = ZendeskAPI::Client.new do |c|
    c.url = "#{site}/api/v2"
    c.username = username
    c.password = password
  end
  @identity ||= client.current_user
end

#request_phaseObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omniauth/strategies/zendesk.rb', line 28

def request_phase
  if site && username && password
    r = Rack::Response.new
    r.redirect(callback_path, 307)
    r.finish
  else
    OmniAuth::Form.build(
      title: (options[:title] || "Zendesk Authentication"),
      url: callback_path
    ) do |f|
      f.text_field 'Username', options.params.username
      f.password_field 'Password', options.params.password
      f.text_field 'Zendesk Site', options.params.site
    end.to_response
  end
end