Class: OmniAuth::Strategies::Nationbuilder

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

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



49
50
51
52
# File 'lib/omniauth/strategies/nationbuilder.rb', line 49

def callback_phase
  options.client_options[:slug] = session.delete("omniauth.nationbuilder.slug")
  super
end

#callback_urlObject

Nationbuilder fails with an invalid callback if the query string is passed along



56
57
58
# File 'lib/omniauth/strategies/nationbuilder.rb', line 56

def callback_url
  full_host + script_name + callback_path
end

#clientObject

Configure site before super initialises the OAuth2 Client



24
25
26
27
28
# File 'lib/omniauth/strategies/nationbuilder.rb', line 24

def client
  options.client_options[:site] = 'https://' + options.client_options[:slug] + '.nationbuilder.com'
    log :debug, "Nation to authorise " + deep_symbolize(options.client_options).inspect
    super
end

#get_slugObject

Build a form to get the nations slug if one has not been supplied



15
16
17
18
19
20
21
# File 'lib/omniauth/strategies/nationbuilder.rb', line 15

def get_slug
  f = OmniAuth::Form.new(:title => 'NationBuilder Authentication')
  f.label_field("Your Nation's Slug", options.slug_param)
  f.input_field('url', options.slug_param)
    f.button "Connect to your Nation"
  f.to_response
end

#request_phaseObject

Override the normal OAuth request_phase to get a slug from the user if one hasn’t been supplied, and insert the slug into the site url



39
40
41
42
43
44
45
46
47
# File 'lib/omniauth/strategies/nationbuilder.rb', line 39

def request_phase
  if slug
    # Store slug on the session
    session["omniauth.nationbuilder.slug"] = options.client_options[:slug] = slug
    super
  else
    get_slug
  end
end

#slugObject

Returns the slug, nil if one has not been specified anywhere



31
32
33
34
35
# File 'lib/omniauth/strategies/nationbuilder.rb', line 31

def slug
  s = options.nation_slug || request.params[options.slug_param.to_s]
  s = nil if s == ''
  s
end