keycloak-admin 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -2
- data/Gemfile.lock +3 -3
- data/README.md +26 -1
- data/lib/keycloak-admin/client/group_client.rb +23 -0
- data/lib/keycloak-admin/representation/group_representation.rb +7 -5
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +2 -0
- data/lib/keycloak-admin/resource/group_resource.rb +4 -0
- data/lib/keycloak-admin/version.rb +1 -1
- data/spec/client/group_client_spec.rb +19 -8
- data/spec/representation/group_representation_spec.rb +15 -0
- data/spec/spec_helper.rb +9 -1
- metadata +7 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a01d12df8eb75fcedbf128aacae50192983a47cb4cfac6c52b1dff4d999aa08
|
|
4
|
+
data.tar.gz: dae8911b975b7aea1989fc8df565047c144da55868569da02039c53fbc8d6963
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f44444327adcb4622856a7397401b5eaeaa10ad55943cce4606f4539340795a2e444f48613c35cdedb41c34431516b9137fec07f163d51c5e7c691ce3a7db17
|
|
7
|
+
data.tar.gz: 2210584caebc4c01e67a7da99740910755759a1edb22fb5c48002c0e51eb3d672460a74723db38bdc0bc639c2effd1cc42e4a8d30b79e185ce0d31a3a6c8ea72
|
data/CHANGELOG.md
CHANGED
|
@@ -5,10 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.21] - 2023-02-03
|
|
9
|
+
|
|
10
|
+
* List users who are a member of a group (thanks to @tlloydthwaites)
|
|
11
|
+
|
|
12
|
+
## [1.0.20] - 2022-12-26
|
|
13
|
+
|
|
14
|
+
* Create subgroups (thanks to @neckhair)
|
|
15
|
+
* Add subgroups to `GroupRepresentation` (thanks to @neckhair)
|
|
16
|
+
* Expose `BaseRoleContainingResource.resource_id` (thanks to @neckhair)
|
|
17
|
+
|
|
8
18
|
## [1.0.19] - 2022-12-03
|
|
9
19
|
|
|
10
|
-
* Remove specific realm roles from user (thanks to @
|
|
11
|
-
* Get role by name (thanks to @
|
|
20
|
+
* Remove specific realm roles from user (thanks to @tlloydthwaites)
|
|
21
|
+
* Get role by name (thanks to @tlloydthwaites)
|
|
12
22
|
|
|
13
23
|
## [1.0.18] - 2022-11-24
|
|
14
24
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
keycloak-admin (1.0.
|
|
4
|
+
keycloak-admin (1.0.21)
|
|
5
5
|
http-cookie (~> 1.0, >= 1.0.3)
|
|
6
6
|
rest-client (~> 2.1)
|
|
7
7
|
|
|
@@ -30,10 +30,10 @@ GEM
|
|
|
30
30
|
rspec-mocks (~> 3.12.0)
|
|
31
31
|
rspec-core (3.12.0)
|
|
32
32
|
rspec-support (~> 3.12.0)
|
|
33
|
-
rspec-expectations (3.12.
|
|
33
|
+
rspec-expectations (3.12.1)
|
|
34
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
35
|
rspec-support (~> 3.12.0)
|
|
36
|
-
rspec-mocks (3.12.
|
|
36
|
+
rspec-mocks (3.12.1)
|
|
37
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
38
|
rspec-support (~> 3.12.0)
|
|
39
39
|
rspec-support (3.12.0)
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ This gem *does not* require Rails.
|
|
|
12
12
|
For example, using `bundle`, add this line to your Gemfile.
|
|
13
13
|
|
|
14
14
|
```ruby
|
|
15
|
-
gem "keycloak-admin", "1.0.
|
|
15
|
+
gem "keycloak-admin", "1.0.21"
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Login
|
|
@@ -119,6 +119,7 @@ All options have a default value. However, all of them can be changed in your in
|
|
|
119
119
|
* Get list of roles, save a role
|
|
120
120
|
* Get list of realms, save/update/delete a realm
|
|
121
121
|
* Get list of client role mappings for a user/group
|
|
122
|
+
* Get list of members of a group
|
|
122
123
|
* Save client role mappings for a user/group
|
|
123
124
|
* Save realm-level role mappings for a user/group
|
|
124
125
|
* Add a Group on a User
|
|
@@ -310,6 +311,30 @@ group_path = "/top"
|
|
|
310
311
|
group_id = KeycloakAdmin.realm("a_realm").groups.create!(group_name, group_path)
|
|
311
312
|
```
|
|
312
313
|
|
|
314
|
+
### Create a new subgroup of an existing group
|
|
315
|
+
|
|
316
|
+
Create a new group as the child of an existing group.
|
|
317
|
+
|
|
318
|
+
```ruby
|
|
319
|
+
parent_id = "7686af34-204c-4515-8122-78d19febbf6e"
|
|
320
|
+
group_name = "test"
|
|
321
|
+
sub_group_id = KeycloakAdmin.realm("a_realm").groups.create_subgroup!(parent_id, group_name)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Get list of members of a group
|
|
325
|
+
|
|
326
|
+
Returns an array of `KeycloakAdmin::UserRepresentation`.
|
|
327
|
+
|
|
328
|
+
```ruby
|
|
329
|
+
KeycloakAdmin.realm("a_realm").group("group_id").members
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
You can specify paging with `first` and `max`:
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
KeycloakAdmin.realm("a_realm").group("group_id").members(first:0, max:100)
|
|
336
|
+
```
|
|
337
|
+
|
|
313
338
|
### Get list of roles in a realm
|
|
314
339
|
|
|
315
340
|
Returns an array of `KeycloakAdmin::RoleRepresentation`.
|
|
@@ -26,6 +26,29 @@ module KeycloakAdmin
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
def create_subgroup!(parent_id, name)
|
|
30
|
+
url = "#{groups_url(parent_id)}/children"
|
|
31
|
+
response = execute_http do
|
|
32
|
+
RestClient::Resource.new(url, @configuration.rest_client_options).post(
|
|
33
|
+
create_payload(build(name, nil)), headers
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
created_id(response)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def members(group_id, first=0, max=100)
|
|
40
|
+
url = "#{groups_url(group_id)}/members"
|
|
41
|
+
query = {first: first.try(:to_i), max: max.try(:to_i)}.compact
|
|
42
|
+
unless query.empty?
|
|
43
|
+
query_string = query.to_a.map { |e| "#{e[0]}=#{e[1]}" }.join("&")
|
|
44
|
+
url = "#{url}?#{query_string}"
|
|
45
|
+
end
|
|
46
|
+
response = execute_http do
|
|
47
|
+
RestClient::Resource.new(url, @configuration.rest_client_options).get(headers)
|
|
48
|
+
end
|
|
49
|
+
JSON.parse(response).map { |user_as_hash| UserRepresentation.from_hash(user_as_hash) }
|
|
50
|
+
end
|
|
51
|
+
|
|
29
52
|
def groups_url(id=nil)
|
|
30
53
|
if id
|
|
31
54
|
"#{@realm_client.realm_admin_url}/groups/#{id}"
|
|
@@ -2,13 +2,15 @@ module KeycloakAdmin
|
|
|
2
2
|
class GroupRepresentation < Representation
|
|
3
3
|
attr_accessor :id,
|
|
4
4
|
:name,
|
|
5
|
-
:path
|
|
5
|
+
:path,
|
|
6
|
+
:sub_groups
|
|
6
7
|
|
|
7
8
|
def self.from_hash(hash)
|
|
8
|
-
group
|
|
9
|
-
group.id
|
|
10
|
-
group.name
|
|
11
|
-
group.path
|
|
9
|
+
group = new
|
|
10
|
+
group.id = hash["id"]
|
|
11
|
+
group.name = hash["name"]
|
|
12
|
+
group.path = hash["path"]
|
|
13
|
+
group.sub_groups = hash.fetch("subGroups", []).map { |sub_group_hash| self.from_hash(sub_group_hash) }
|
|
12
14
|
group
|
|
13
15
|
end
|
|
14
16
|
end
|
|
@@ -111,15 +111,26 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
|
111
111
|
'Create method returned status OK (Code: 200); expected status: Created (201)'
|
|
112
112
|
)
|
|
113
113
|
end
|
|
114
|
+
end
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
describe "#create_subgroup!" do
|
|
117
|
+
let(:realm_name) { "valid-realm" }
|
|
118
|
+
|
|
119
|
+
before(:each) do
|
|
120
|
+
@group_client = KeycloakAdmin.realm(realm_name).groups
|
|
121
|
+
|
|
122
|
+
stub_token_client
|
|
123
|
+
@response = double headers: {
|
|
124
|
+
location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/7686af34-204c-4515-8122-78d19febbf6e'
|
|
125
|
+
}
|
|
126
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return @response
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "creates a subgroup" do
|
|
130
|
+
stub_net_http_res(Net::HTTPCreated, 201, 'Created')
|
|
131
|
+
|
|
132
|
+
group_id = @group_client.create_subgroup!('be061c48-6edd-4783-a726-1a57d4bfa22b', 'subgroup-name')
|
|
133
|
+
expect(group_id).to eq '7686af34-204c-4515-8122-78d19febbf6e'
|
|
123
134
|
end
|
|
124
135
|
end
|
|
125
136
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
RSpec.describe KeycloakAdmin::GroupRepresentation do
|
|
3
|
+
describe ".from_hash" do
|
|
4
|
+
it "parses the sub groups into group representations" do
|
|
5
|
+
group = described_class.from_hash({
|
|
6
|
+
"name" => "group a",
|
|
7
|
+
"subGroups" => [{
|
|
8
|
+
"name" => "subgroup b"
|
|
9
|
+
}]
|
|
10
|
+
})
|
|
11
|
+
expect(group.sub_groups.length).to eq 1
|
|
12
|
+
expect(group.sub_groups.first).to be_a described_class
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -10,7 +10,7 @@ def configure
|
|
|
10
10
|
config.client_secret = "aaaaaaaa"
|
|
11
11
|
config.client_realm_name = "master2"
|
|
12
12
|
config.use_service_account = true
|
|
13
|
-
end
|
|
13
|
+
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
RSpec.configure do |config|
|
|
@@ -27,3 +27,11 @@ def stub_token_client
|
|
|
27
27
|
'refresh_expires_in', 'id_token', 'not_before_policy', 'session_state'
|
|
28
28
|
)
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
def stub_net_http_res(res_class, code, message)
|
|
32
|
+
net_http_res = double(message: message, code: code)
|
|
33
|
+
allow(net_http_res).to receive(:is_a?) do |target_class|
|
|
34
|
+
target_class == res_class
|
|
35
|
+
end
|
|
36
|
+
allow(@response).to receive(:net_http_res).and_return(net_http_res)
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: keycloak-admin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.21
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lorent Lempereur
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-02-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: http-cookie
|
|
@@ -134,6 +134,7 @@ files:
|
|
|
134
134
|
- spec/client/user_client_spec.rb
|
|
135
135
|
- spec/configuration_spec.rb
|
|
136
136
|
- spec/representation/client_representation_spec.rb
|
|
137
|
+
- spec/representation/group_representation_spec.rb
|
|
137
138
|
- spec/representation/identity_provider_mapper_representation_spec.rb
|
|
138
139
|
- spec/representation/identity_provider_representation_spec.rb
|
|
139
140
|
- spec/representation/impersonation_representation_spec.rb
|
|
@@ -147,7 +148,7 @@ homepage: https://github.com/looorent/keycloak-admin-ruby
|
|
|
147
148
|
licenses:
|
|
148
149
|
- MIT
|
|
149
150
|
metadata: {}
|
|
150
|
-
post_install_message:
|
|
151
|
+
post_install_message:
|
|
151
152
|
rdoc_options: []
|
|
152
153
|
require_paths:
|
|
153
154
|
- lib
|
|
@@ -162,8 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
162
163
|
- !ruby/object:Gem::Version
|
|
163
164
|
version: '0'
|
|
164
165
|
requirements: []
|
|
165
|
-
rubygems_version: 3.
|
|
166
|
-
signing_key:
|
|
166
|
+
rubygems_version: 3.0.3.1
|
|
167
|
+
signing_key:
|
|
167
168
|
specification_version: 4
|
|
168
169
|
summary: Keycloak Admin REST API client written in Ruby
|
|
169
170
|
test_files: []
|