Class: KeycloakAdmin::ClientAuthzScopeClient

Inherits:
Client
  • Object
show all
Defined in:
lib/keycloak-admin/client/client_authz_scope_client.rb

Instance Method Summary collapse

Methods inherited from Client

#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url

Constructor Details

#initialize(configuration, realm_client, client_id, resource_id = nil) ⇒ ClientAuthzScopeClient

Returns a new instance of ClientAuthzScopeClient.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 3

def initialize(configuration, realm_client, client_id, resource_id = nil)
  super(configuration)
  raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
  @realm_client = realm_client
  @client_id = client_id
  @resource_id = resource_id
end

Instance Method Details

#authz_scopes_url(client_id, resource_id = nil, id = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 45

def authz_scopes_url(client_id, resource_id = nil, id = nil)
  if resource_id
    "#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/resource/#{resource_id}/scopes"
  elsif id
    "#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/scope/#{id}"
  else
    "#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/scope"
  end
end

#build(name, display_name, icon_uri) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 63

def build(name, display_name, icon_uri)
  scope              = ClientAuthzScopeRepresentation.new
  scope.name         = name
  scope.icon_uri     = icon_uri
  scope.display_name = display_name
  scope
end

#create!(name, display_name, icon_uri) ⇒ Object



11
12
13
14
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 11

def create!(name, display_name, icon_uri)
  response = save(build(name, display_name, icon_uri))
  ClientAuthzScopeRepresentation.from_hash(JSON.parse(response))
end

#delete(scope_id) ⇒ Object



23
24
25
26
27
28
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 23

def delete(scope_id)
  execute_http do
    RestClient::Resource.new(authz_scopes_url(@client_id, nil, scope_id), @configuration.rest_client_options).delete(headers)
  end
  true
end

#get(scope_id) ⇒ Object



30
31
32
33
34
35
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 30

def get(scope_id)
  response = execute_http do
    RestClient::Resource.new(authz_scopes_url(@client_id, nil, scope_id), @configuration.rest_client_options).get(headers)
  end
  ClientAuthzScopeRepresentation.from_hash(JSON.parse(response))
end

#listObject



16
17
18
19
20
21
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 16

def list
  response = execute_http do
    RestClient::Resource.new(authz_scopes_url(@client_id, @resource_id), @configuration.rest_client_options).get(headers)
  end
  JSON.parse(response).map { |role_as_hash| ClientAuthzScopeRepresentation.from_hash(role_as_hash) }
end

#save(scope_representation) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 55

def save(scope_representation)
  execute_http do
    RestClient::Resource.new(authz_scopes_url(@client_id), @configuration.rest_client_options).post(
      create_payload(scope_representation), headers
    )
  end
end

#search(name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/keycloak-admin/client/client_authz_scope_client.rb', line 37

def search(name)
  url = "#{authz_scopes_url(@client_id)}?first=0&max=11&deep=false&name=#{name}"
  response = execute_http do
    RestClient::Resource.new(url, @configuration.rest_client_options).get(headers)
  end
  JSON.parse(response).map { |role_as_hash| ClientAuthzScopeRepresentation.from_hash(role_as_hash) }
end