Class: Lmb::Developers::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/lmb/developers/auth.rb

Constant Summary collapse

AUTH_PATH =

Path to consume login

'/v1/auth/login'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



4
5
6
# File 'lib/lmb/developers/auth.rb', line 4

def configuration
  @configuration
end

Class Method Details

.configurationObject

Get configuration.



66
67
68
# File 'lib/lmb/developers/auth.rb', line 66

def self.configuration
    @configuration = Lmb::Developers.configuration
end

.login(username, password, user_type = 'employee') ⇒ Hash, Lmb::Developers::Error

Check if user is valid in LMB Ldap.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/lmb/developers/auth.rb', line 39

def self. username, password, user_type = 'employee'
    begin
        uri = URI.parse("#{configuration.url}#{AUTH_PATH}")
        request = Net::HTTP::Post.new(uri)
        request.content_type = "application/x-www-form-urlencoded"
        request["Apikey"] = "#{configuration.api_key}"
        request["Cache-Control"] = "no-cache"
        request.body = "username=#{username}&password=#{password}&userType=#{user_type}"
        req_options = {
            use_ssl: uri.scheme == "https",
        }
        response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
            http.request(request)
        end
        result = JSON.parse(response.body)
        if response.code.to_i == 200
            result
        else
            fail Error, JSON.parse(response.body)
        end
    rescue => exception
        exception
    end

end