39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/rack/auth.rb', line 39
def auth
return @auth if @auth
return nil if @env["HTTP_AUTHORIZATION"].to_s.empty?
type, token = @env["HTTP_AUTHORIZATION"].split(" ", 2).map(&:strip)
type = type.strip.downcase.to_sym
raise TokenValidityError, "Invalid token type." unless AuthHandlers::TOKENS.include? type
raise TokenValidityError, "Authorization data cannot have a zero length." if token.empty?
args = case type
when :bearer, :mac then { "token" => token }
when :basic then Hash[["username","password"].zip(Base64.decode64(token).split(":"))]
end
@auth ||= AuthHandlers[type].call(*args.values) || args
end
|