Class: KeycloakAdmin::OrganizationClient
- Inherits:
-
Client
- Object
- Client
- KeycloakAdmin::OrganizationClient
show all
- Defined in:
- lib/keycloak-admin/client/organization_client.rb
Instance Method Summary
collapse
-
#add_identity_provider(organization_id, identity_provider_alias) ⇒ Object
-
#add_member(organization_id, user_id) ⇒ Object
-
#associated_with_member(member_id, brief_representation = true) ⇒ Object
-
#associated_with_member_url(member_id, brief_representation = true) ⇒ Object
-
#build(name, alias_name, enabled, description, redirect_url = nil, domains = [], attributes = {}) ⇒ Object
-
#count(exact = nil, query = nil, search = nil) ⇒ Object
-
#count_url(exact, query, search) ⇒ Object
-
#create!(name, alias_name, enabled, description, redirect_url = nil, domains = [], attributes = {}) ⇒ Object
-
#delete(organization_id) ⇒ Object
-
#delete_identity_provider(organization_id, identity_provider_alias) ⇒ Object
-
#delete_member(organization_id, member_id) ⇒ Object
-
#get(organization_id) ⇒ Object
-
#get_identity_provider(organization_id, identity_provider_alias) ⇒ Object
-
#get_member(organization_id, member_id) ⇒ Object
-
#identity_provider_url(organization_id, identity_provider_alias) ⇒ Object
-
#identity_providers(organization_id) ⇒ Object
-
#identity_providers_url(organization_id) ⇒ Object
-
#initialize(configuration, realm_client) ⇒ OrganizationClient
constructor
A new instance of OrganizationClient.
-
#invite_existing_user(organization_id, user_id) ⇒ Object
-
#invite_existing_user_url(organization_id) ⇒ Object
-
#invite_user(organization_id, email, first_name, last_name) ⇒ Object
-
#invite_user_url(organization_id) ⇒ Object
-
#list(brief_representation = true, exact = nil, first = nil, max = nil, query = nil, search = nil) ⇒ Object
This endpoint does not return members.
-
#member_url(organization_id, member_id) ⇒ Object
-
#members(organization_id, exact = nil, first = nil, max = nil, membership_type = nil, search = nil) ⇒ Object
-
#members_count(organization_id) ⇒ Object
-
#members_count_url(organization_id) ⇒ Object
-
#members_url(organization_id) ⇒ Object
-
#members_url_with_query_parameters(organization_id, exact, first, max, membership_type, search) ⇒ Object
-
#organization_url(organization_id) ⇒ Object
-
#organizations_url ⇒ Object
-
#organizations_url_with_parameters(brief_representation, exact, first, max, query, search) ⇒ Object
-
#save(organization_representation) ⇒ Object
This operation does not associate members and identity providers.
-
#update(organization_representation) ⇒ Object
Methods inherited from Client
#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url
Constructor Details
#initialize(configuration, realm_client) ⇒ OrganizationClient
Returns a new instance of OrganizationClient.
3
4
5
6
7
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 3
def initialize(configuration, realm_client)
super(configuration)
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
@realm_client = realm_client
end
|
Instance Method Details
#add_identity_provider(organization_id, identity_provider_alias) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 77
def add_identity_provider(organization_id, identity_provider_alias)
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
execute_http do
RestClient::Resource.new(identity_providers_url(organization_id), @configuration.rest_client_options).post(identity_provider_alias, )
end
true
end
|
#add_member(organization_id, user_id) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 125
def add_member(organization_id, user_id)
raise ArgumentError.new("user_id must be defined") if user_id.nil?
execute_http do
RestClient::Resource.new(members_url(organization_id), @configuration.rest_client_options).post(user_id, )
end
true
end
|
#associated_with_member(member_id, brief_representation = true) ⇒ Object
147
148
149
150
151
152
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 147
def associated_with_member(member_id, brief_representation=true)
response = execute_http do
RestClient::Resource.new(associated_with_member_url(member_id, brief_representation), @configuration.rest_client_options).get()
end
JSON.parse(response).map { |organization_as_hash| OrganizationRepresentation.from_hash(organization_as_hash) }
end
|
#associated_with_member_url(member_id, brief_representation = true) ⇒ Object
189
190
191
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 189
def associated_with_member_url(member_id, brief_representation=true)
"#{organizations_url}/members/#{member_id}/organizations?briefRepresentation=#{brief_representation}"
end
|
#build(name, alias_name, enabled, description, redirect_url = nil, domains = [], attributes = {}) ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 225
def build(name, alias_name, enabled, description, redirect_url=nil, domains=[], attributes={})
unless domains.is_a?(Array)
raise ArgumentError.new("domains must be an Array, got #{new_domains.class}")
end
unless domains.all? { |domain| domain.is_a?(KeycloakAdmin::OrganizationDomainRepresentation) }
raise ArgumentError.new("All items in domains must be of type OrganizationDomainRepresentation")
end
organization = OrganizationRepresentation.new
organization.name = name
organization.alias = alias_name
organization.enabled = enabled
organization.description = description
organization.redirect_url = redirect_url
organization.domains = domains
organization.attributes = attributes
organization
end
|
#count(exact = nil, query = nil, search = nil) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 17
def count(exact=nil, query=nil, search=nil)
response = execute_http do
RestClient::Resource.new(count_url(exact, query, search), @configuration.rest_client_options).get()
end
response.to_i
end
|
#count_url(exact, query, search) ⇒ Object
172
173
174
175
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 172
def count_url(exact, query, search)
query_parameters = {exact: exact, q: query, search: search}.compact.to_a.map { |e| "#{e[0]}=#{e[1]}" }.join("&")
"#{organizations_url}/count?#{query_parameters}"
end
|
#create!(name, alias_name, enabled, description, redirect_url = nil, domains = [], attributes = {}) ⇒ Object
41
42
43
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 41
def create!(name, alias_name, enabled, description, redirect_url=nil, domains=[], attributes={})
save(build(name, alias_name, enabled, description, redirect_url, domains, attributes))
end
|
#delete(organization_id) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 24
def delete(organization_id)
execute_http do
RestClient::Resource.new(organization_url(organization_id), @configuration.rest_client_options).delete()
end
true
end
|
#delete_identity_provider(organization_id, identity_provider_alias) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 85
def delete_identity_provider(organization_id, identity_provider_alias)
execute_http do
RestClient::Resource.new(identity_provider_url(organization_id, identity_provider_alias), @configuration.rest_client_options).delete()
end
true
end
|
#delete_member(organization_id, member_id) ⇒ Object
133
134
135
136
137
138
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 133
def delete_member(organization_id, member_id)
execute_http do
RestClient::Resource.new(member_url(organization_id, member_id), @configuration.rest_client_options).delete()
end
true
end
|
#get(organization_id) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 55
def get(organization_id)
response = execute_http do
RestClient::Resource.new(organization_url(organization_id), @configuration.rest_client_options).get()
end
OrganizationRepresentation.from_hash(JSON.parse(response))
end
|
#get_identity_provider(organization_id, identity_provider_alias) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 69
def get_identity_provider(organization_id, identity_provider_alias)
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
response = execute_http do
RestClient::Resource.new("#{identity_providers_url(organization_id)}/#{identity_provider_alias}", @configuration.rest_client_options).get()
end
IdentityProviderRepresentation.from_hash(JSON.parse(response))
end
|
#get_member(organization_id, member_id) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 140
def get_member(organization_id, member_id)
response = execute_http do
RestClient::Resource.new(member_url(organization_id, member_id), @configuration.rest_client_options).get()
end
MemberRepresentation.from_hash(JSON.parse(response))
end
|
#identity_provider_url(organization_id, identity_provider_alias) ⇒ Object
167
168
169
170
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 167
def identity_provider_url(organization_id, identity_provider_alias)
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
"#{identity_providers_url(organization_id)}/#{identity_provider_alias}"
end
|
#identity_providers(organization_id) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 62
def identity_providers(organization_id)
response = execute_http do
RestClient::Resource.new(identity_providers_url(organization_id), @configuration.rest_client_options).get()
end
JSON.parse(response).map { |idp_as_hash| IdentityProviderRepresentation.from_hash(idp_as_hash) }
end
|
#identity_providers_url(organization_id) ⇒ Object
163
164
165
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 163
def identity_providers_url(organization_id)
"#{organization_url(organization_id)}/identity-providers"
end
|
#invite_existing_user(organization_id, user_id) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 106
def invite_existing_user(organization_id, user_id)
raise ArgumentError.new("user_id must be defined") if user_id.nil?
execute_http do
RestClient::Resource.new(invite_existing_user_url(organization_id), @configuration.rest_client_options).post({id: user_id}, .merge(content_type: "application/x-www-form-urlencoded"))
end
true
end
|
#invite_existing_user_url(organization_id) ⇒ Object
202
203
204
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 202
def invite_existing_user_url(organization_id)
"#{organization_url(organization_id)}/members/invite-existing-user"
end
|
#invite_user(organization_id, email, first_name, last_name) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 114
def invite_user(organization_id, email, first_name, last_name)
execute_http do
RestClient::Resource.new(invite_user_url(organization_id), @configuration.rest_client_options).post({
email: email,
firstName: first_name,
lastName: last_name
}, .merge(content_type: "application/x-www-form-urlencoded"))
end
true
end
|
#invite_user_url(organization_id) ⇒ Object
206
207
208
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 206
def invite_user_url(organization_id)
"#{organization_url(organization_id)}/members/invite-user"
end
|
#list(brief_representation = true, exact = nil, first = nil, max = nil, query = nil, search = nil) ⇒ Object
This endpoint does not return members
10
11
12
13
14
15
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 10
def list(brief_representation=true, exact=nil, first=nil, max=nil, query=nil, search=nil)
response = execute_http do
RestClient::Resource.new(organizations_url_with_parameters(brief_representation, exact, first, max, query, search), @configuration.rest_client_options).get()
end
JSON.parse(response).map { |organization_as_hash| OrganizationRepresentation.from_hash(organization_as_hash) }
end
|
#member_url(organization_id, member_id) ⇒ Object
197
198
199
200
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 197
def member_url(organization_id, member_id)
raise ArgumentError.new("member_id must be defined") if member_id.nil?
"#{organization_url(organization_id)}/members/#{member_id}"
end
|
#members(organization_id, exact = nil, first = nil, max = nil, membership_type = nil, search = nil) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 99
def members(organization_id, exact=nil, first=nil, max=nil, membership_type=nil, search=nil)
response = execute_http do
RestClient::Resource.new(members_url_with_query_parameters(organization_id, exact, first, max, membership_type, search), @configuration.rest_client_options).get()
end
JSON.parse(response).map { |member_as_hash| MemberRepresentation.from_hash(member_as_hash) }
end
|
#members_count(organization_id) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 92
def members_count(organization_id)
response = execute_http do
RestClient::Resource.new(members_count_url(organization_id), @configuration.rest_client_options).get()
end
response.to_i
end
|
#members_count_url(organization_id) ⇒ Object
193
194
195
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 193
def members_count_url(organization_id)
"#{organization_url(organization_id)}/members/count"
end
|
#members_url(organization_id) ⇒ Object
210
211
212
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 210
def members_url(organization_id)
"#{organization_url(organization_id)}/members"
end
|
#members_url_with_query_parameters(organization_id, exact, first, max, membership_type, search) ⇒ Object
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 214
def members_url_with_query_parameters(organization_id, exact, first, max, membership_type, search)
query_parameters = {
exact: exact,
first: first,
max: max,
membershipType: membership_type,
search: search
}.compact.to_a.map { |e| "#{e[0]}=#{e[1]}" }.join("&")
"#{organization_url(organization_id)}/members?#{query_parameters}"
end
|
#organization_url(organization_id) ⇒ Object
158
159
160
161
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 158
def organization_url(organization_id)
raise ArgumentError.new("organization_id must be defined") if organization_id.nil?
"#{organizations_url}/#{organization_id}"
end
|
#organizations_url ⇒ Object
154
155
156
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 154
def organizations_url
"#{@realm_client.realm_admin_url}/organizations"
end
|
#organizations_url_with_parameters(brief_representation, exact, first, max, query, search) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 177
def organizations_url_with_parameters(brief_representation, exact, first, max, query, search)
query_parameters = {
briefRepresentation: brief_representation,
exact: exact,
first: first,
max: max,
q: query,
search: search
}.compact.to_a.map { |e| "#{e[0]}=#{e[1]}" }.join("&")
"#{organizations_url}?#{query_parameters}"
end
|
#save(organization_representation) ⇒ Object
This operation does not associate members and identity providers
46
47
48
49
50
51
52
53
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 46
def save(organization_representation)
execute_http do
RestClient::Resource.new(organizations_url, @configuration.rest_client_options).post(
create_payload(organization_representation),
)
end
true
end
|
#update(organization_representation) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/keycloak-admin/client/organization_client.rb', line 31
def update(organization_representation)
execute_http do
RestClient::Resource.new(organization_url(organization_representation.id), @configuration.rest_client_options).put(
create_payload(organization_representation),
)
end
get(organization_representation.id)
end
|