Class: OmniAuth::Strategies::Pubcookie

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy, Rack::Pubcookie::Auth
Defined in:
lib/omniauth/strategies/pubcookie.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options, &block) ⇒ Pubcookie

Returns a new instance of Pubcookie.



11
12
13
14
# File 'lib/omniauth/strategies/pubcookie.rb', line 11

def initialize app, options, &block
  self.pubcookie_options = options
  super app, :pubcookie, &block
end

Instance Method Details

#auth_hash(username) ⇒ Object



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

def auth_hash username
  OmniAuth::Utils.deep_merge(super(), {
    'uid'       => username,
    'provider'  => 'pubcookie',
    'user_info' => {'name' => username}
  })
end

#callback_phaseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omniauth/strategies/pubcookie.rb', line 20

def callback_phase
  username = extract_username request
  request.env['REMOTE_USER'] = username # Part of the pubcookie spec

  if username
    request.env['omniauth.auth'] = auth_hash(username)
    request.env['REQUEST_METHOD'] = 'GET'

    status, headers, body = call_app!

    # Set the actual cookie for pubcookie, as per its spec
    response = Rack::Response.new body, status, headers
    set_pubcookie! request, response

    response.finish
  else
    fail! :login_failed
  end
end

#request_phaseObject



16
17
18
# File 'lib/omniauth/strategies/pubcookie.rb', line 16

def request_phase
  Rack::Response.new().finish
end