module ASF::Auth

Rack support for HTTP Authorization, contains a number of classes that can be used within a config.ru of a Passenger application.

Public Class Methods

decode(env) click to toggle source

decode HTTP authorization, when present

# File lib/whimsy/asf/rack.rb, line 11
def self.decode(env)
  class << env; attr_accessor :user, :password; end

  auth = env['HTTP_AUTHORIZATION'] || ENV['HTTP_AUTHORIZATION']

  if auth.to_s.empty?
    env.user = env['REMOTE_USER'] || ENV['USER'] || Etc.getpwuid.name
  else
    require 'base64'
    env.user, env.password = Base64.
      decode64(auth[/^Basic ([A-Za-z0-9+\/=]+)$/,1].to_s).split(':',2)
  end

  env['REMOTE_USER'] ||= env.user

  ASF::Person.new(env.user)
end