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.

Parameters:

  • username (String)

    the ldap username.

  • password (String)

    the ldap password.

  • user_type (String) (defaults to: 'employee')

    the ldap user_type, ‘employee` (default), `customer` or `supplier`

Returns:

  • (Hash)

    when login successful.

    • String

      :userType LDAP user_type

    • String

      :username LDAP of the employee

    • String

      :employeeID ID of the employee

    • String

      :employeeType EmployeeType

    • String

      :fullName Full Name of the user

    • String

      :givenName Given Name of the user

    • String

      :surname Surname of the user

    • String

      :title Mission designated to the user

    • String

      :titleCode Code of mission designated to the user

    • String

      :locationName Site where the user works

    • String

      :locationCode Code from site where the user works

    • String

      :department Department of the user

    • Date

      :contractStartDate Contract start date of the user

    • String

      :email Email of the user

    • String

      :Telephone number of the user’s department

    • String

      :mobile Mobile phone number of the user

    • String

      :manager Manager’s distinguish name from LDAP

    • String

      :o Brands abbreviation. E.g. LM for Leroy Merlin

    • String

      :ou Organization unit

    • Date

      :birthdate Birthdate from user

    • String

      :createdBy Distinguish name from user that created the registry in LDAP

    • String

      :modifiedBy Distinguish name from user that modified the registry in LDAP

    • Byte

      :jpegPhoto Binary Base64 represeting JPEG photo.

  • (Lmb::Developers::Error)

    when login failure.



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