Sha256: d1d420e779de53cf5f5835adc9e1e6d411b753cf12dc0aed33357887c85d2e2a

Contents?: true

Size: 730 Bytes

Versions: 24

Compression:

Stored size: 730 Bytes

Contents

require 'rack/auth/basic'

module Grape
  module Middleware
    module Auth
      class Basic < Grape::Middleware::Base
        attr_reader :authenticator
        
        def initialize(app, options = {}, &authenticator)
          super(app, options)
          @authenticator = authenticator
        end
        
        def basic_request
          Rack::Auth::Basic::Request.new(env)
        end
        
        def credentials
          basic_request.provided?? basic_request.credentials : [nil, nil]
        end
        
        def before
          unless authenticator.call(*credentials)
            throw :error, :status => 401, :message => "API Authorization Failed."
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
grape-0.5.0 lib/grape/middleware/auth/basic.rb
grape-0.4.1 lib/grape/middleware/auth/basic.rb
grape-0.4.0 lib/grape/middleware/auth/basic.rb
grape-0.3.2 lib/grape/middleware/auth/basic.rb
grape-0.3.1 lib/grape/middleware/auth/basic.rb
grape-0.3.0 lib/grape/middleware/auth/basic.rb
grape-0.2.1.1 lib/grape/middleware/auth/basic.rb
grape-0.2.6 lib/grape/middleware/auth/basic.rb
grape-0.2.5 lib/grape/middleware/auth/basic.rb
grape-0.2.4 lib/grape/middleware/auth/basic.rb
grape-0.2.3 lib/grape/middleware/auth/basic.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/lib/grape/middleware/auth/basic.rb
fragrant-0.0.4 vendor/grape/lib/grape/middleware/auth/basic.rb
grape-0.2.2 lib/grape/middleware/auth/basic.rb
fragrant-0.0.3 vendor/grape/lib/grape/middleware/auth/basic.rb
fragrant-0.0.2 vendor/grape/lib/grape/middleware/auth/basic.rb
fragrant-0.0.1 vendor/grape/lib/grape/middleware/auth/basic.rb
grape-0.2.1 lib/grape/middleware/auth/basic.rb
grape-0.2.0 lib/grape/middleware/auth/basic.rb
grape-0.1.5 lib/grape/middleware/auth/basic.rb