Class: Keycloak::Admin::Agent

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/keycloak/admin/agent.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



17
18
19
20
21
22
23
24
# File 'lib/keycloak/admin/agent.rb', line 17

def initialize
  @base_url = 'http://localhost:8080'
  @realm = 'master'
  @username = 'nil'
  @password = 'nil'
  @grant_type = 'password'
  @always_terminate = false
end

Instance Attribute Details

#always_terminateObject

Returns the value of attribute always_terminate.



15
16
17
# File 'lib/keycloak/admin/agent.rb', line 15

def always_terminate
  @always_terminate
end

#base_urlObject

Returns the value of attribute base_url.



15
16
17
# File 'lib/keycloak/admin/agent.rb', line 15

def base_url
  @base_url
end

#grant_typeObject

Returns the value of attribute grant_type.



15
16
17
# File 'lib/keycloak/admin/agent.rb', line 15

def grant_type
  @grant_type
end

#passwordObject

Returns the value of attribute password.



15
16
17
# File 'lib/keycloak/admin/agent.rb', line 15

def password
  @password
end

#realmObject

Returns the value of attribute realm.



15
16
17
# File 'lib/keycloak/admin/agent.rb', line 15

def realm
  @realm
end

#usernameObject

Returns the value of attribute username.



15
16
17
# File 'lib/keycloak/admin/agent.rb', line 15

def username
  @username
end

Instance Method Details

#logoutObject



26
27
28
# File 'lib/keycloak/admin/agent.rb', line 26

def logout
  terminate_session
end

#request(method, path, params: {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/keycloak/admin/agent.rb', line 36

def request(method, path, params: {})
  refresh_session || create_session

  params[:headers] ||= {}
  params[:headers][:Authorization] = "Bearer #{@session['access_token']}"

  response = self.class.send(
    method,
    "#{@base_url}/#{path}",
    body: params[:body],
    headers: params[:headers]
  )

  terminate_session if @always_terminate

  Keycloak::Admin.raise_error(response) if !response.code.between?(200, 299)

  response.parsed_response
end