Class: Rack::Pubcookie::Auth

Inherits:
Object
  • Object
show all
Includes:
AES, DES
Defined in:
lib/rack/pubcookie/auth.rb

Instance Method Summary collapse

Methods included from DES

#des_decrypt

Methods included from AES

#aes_decrypt

Constructor Details

#initialize(app, login_server, host, appid, keyfile, granting_cert, opts = {}) ⇒ Auth

Returns a new instance of Auth.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rack/pubcookie/auth.rb', line 12

def initialize app, , host, appid, keyfile, granting_cert,
    opts = {}
  @app          = app
  @login_server = 
  @host         = host
  @appid        = appid
  @keyfile      = keyfile
  @granting = OpenSSL::X509::Certificate.new(::File.read(granting_cert))
  ::File.open(@keyfile, 'rb'){ |f| @key = f.read.bytes.to_a }

  @options = opts
  @options[:expires_after] = 24 * 3600 # 24 hrs
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rack/pubcookie/auth.rb', line 26

def call env
  request = Rack::Request.new env

  if request.path == '/auth/pubcookie'
    response = Rack::Response.new 
  else
    request.env['REMOTE_USER'] = extract_username request
    status, headers, body = @app.call(request.env)
    response = Rack::Response.new body, status, headers

    if !request.params['pubcookie_g'].nil? &&
        request.params['pubcookie_g'] != request.cookies['pubcookie_g']
      response.set_cookie 'pubcookie_g', :path => '/', :secure => true,
        :value => request.params['pubcookie_g']
    end
  end

  response.finish
end