Sha256: 059694ae674a7764dd5307f3f01d43fec96638120fc4a694e11cd0cbeda4b45b

Contents?: true

Size: 578 Bytes

Versions: 3

Compression:

Stored size: 578 Bytes

Contents

class MaitreD::API::AuthenticationGuard < Sliver::Hook
  def continue?
    valid_authorization?
  end

  def respond
    response.status = 401
    response.body   = ['401 Unauthorized']
    response.headers['Content-Length'] = response.body.first.length.to_s
  end

  private

  def expected_credentials
    "#{action.configuration.id}:#{action.configuration.password}"
  end

  def provided_credentials
    Base64.decode64 action.request.env['HTTP_AUTHORIZATION'].gsub(/^Basic /, '')
  end

  def valid_authorization?
    provided_credentials == expected_credentials
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
maitre_d-0.7.1 lib/maitre_d/api/authentication_guard.rb
maitre_d-0.7.0 lib/maitre_d/api/authentication_guard.rb
maitre_d-0.6.1 lib/maitre_d/api/authentication_guard.rb