Sha256: e0d297d120934e66678c6e883e6f8dbd5a6ec2e4376e72bb00184607ca94e576

Contents?: true

Size: 870 Bytes

Versions: 19

Compression:

Stored size: 870 Bytes

Contents

require "sinatra/authorization"

module Integrity
  module Helpers
    module Authorization
      include Sinatra::Authorization

      def authorization_realm
        "Integrity"
      end

      def authorized?
        return true unless Integrity.config[:use_basic_auth]
        !!request.env["REMOTE_USER"]
      end

      def authorize(user, password)
        if Integrity.config[:hash_admin_password]
          password = Digest::SHA1.hexdigest(password)
        end

        !Integrity.config[:use_basic_auth] ||
        (Integrity.config[:admin_username] == user &&
          Integrity.config[:admin_password] == password)
      end

      def unauthorized!(realm=authorization_realm)
        response["WWW-Authenticate"] = %(Basic realm="#{realm}")
        throw :halt, [401, show(:unauthorized, :title => "incorrect credentials")]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
alphasights-integrity-0.1.10 lib/integrity/helpers/authorization.rb
alphasights-integrity-0.1.9.3 lib/integrity/helpers/authorization.rb
alphasights-integrity-0.1.9.4 lib/integrity/helpers/authorization.rb
alphasights-integrity-0.1.9.5 lib/integrity/helpers/authorization.rb
alphasights-integrity-0.1.9.6 lib/integrity/helpers/authorization.rb
alphasights-integrity-0.1.9.7 lib/integrity/helpers/authorization.rb
alphasights-integrity-0.1.9.8 lib/integrity/helpers/authorization.rb
foca-integrity-0.1.9.2 lib/integrity/helpers/authorization.rb
foca-integrity-0.1.9.3 lib/integrity/helpers/authorization.rb
gforces-integrity-0.1.9.3 lib/integrity/helpers/authorization.rb
gforces-integrity-0.1.9.4 lib/integrity/helpers/authorization.rb
imbriaco-integrity-0.1.9.2.1 lib/integrity/helpers/authorization.rb
imbriaco-integrity-0.1.9.2 lib/integrity/helpers/authorization.rb
integrity-integrity-0.1.10 lib/integrity/helpers/authorization.rb
integrity-integrity-0.1.9.3 lib/integrity/helpers/authorization.rb
integrity-0.1.11 lib/integrity/helpers/authorization.rb
integrity-0.1.10 lib/integrity/helpers/authorization.rb
integrity-0.1.9.3 lib/integrity/helpers/authorization.rb
integrity-0.1.9.2 lib/integrity/helpers/authorization.rb