class OmniAuth::Aleph::Adaptor

Constants

KEYS

List of keys, all are required.

Public Class Methods

new(configuration={}) click to toggle source
# File lib/omniauth/aleph/adaptor.rb, line 21
def initialize(configuration={})
  self.class.validate(configuration)
  @configuration = configuration.dup
  @logger = @configuration.delete(:logger)
  KEYS.each do |key|
    instance_variable_set("@#{key}", @configuration[key])
  end
end
validate(configuration={}) click to toggle source
# File lib/omniauth/aleph/adaptor.rb, line 11
def self.validate(configuration={})
  message = []
  KEYS.each do |key|
    message << key if(configuration[key].nil?)
  end
  unless message.empty?
    raise ArgumentError.new(message.join(",") +" MUST be provided")
  end
end

Public Instance Methods

authenticate(username, password) click to toggle source
# File lib/omniauth/aleph/adaptor.rb, line 30
def authenticate(username, password)
  url = bor_auth_url + "&bor_id=#{username}&verification=#{password}"
  response = Faraday.get url
  # If we get a successful response AND we are looking at XML and we have a body
  if response.status == 200 && response.headers["content-type"].include?('text/xml') && response.body
    json = MultiXml.parse(response.body)
    if json["bor_auth"] && (error = json["bor_auth"]["error"]).nil?
      return json
    elsif json["bor_auth"].nil?
      raise AlephError.new("Aleph responded, but it's not a response I understand.")
    else
      raise AlephError.new(error)
    end
  else
    raise AlephError.new("Aleph response:\n\t #{@response.inspect}.")
  end
rescue Faraday::ConnectionFailed => e
  raise AlephError.new("Couldn't connect to Aleph.")
end

Private Instance Methods

bor_auth_url() click to toggle source
# File lib/omniauth/aleph/adaptor.rb, line 50
def bor_auth_url
  @bor_auth_url ||= "#{@scheme}://#{@host}:#{@port}"+
    "/X?op=bor-auth&library=#{@library}&sub_library=#{@sub_library}"
end