Class: KeycloakAdmin::ImpersonationRepresentation

Inherits:
Representation show all
Defined in:
lib/keycloak-admin/representation/impersonation_representation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Representation

#as_json, from_json, #to_json

Methods included from CamelJson

#camelize

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



5
6
7
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 5

def domain
  @domain
end

#redirectObject

Returns the value of attribute redirect.



5
6
7
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 5

def redirect
  @redirect
end

#same_realmObject

Returns the value of attribute same_realm.



5
6
7
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 5

def same_realm
  @same_realm
end

Returns the value of attribute set_cookie_strings.



5
6
7
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 5

def set_cookie_strings
  @set_cookie_strings
end

#set_cookiesObject

Returns the value of attribute set_cookies.



5
6
7
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 5

def set_cookies
  @set_cookies
end

Class Method Details

.from_response(response, origin) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 11

def self.from_response(response, origin)
  body                              = JSON.parse(response.body)
  representation                    = new
  representation.set_cookie_strings = response.headers[:set_cookie]
  representation.set_cookies        = representation.set_cookie_strings.map { |set_cookie| parse_set_cookie_string(set_cookie, origin) }
  representation.same_realm         = body["sameRealm"]
  representation.redirect           = body["redirect"]
  representation.domain             = origin
  representation
end


22
23
24
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 22

def self.parse_set_cookie_string(set_cookie_string, origin)
  HTTP::Cookie.parse(set_cookie_string, origin).first
end

Instance Method Details

#cookies_to_rails_hashObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/keycloak-admin/representation/impersonation_representation.rb', line 26

def cookies_to_rails_hash
  @set_cookies.map do |cookie|
    rails_cookie = {
      name:     cookie.name,
      value:    cookie.value,
      httponly: cookie.httponly,
      expires:  cookie.expires,
      path:     cookie.path,
      domain:   cookie.domain
    }
  
    rails_cookie[:max_age] = cookie.max_age if cookie.max_age
    rails_cookie[:secure]  = cookie.secure  if cookie.secure
    rails_cookie
  end
end