keycloak-admin 1.2.0 → 2.0.0
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/.github/workflows/ci.yml +4 -2
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +17 -20
- data/README.md +9 -5
- data/keycloak-admin.gemspec +4 -3
- data/lib/keycloak-admin/client/attack_detection_client.rb +3 -3
- data/lib/keycloak-admin/client/client.rb +10 -6
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +7 -7
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +5 -5
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +6 -6
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +5 -5
- data/lib/keycloak-admin/client/client_client.rb +6 -6
- data/lib/keycloak-admin/client/client_role_client.rb +1 -1
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +2 -2
- data/lib/keycloak-admin/client/client_scope_client.rb +5 -5
- data/lib/keycloak-admin/client/client_scope_protocol_mapper_client.rb +5 -5
- data/lib/keycloak-admin/client/configurable_token_client.rb +2 -2
- data/lib/keycloak-admin/client/group_client.rb +13 -13
- data/lib/keycloak-admin/client/identity_provider_client.rb +4 -4
- data/lib/keycloak-admin/client/organization_client.rb +18 -18
- data/lib/keycloak-admin/client/realm_client.rb +4 -4
- data/lib/keycloak-admin/client/role_client.rb +6 -6
- data/lib/keycloak-admin/client/role_mapper_client.rb +7 -7
- data/lib/keycloak-admin/client/token_client.rb +1 -3
- data/lib/keycloak-admin/client/user_client.rb +24 -24
- data/lib/keycloak-admin/configuration.rb +1 -1
- data/lib/keycloak-admin/version.rb +1 -1
- data/lib/keycloak-admin.rb +3 -1
- data/spec/client/attack_detection_client_spec.rb +3 -3
- data/spec/client/client_authz_permission_client_spec.rb +5 -5
- data/spec/client/client_authz_policy_client_spec.rb +5 -5
- data/spec/client/client_authz_resource_client_spec.rb +7 -7
- data/spec/client/client_authz_scope_client_spec.rb +5 -5
- data/spec/client/client_client_spec.rb +14 -14
- data/spec/client/client_role_mappings_client_spec.rb +10 -10
- data/spec/client/client_scope_client_spec.rb +7 -7
- data/spec/client/client_scope_protocol_mapper_client_spec.rb +7 -7
- data/spec/client/client_spec.rb +27 -7
- data/spec/client/group_client_spec.rb +47 -47
- data/spec/client/identity_provider_client_spec.rb +5 -5
- data/spec/client/organization_client_spec.rb +31 -31
- data/spec/client/realm_client_spec.rb +20 -20
- data/spec/client/role_client_spec.rb +10 -10
- data/spec/client/role_mapper_client_spec.rb +10 -10
- data/spec/client/token_client_spec.rb +5 -5
- data/spec/client/user_client_spec.rb +29 -29
- data/spec/configuration_spec.rb +2 -2
- data/spec/gemspec_spec.rb +25 -0
- data/spec/integration/client_authorization_spec.rb +4 -4
- data/spec/representation/client_authz_policy_representation_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -8
- metadata +22 -7
|
@@ -8,7 +8,7 @@ module KeycloakAdmin
|
|
|
8
8
|
|
|
9
9
|
def get(group_id)
|
|
10
10
|
response = execute_http do
|
|
11
|
-
|
|
11
|
+
resource(groups_url(group_id)).get(headers)
|
|
12
12
|
end
|
|
13
13
|
GroupRepresentation.from_hash(JSON.parse(response))
|
|
14
14
|
end
|
|
@@ -16,7 +16,7 @@ module KeycloakAdmin
|
|
|
16
16
|
def children(parent_id)
|
|
17
17
|
response = execute_http do
|
|
18
18
|
url = "#{groups_url(parent_id)}/children"
|
|
19
|
-
|
|
19
|
+
resource(url).get(headers)
|
|
20
20
|
end
|
|
21
21
|
JSON.parse(response).map { |group_as_hash| GroupRepresentation.from_hash(group_as_hash) }
|
|
22
22
|
end
|
|
@@ -35,7 +35,7 @@ module KeycloakAdmin
|
|
|
35
35
|
headers
|
|
36
36
|
end
|
|
37
37
|
response = execute_http do
|
|
38
|
-
|
|
38
|
+
resource(groups_url).get(derived_headers)
|
|
39
39
|
end
|
|
40
40
|
JSON.parse(response).map { |group_as_hash| GroupRepresentation.from_hash(group_as_hash) }
|
|
41
41
|
end
|
|
@@ -49,9 +49,9 @@ module KeycloakAdmin
|
|
|
49
49
|
execute_http do
|
|
50
50
|
payload = create_payload(group_representation)
|
|
51
51
|
if group_representation.id
|
|
52
|
-
|
|
52
|
+
resource(groups_url(group_representation.id)).put(payload, headers)
|
|
53
53
|
else
|
|
54
|
-
|
|
54
|
+
resource(groups_url).post(payload, headers)
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -59,7 +59,7 @@ module KeycloakAdmin
|
|
|
59
59
|
def create_subgroup!(parent_id, name, attributes = {})
|
|
60
60
|
url = "#{groups_url(parent_id)}/children"
|
|
61
61
|
response = execute_http do
|
|
62
|
-
|
|
62
|
+
resource(url).post(
|
|
63
63
|
create_payload(build(name, nil, attributes)), headers
|
|
64
64
|
)
|
|
65
65
|
end
|
|
@@ -68,7 +68,7 @@ module KeycloakAdmin
|
|
|
68
68
|
|
|
69
69
|
def delete(group_id)
|
|
70
70
|
execute_http do
|
|
71
|
-
|
|
71
|
+
resource(groups_url(group_id)).delete(headers)
|
|
72
72
|
end
|
|
73
73
|
true
|
|
74
74
|
end
|
|
@@ -81,7 +81,7 @@ module KeycloakAdmin
|
|
|
81
81
|
url = "#{url}?#{query_string}"
|
|
82
82
|
end
|
|
83
83
|
response = execute_http do
|
|
84
|
-
|
|
84
|
+
resource(url).get(headers)
|
|
85
85
|
end
|
|
86
86
|
JSON.parse(response).map { |user_as_hash| UserRepresentation.from_hash(user_as_hash) }
|
|
87
87
|
end
|
|
@@ -90,7 +90,7 @@ module KeycloakAdmin
|
|
|
90
90
|
def get_realm_level_roles(group_id)
|
|
91
91
|
url = "#{groups_url(group_id)}/role-mappings/realm"
|
|
92
92
|
response = execute_http do
|
|
93
|
-
|
|
93
|
+
resource(url).get(headers)
|
|
94
94
|
end
|
|
95
95
|
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
96
96
|
end
|
|
@@ -101,7 +101,7 @@ module KeycloakAdmin
|
|
|
101
101
|
role_representation = RoleClient.new(@configuration, @realm_client).get(role_name)
|
|
102
102
|
url = "#{groups_url(group_id)}/role-mappings/realm"
|
|
103
103
|
response = execute_http do
|
|
104
|
-
|
|
104
|
+
resource(url).post(
|
|
105
105
|
create_payload([role_representation]), headers
|
|
106
106
|
)
|
|
107
107
|
end
|
|
@@ -113,9 +113,9 @@ module KeycloakAdmin
|
|
|
113
113
|
role_representation = RoleClient.new(@configuration, @realm_client).get(role_name)
|
|
114
114
|
url = "#{groups_url(group_id)}/role-mappings/realm"
|
|
115
115
|
execute_http do
|
|
116
|
-
|
|
117
|
-
@configuration.
|
|
118
|
-
url
|
|
116
|
+
Resource.execute(
|
|
117
|
+
@configuration.faraday_options.merge(
|
|
118
|
+
url: url,
|
|
119
119
|
method: :delete,
|
|
120
120
|
payload: create_payload([role_representation]),
|
|
121
121
|
headers: headers
|
|
@@ -8,7 +8,7 @@ module KeycloakAdmin
|
|
|
8
8
|
|
|
9
9
|
def create(identity_provider_representation)
|
|
10
10
|
execute_http do
|
|
11
|
-
|
|
11
|
+
resource(identity_providers_url).post(
|
|
12
12
|
create_payload(identity_provider_representation), headers
|
|
13
13
|
)
|
|
14
14
|
end
|
|
@@ -16,7 +16,7 @@ module KeycloakAdmin
|
|
|
16
16
|
|
|
17
17
|
def add_mapping(identity_provider_alias, identity_provider_mapping_representation)
|
|
18
18
|
execute_http do
|
|
19
|
-
|
|
19
|
+
resource(identity_provider_mappers_url(identity_provider_alias)).post(
|
|
20
20
|
create_payload(identity_provider_mapping_representation), headers
|
|
21
21
|
)
|
|
22
22
|
end
|
|
@@ -24,14 +24,14 @@ module KeycloakAdmin
|
|
|
24
24
|
|
|
25
25
|
def list
|
|
26
26
|
response = execute_http do
|
|
27
|
-
|
|
27
|
+
resource(identity_providers_url).get(headers)
|
|
28
28
|
end
|
|
29
29
|
JSON.parse(response).map { |provider_as_hash| IdentityProviderRepresentation.from_hash(provider_as_hash) }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def get(internal_id_or_alias=nil)
|
|
33
33
|
response = execute_http do
|
|
34
|
-
|
|
34
|
+
resource(identity_providers_url(internal_id_or_alias)).get(headers)
|
|
35
35
|
end
|
|
36
36
|
IdentityProviderRepresentation.from_hash(JSON.parse(response))
|
|
37
37
|
end
|
|
@@ -9,28 +9,28 @@ module KeycloakAdmin
|
|
|
9
9
|
# This endpoint does not return members
|
|
10
10
|
def list(brief_representation=true, exact=nil, first=nil, max=nil, query=nil, search=nil)
|
|
11
11
|
response = execute_http do
|
|
12
|
-
|
|
12
|
+
resource(organizations_url_with_parameters(brief_representation, exact, first, max, query, search)).get(headers)
|
|
13
13
|
end
|
|
14
14
|
JSON.parse(response).map { |organization_as_hash| OrganizationRepresentation.from_hash(organization_as_hash) }
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def count(exact=nil, query=nil, search=nil)
|
|
18
18
|
response = execute_http do
|
|
19
|
-
|
|
19
|
+
resource(count_url(exact, query, search)).get(headers)
|
|
20
20
|
end
|
|
21
21
|
response.to_i
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def delete(organization_id)
|
|
25
25
|
execute_http do
|
|
26
|
-
|
|
26
|
+
resource(organization_url(organization_id)).delete(headers)
|
|
27
27
|
end
|
|
28
28
|
true
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def update(organization_representation)
|
|
32
32
|
execute_http do
|
|
33
|
-
|
|
33
|
+
resource(organization_url(organization_representation.id)).put(
|
|
34
34
|
create_payload(organization_representation), headers
|
|
35
35
|
)
|
|
36
36
|
end
|
|
@@ -45,7 +45,7 @@ module KeycloakAdmin
|
|
|
45
45
|
# This operation does not associate members and identity providers
|
|
46
46
|
def save(organization_representation)
|
|
47
47
|
execute_http do
|
|
48
|
-
|
|
48
|
+
resource(organizations_url).post(
|
|
49
49
|
create_payload(organization_representation), headers
|
|
50
50
|
)
|
|
51
51
|
end
|
|
@@ -54,14 +54,14 @@ module KeycloakAdmin
|
|
|
54
54
|
|
|
55
55
|
def get(organization_id)
|
|
56
56
|
response = execute_http do
|
|
57
|
-
|
|
57
|
+
resource(organization_url(organization_id)).get(headers)
|
|
58
58
|
end
|
|
59
59
|
OrganizationRepresentation.from_hash(JSON.parse(response))
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def identity_providers(organization_id)
|
|
63
63
|
response = execute_http do
|
|
64
|
-
|
|
64
|
+
resource(identity_providers_url(organization_id)).get(headers)
|
|
65
65
|
end
|
|
66
66
|
JSON.parse(response).map { |idp_as_hash| IdentityProviderRepresentation.from_hash(idp_as_hash) }
|
|
67
67
|
end
|
|
@@ -69,7 +69,7 @@ module KeycloakAdmin
|
|
|
69
69
|
def get_identity_provider(organization_id, identity_provider_alias)
|
|
70
70
|
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
|
|
71
71
|
response = execute_http do
|
|
72
|
-
|
|
72
|
+
resource("#{identity_providers_url(organization_id)}/#{identity_provider_alias}").get(headers)
|
|
73
73
|
end
|
|
74
74
|
IdentityProviderRepresentation.from_hash(JSON.parse(response))
|
|
75
75
|
end
|
|
@@ -77,28 +77,28 @@ module KeycloakAdmin
|
|
|
77
77
|
def add_identity_provider(organization_id, identity_provider_alias)
|
|
78
78
|
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
|
|
79
79
|
execute_http do
|
|
80
|
-
|
|
80
|
+
resource(identity_providers_url(organization_id)).post(identity_provider_alias, headers)
|
|
81
81
|
end
|
|
82
82
|
true
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def delete_identity_provider(organization_id, identity_provider_alias)
|
|
86
86
|
execute_http do
|
|
87
|
-
|
|
87
|
+
resource(identity_provider_url(organization_id, identity_provider_alias)).delete(headers)
|
|
88
88
|
end
|
|
89
89
|
true
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def members_count(organization_id)
|
|
93
93
|
response = execute_http do
|
|
94
|
-
|
|
94
|
+
resource(members_count_url(organization_id)).get(headers)
|
|
95
95
|
end
|
|
96
96
|
response.to_i
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
def members(organization_id, exact=nil, first=nil, max=nil, membership_type=nil, search=nil)
|
|
100
100
|
response = execute_http do
|
|
101
|
-
|
|
101
|
+
resource(members_url_with_query_parameters(organization_id, exact, first, max, membership_type, search)).get(headers)
|
|
102
102
|
end
|
|
103
103
|
JSON.parse(response).map { |member_as_hash| MemberRepresentation.from_hash(member_as_hash) }
|
|
104
104
|
end
|
|
@@ -106,14 +106,14 @@ module KeycloakAdmin
|
|
|
106
106
|
def invite_existing_user(organization_id, user_id)
|
|
107
107
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
108
108
|
execute_http do
|
|
109
|
-
|
|
109
|
+
resource(invite_existing_user_url(organization_id)).post({id: user_id}, headers.merge(content_type: "application/x-www-form-urlencoded"))
|
|
110
110
|
end
|
|
111
111
|
true
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
def invite_user(organization_id, email, first_name, last_name)
|
|
115
115
|
execute_http do
|
|
116
|
-
|
|
116
|
+
resource(invite_user_url(organization_id)).post({
|
|
117
117
|
email: email,
|
|
118
118
|
firstName: first_name,
|
|
119
119
|
lastName: last_name
|
|
@@ -125,28 +125,28 @@ module KeycloakAdmin
|
|
|
125
125
|
def add_member(organization_id, user_id)
|
|
126
126
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
127
127
|
execute_http do
|
|
128
|
-
|
|
128
|
+
resource(members_url(organization_id)).post(user_id, headers)
|
|
129
129
|
end
|
|
130
130
|
true
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def delete_member(organization_id, member_id)
|
|
134
134
|
execute_http do
|
|
135
|
-
|
|
135
|
+
resource(member_url(organization_id, member_id)).delete(headers)
|
|
136
136
|
end
|
|
137
137
|
true
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
def get_member(organization_id, member_id)
|
|
141
141
|
response = execute_http do
|
|
142
|
-
|
|
142
|
+
resource(member_url(organization_id, member_id)).get(headers)
|
|
143
143
|
end
|
|
144
144
|
MemberRepresentation.from_hash(JSON.parse(response))
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
def associated_with_member(member_id, brief_representation=true)
|
|
148
148
|
response = execute_http do
|
|
149
|
-
|
|
149
|
+
resource(associated_with_member_url(member_id, brief_representation)).get(headers)
|
|
150
150
|
end
|
|
151
151
|
JSON.parse(response).map { |organization_as_hash| OrganizationRepresentation.from_hash(organization_as_hash) }
|
|
152
152
|
end
|
|
@@ -7,21 +7,21 @@ module KeycloakAdmin
|
|
|
7
7
|
|
|
8
8
|
def list
|
|
9
9
|
response = execute_http do
|
|
10
|
-
|
|
10
|
+
resource(realm_list_url).get(headers)
|
|
11
11
|
end
|
|
12
12
|
JSON.parse(response).map { |realm_as_hash| RealmRepresentation.from_hash(realm_as_hash) }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def delete
|
|
16
16
|
execute_http do
|
|
17
|
-
|
|
17
|
+
resource(realm_admin_url).delete(headers)
|
|
18
18
|
end
|
|
19
19
|
true
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def save(realm_representation)
|
|
23
23
|
execute_http do
|
|
24
|
-
|
|
24
|
+
resource(realm_list_url).post(
|
|
25
25
|
create_payload(realm_representation), headers
|
|
26
26
|
)
|
|
27
27
|
end
|
|
@@ -29,7 +29,7 @@ module KeycloakAdmin
|
|
|
29
29
|
|
|
30
30
|
def update(realm_representation_body)
|
|
31
31
|
execute_http do
|
|
32
|
-
|
|
32
|
+
resource(realm_admin_url).put(
|
|
33
33
|
create_payload(realm_representation_body), headers
|
|
34
34
|
)
|
|
35
35
|
end
|
|
@@ -8,17 +8,17 @@ module KeycloakAdmin
|
|
|
8
8
|
|
|
9
9
|
def list
|
|
10
10
|
response = execute_http do
|
|
11
|
-
|
|
11
|
+
resource(roles_url).get(headers)
|
|
12
12
|
end
|
|
13
13
|
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
# Returns the role representation for the specified role name
|
|
17
17
|
def get(name)
|
|
18
18
|
# allows special characters in the name like space
|
|
19
19
|
name = URI.encode_uri_component(name)
|
|
20
20
|
response = execute_http do
|
|
21
|
-
|
|
21
|
+
resource(role_name_url(name)).get(headers)
|
|
22
22
|
end
|
|
23
23
|
RoleRepresentation.from_hash JSON.parse(response)
|
|
24
24
|
end
|
|
@@ -28,7 +28,7 @@ module KeycloakAdmin
|
|
|
28
28
|
# allows special characters in the name like space
|
|
29
29
|
name = URI.encode_uri_component(name)
|
|
30
30
|
response = execute_http do
|
|
31
|
-
|
|
31
|
+
resource("#{role_name_url(name)}/groups").get(headers)
|
|
32
32
|
end
|
|
33
33
|
JSON.parse(response).map { |role_as_hash| GroupRepresentation.from_hash(role_as_hash) }
|
|
34
34
|
end
|
|
@@ -37,9 +37,9 @@ module KeycloakAdmin
|
|
|
37
37
|
execute_http do
|
|
38
38
|
payload = create_payload(role_representation)
|
|
39
39
|
if role_representation.id
|
|
40
|
-
|
|
40
|
+
resource(role_id_url(role_representation.id)).put(payload, headers)
|
|
41
41
|
else
|
|
42
|
-
|
|
42
|
+
resource(roles_url).post(payload, headers)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -7,14 +7,14 @@ module KeycloakAdmin
|
|
|
7
7
|
|
|
8
8
|
def list
|
|
9
9
|
response = execute_http do
|
|
10
|
-
|
|
10
|
+
resource(realm_level_url).get(headers)
|
|
11
11
|
end
|
|
12
12
|
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def save_realm_level(role_representation_list)
|
|
16
16
|
execute_http do
|
|
17
|
-
|
|
17
|
+
resource(realm_level_url).post(
|
|
18
18
|
create_payload(role_representation_list), headers
|
|
19
19
|
)
|
|
20
20
|
end
|
|
@@ -22,20 +22,20 @@ module KeycloakAdmin
|
|
|
22
22
|
|
|
23
23
|
def remove_realm_level(role_representation_list)
|
|
24
24
|
execute_http do
|
|
25
|
-
|
|
26
|
-
@configuration.
|
|
25
|
+
Resource.execute(
|
|
26
|
+
@configuration.faraday_options.merge(
|
|
27
27
|
method: :delete,
|
|
28
28
|
url: realm_level_url,
|
|
29
|
-
payload: create_payload(role_representation_list),
|
|
29
|
+
payload: create_payload(role_representation_list),
|
|
30
30
|
headers: headers
|
|
31
31
|
)
|
|
32
32
|
)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
def remove_all_realm_roles
|
|
37
37
|
execute_http do
|
|
38
|
-
|
|
38
|
+
resource(realm_level_url).delete(headers)
|
|
39
39
|
end
|
|
40
40
|
true
|
|
41
41
|
end
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require "rest-client"
|
|
2
|
-
|
|
3
1
|
module KeycloakAdmin
|
|
4
2
|
class TokenClient < Client
|
|
5
3
|
def initialize(configuration, realm_client)
|
|
@@ -18,7 +16,7 @@ module KeycloakAdmin
|
|
|
18
16
|
|
|
19
17
|
def get
|
|
20
18
|
response = execute_http do
|
|
21
|
-
|
|
19
|
+
resource(token_url).post(
|
|
22
20
|
@configuration.body_for_token_retrieval,
|
|
23
21
|
@configuration.headers_for_token_retrieval
|
|
24
22
|
)
|
|
@@ -13,7 +13,7 @@ module KeycloakAdmin
|
|
|
13
13
|
|
|
14
14
|
def save(user_representation)
|
|
15
15
|
execute_http do
|
|
16
|
-
|
|
16
|
+
resource(users_url).post(
|
|
17
17
|
create_payload(user_representation), headers
|
|
18
18
|
)
|
|
19
19
|
end
|
|
@@ -23,8 +23,8 @@ module KeycloakAdmin
|
|
|
23
23
|
# pay attention that, since Keycloak 24.0.4, partial updates of attributes are not authorized anymore
|
|
24
24
|
def update(user_id, user_representation_body)
|
|
25
25
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
26
|
-
|
|
27
|
-
@configuration.
|
|
26
|
+
Resource.execute(
|
|
27
|
+
@configuration.faraday_options.merge(
|
|
28
28
|
method: :put,
|
|
29
29
|
url: users_url(user_id),
|
|
30
30
|
payload: create_payload(user_representation_body),
|
|
@@ -34,8 +34,8 @@ module KeycloakAdmin
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def add_group(user_id, group_id)
|
|
37
|
-
|
|
38
|
-
@configuration.
|
|
37
|
+
Resource.execute(
|
|
38
|
+
@configuration.faraday_options.merge(
|
|
39
39
|
method: :put,
|
|
40
40
|
url: "#{users_url(user_id)}/groups/#{group_id}",
|
|
41
41
|
payload: create_payload({}),
|
|
@@ -45,8 +45,8 @@ module KeycloakAdmin
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def remove_group(user_id, group_id)
|
|
48
|
-
|
|
49
|
-
@configuration.
|
|
48
|
+
Resource.execute(
|
|
49
|
+
@configuration.faraday_options.merge(
|
|
50
50
|
method: :delete,
|
|
51
51
|
url: "#{users_url(user_id)}/groups/#{group_id}",
|
|
52
52
|
headers: headers
|
|
@@ -56,7 +56,7 @@ module KeycloakAdmin
|
|
|
56
56
|
|
|
57
57
|
def add_client_roles_on_user(user_id, client_id, role_representations)
|
|
58
58
|
execute_http do
|
|
59
|
-
|
|
59
|
+
resource(user_client_role_mappings_url(user_id, client_id)).post(
|
|
60
60
|
create_payload(role_representations), headers
|
|
61
61
|
)
|
|
62
62
|
end
|
|
@@ -64,7 +64,7 @@ module KeycloakAdmin
|
|
|
64
64
|
|
|
65
65
|
def get(user_id)
|
|
66
66
|
response = execute_http do
|
|
67
|
-
|
|
67
|
+
resource(users_url(user_id)).get(headers)
|
|
68
68
|
end
|
|
69
69
|
UserRepresentation.from_hash(JSON.parse(response))
|
|
70
70
|
end
|
|
@@ -86,7 +86,7 @@ module KeycloakAdmin
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
response = execute_http do
|
|
89
|
-
|
|
89
|
+
resource(users_url).get(derived_headers)
|
|
90
90
|
end
|
|
91
91
|
JSON.parse(response).map { |user_as_hash| UserRepresentation.from_hash(user_as_hash) }
|
|
92
92
|
end
|
|
@@ -97,22 +97,22 @@ module KeycloakAdmin
|
|
|
97
97
|
|
|
98
98
|
def delete(user_id)
|
|
99
99
|
execute_http do
|
|
100
|
-
|
|
100
|
+
resource(users_url(user_id)).delete(headers)
|
|
101
101
|
end
|
|
102
102
|
true
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def groups(user_id)
|
|
106
106
|
response = execute_http do
|
|
107
|
-
|
|
107
|
+
resource(groups_url(user_id)).get(headers)
|
|
108
108
|
end
|
|
109
109
|
JSON.parse(response).map { |group_as_hash| GroupRepresentation.from_hash(group_as_hash) }
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def update_password(user_id, new_password)
|
|
113
113
|
execute_http do
|
|
114
|
-
|
|
115
|
-
@configuration.
|
|
114
|
+
Resource.execute(
|
|
115
|
+
@configuration.faraday_options.merge(
|
|
116
116
|
method: :put,
|
|
117
117
|
url: reset_password_url(user_id),
|
|
118
118
|
payload: { type: "password", value: new_password, temporary: false }.to_json,
|
|
@@ -125,7 +125,7 @@ module KeycloakAdmin
|
|
|
125
125
|
|
|
126
126
|
def credentials(user_id)
|
|
127
127
|
response = execute_http do
|
|
128
|
-
|
|
128
|
+
resource(credentials_url(user_id)).get(headers)
|
|
129
129
|
end
|
|
130
130
|
JSON.parse(response).map { |group_as_hash| CredentialRepresentation.from_hash(group_as_hash) }
|
|
131
131
|
end
|
|
@@ -140,7 +140,7 @@ module KeycloakAdmin
|
|
|
140
140
|
lifespan_param = lifespan.nil? ? "" : "&lifespan=#{lifespan.seconds}"
|
|
141
141
|
redirect_uri_param = redirect_uri.nil? ? "" : "&redirect_uri=#{redirect_uri}"
|
|
142
142
|
client_id_param = client_id.nil? ? "" : "client_id=#{client_id}"
|
|
143
|
-
|
|
143
|
+
Resource.put("#{execute_actions_email_url(user_id)}?#{client_id_param}#{redirect_uri_param}#{lifespan_param}", create_payload(actions), headers)
|
|
144
144
|
end
|
|
145
145
|
user_id
|
|
146
146
|
end
|
|
@@ -148,8 +148,8 @@ module KeycloakAdmin
|
|
|
148
148
|
def impersonate(user_id)
|
|
149
149
|
impersonation = get_redirect_impersonation(user_id)
|
|
150
150
|
response = execute_http do
|
|
151
|
-
|
|
152
|
-
@configuration.
|
|
151
|
+
Resource.execute(
|
|
152
|
+
@configuration.faraday_options.merge(
|
|
153
153
|
method: :post,
|
|
154
154
|
url: impersonation.impersonation_url,
|
|
155
155
|
payload: impersonation.body.to_json,
|
|
@@ -164,7 +164,7 @@ module KeycloakAdmin
|
|
|
164
164
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
165
165
|
|
|
166
166
|
response = execute_http do
|
|
167
|
-
|
|
167
|
+
resource("#{users_url(user_id)}/sessions").get(headers)
|
|
168
168
|
end
|
|
169
169
|
JSON.parse(response).map { |session_as_hash| SessionRepresentation.from_hash(session_as_hash) }
|
|
170
170
|
end
|
|
@@ -173,8 +173,8 @@ module KeycloakAdmin
|
|
|
173
173
|
raise ArgumentError.new("user_id must be defined") if user_id.nil?
|
|
174
174
|
|
|
175
175
|
execute_http do
|
|
176
|
-
|
|
177
|
-
@configuration.
|
|
176
|
+
Resource.execute(
|
|
177
|
+
@configuration.faraday_options.merge(
|
|
178
178
|
method: :post,
|
|
179
179
|
url: logout_url(user_id),
|
|
180
180
|
headers: headers
|
|
@@ -195,8 +195,8 @@ module KeycloakAdmin
|
|
|
195
195
|
fed_id_rep.identity_provider = idp_id
|
|
196
196
|
|
|
197
197
|
execute_http do
|
|
198
|
-
|
|
199
|
-
@configuration.
|
|
198
|
+
Resource.execute(
|
|
199
|
+
@configuration.faraday_options.merge(
|
|
200
200
|
method: :post,
|
|
201
201
|
url: federated_identity_url(user_id, idp_id),
|
|
202
202
|
payload: fed_id_rep.to_json,
|
|
@@ -208,7 +208,7 @@ module KeycloakAdmin
|
|
|
208
208
|
|
|
209
209
|
def unlink_idp(user_id, idp_id)
|
|
210
210
|
execute_http do
|
|
211
|
-
|
|
211
|
+
resource(federated_identity_url(user_id, idp_id)).delete(headers)
|
|
212
212
|
end
|
|
213
213
|
end
|
|
214
214
|
|
|
@@ -2,7 +2,7 @@ require "base64"
|
|
|
2
2
|
|
|
3
3
|
module KeycloakAdmin
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_accessor :server_url, :server_domain, :client_id, :client_secret, :client_realm_name, :use_service_account, :username, :password, :logger, :
|
|
5
|
+
attr_accessor :server_url, :server_domain, :client_id, :client_secret, :client_realm_name, :use_service_account, :username, :password, :logger, :faraday_options
|
|
6
6
|
|
|
7
7
|
def body_for_token_retrieval
|
|
8
8
|
if use_service_account
|
data/lib/keycloak-admin.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
require "logger"
|
|
2
2
|
|
|
3
3
|
require_relative "keycloak-admin/configuration"
|
|
4
|
+
require_relative "keycloak-admin/client/response"
|
|
5
|
+
require_relative "keycloak-admin/client/resource"
|
|
4
6
|
require_relative "keycloak-admin/client/client"
|
|
5
7
|
require_relative "keycloak-admin/client/client_client"
|
|
6
8
|
require_relative "keycloak-admin/client/client_role_client"
|
|
@@ -83,7 +85,7 @@ module KeycloakAdmin
|
|
|
83
85
|
config.use_service_account = true
|
|
84
86
|
config.username = nil
|
|
85
87
|
config.password = nil
|
|
86
|
-
config.
|
|
88
|
+
config.faraday_options = {}
|
|
87
89
|
end
|
|
88
90
|
end
|
|
89
91
|
|
|
@@ -25,7 +25,7 @@ RSpec.describe KeycloakAdmin::AttackDetectionClient do
|
|
|
25
25
|
before(:each) do
|
|
26
26
|
@attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
|
|
27
27
|
stub_token_client
|
|
28
|
-
allow_any_instance_of(
|
|
28
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"numFailures":1,"disabled":true, "lastFailure":123456}'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
context "when user_id is defined" do
|
|
@@ -49,7 +49,7 @@ RSpec.describe KeycloakAdmin::AttackDetectionClient do
|
|
|
49
49
|
before(:each) do
|
|
50
50
|
@attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
|
|
51
51
|
stub_token_client
|
|
52
|
-
allow_any_instance_of(
|
|
52
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
context "when user_id is defined" do
|
|
@@ -72,7 +72,7 @@ RSpec.describe KeycloakAdmin::AttackDetectionClient do
|
|
|
72
72
|
before(:each) do
|
|
73
73
|
@attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
|
|
74
74
|
stub_token_client
|
|
75
|
-
allow_any_instance_of(
|
|
75
|
+
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
|
|
76
76
|
end
|
|
77
77
|
it "returns true" do
|
|
78
78
|
expect(@attack_detections.unlock_users).to be_truthy
|