Sha256: 392ee05e436fa86f4743ee364c1700c5f329dd4bc6cd62f358a5d14dc5662ae6
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
require 'digest' require 'rack' require 'active_model' require 'gollum/auth/version' require 'gollum/auth/request' require 'gollum/auth/user' module Gollum module Auth def self.new(*args) App.new(*args) end class App def initialize(app, users, opts = { }) @app = app users.each { |args| User.new(args).save! } @opts = { allow_unauthenticated_readonly: false }.merge(opts) end def call(env) request = Request.new(env) if request.requires_authentication?(@opts[:allow_unauthenticated_readonly]) auth = Rack::Auth::Basic::Request.new(env) if auth.provided? && auth.basic? && user = User.find_by_credentials(auth.credentials) request.store_author_in_session(user) else return not_authorized end end @app.call(env) end private def not_authorized [ 401, { 'Content-Type' => 'text/plain', 'WWW-Authenticate' => 'Basic realm="Gollum Wiki"' }, [ 'Not authorized' ] ] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gollum-auth-0.7.1 | lib/gollum/auth.rb |
gollum-auth-0.7.0 | lib/gollum/auth.rb |