module SimpleApiAuth::Authenticable::ClassMethods

Attributes

saa_options[RW]

Public Instance Methods

api_authenticable?() click to toggle source
# File lib/simple-api-auth/authenticable.rb, line 23
def api_authenticable?
  true
end
generate_saa_key(options = {}) click to toggle source
# File lib/simple-api-auth/authenticable.rb, line 41
def generate_saa_key(options = {})
  length = options[:length] || (Math.log(count + 1, 64) + 5)
  loop do
    key = SecureRandom.urlsafe_base64(length)
    break key unless exists?(saa_options[:saa_key] => key)
  end
end
generate_saa_secret(options = {}) click to toggle source
# File lib/simple-api-auth/authenticable.rb, line 49
def generate_saa_secret(options = {})
  length = options[:length] || 64
  SecureRandom.urlsafe_base64(length)
end
saa_authenticate(request) click to toggle source
# File lib/simple-api-auth/authenticable.rb, line 27
def saa_authenticate(request)
  request = SimpleApiAuth::Request.create(request)
  entity = saa_find(request)
  return false if entity.nil?
  secret_key = entity.send(saa_options[:saa_secret])
  return false unless SimpleApiAuth.valid_signature?(request, secret_key)
  entity
end
saa_find(request) click to toggle source
# File lib/simple-api-auth/authenticable.rb, line 36
def saa_find(request)
  key = SimpleApiAuth.extract_key(request)
  find_by(saa_options[:saa_key] => key)
end