Class: KeycloakAdmin::Client
- Inherits:
-
Object
- Object
- KeycloakAdmin::Client
show all
- Defined in:
- lib/keycloak-admin/client/client.rb
Direct Known Subclasses
AttackDetectionClient, ClientAuthzPermissionClient, ClientAuthzPolicyClient, ClientAuthzResourceClient, ClientAuthzScopeClient, ClientClient, ClientRoleClient, ClientRoleMappingsClient, ConfigurableTokenClient, GroupClient, IdentityProviderClient, RealmClient, RoleClient, RoleMapperClient, TokenClient, UserClient
Instance Method Summary
collapse
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
4
5
6
|
# File 'lib/keycloak-admin/client/client.rb', line 4
def initialize(configuration)
@configuration = configuration
end
|
Instance Method Details
#create_payload(value) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/keycloak-admin/client/client.rb', line 40
def create_payload(value)
if value.nil?
""
elsif value.kind_of?(Array)
"[#{value.map(&:to_json) * ","}]"
else
value.to_json
end
end
|
#created_id(response) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/keycloak-admin/client/client.rb', line 32
def created_id(response)
unless response.net_http_res.is_a? Net::HTTPCreated
raise "Create method returned status #{response.net_http_res.message} (Code: #{response.net_http_res.code}); expected status: Created (201)"
end
(_head, _separator, id) = response.[:location].rpartition("/")
id
end
|
#current_token ⇒ Object
12
13
14
|
# File 'lib/keycloak-admin/client/client.rb', line 12
def current_token
@current_token ||= KeycloakAdmin.create_client(@configuration, @configuration.client_realm_name).token.get
end
|
#execute_http ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/keycloak-admin/client/client.rb', line 24
def execute_http
yield
rescue RestClient::Exceptions::Timeout => e
raise
rescue RestClient::ExceptionWithResponse => e
http_error(e.response)
end
|
16
17
18
19
20
21
22
|
# File 'lib/keycloak-admin/client/client.rb', line 16
def
{
Authorization: "Bearer #{current_token.access_token}",
content_type: :json,
accept: :json
}
end
|
#server_url ⇒ Object
8
9
10
|
# File 'lib/keycloak-admin/client/client.rb', line 8
def server_url
@configuration.server_url
end
|