keycloak-admin 2.0.2 → 2.0.3
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 +27 -0
- data/MIT-LICENSE +18 -17
- data/README.md +66 -5
- data/keycloak-admin.gemspec +1 -0
- data/lib/keycloak-admin/client/attack_detection_client.rb +2 -1
- data/lib/keycloak-admin/client/client.rb +17 -4
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +4 -3
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +3 -2
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +14 -10
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +4 -3
- data/lib/keycloak-admin/client/client_client.rb +6 -2
- data/lib/keycloak-admin/client/client_role_client.rb +2 -1
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +3 -2
- data/lib/keycloak-admin/client/client_scope_client.rb +2 -1
- data/lib/keycloak-admin/client/client_scope_protocol_mapper_client.rb +3 -2
- data/lib/keycloak-admin/client/configurable_token_client.rb +2 -1
- data/lib/keycloak-admin/client/group_client.rb +13 -4
- data/lib/keycloak-admin/client/identity_provider_client.rb +2 -1
- data/lib/keycloak-admin/client/organization_client.rb +6 -5
- data/lib/keycloak-admin/client/realm_client.rb +3 -2
- data/lib/keycloak-admin/client/resource.rb +8 -6
- data/lib/keycloak-admin/client/response.rb +1 -0
- data/lib/keycloak-admin/client/role_client.rb +3 -6
- data/lib/keycloak-admin/client/role_mapper_client.rb +2 -1
- data/lib/keycloak-admin/client/token_client.rb +1 -0
- data/lib/keycloak-admin/client/user_client.rb +63 -44
- data/lib/keycloak-admin/configuration.rb +37 -2
- data/lib/keycloak-admin/error.rb +1 -0
- data/lib/keycloak-admin/path_encoding.rb +24 -0
- data/lib/keycloak-admin/representation/attack_detection_representation.rb +1 -0
- data/lib/keycloak-admin/representation/camel_json.rb +7 -3
- data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_representation.rb +4 -5
- data/lib/keycloak-admin/representation/client_scope_representation.rb +1 -0
- data/lib/keycloak-admin/representation/credential_representation.rb +1 -0
- data/lib/keycloak-admin/representation/federated_identity_representation.rb +1 -0
- data/lib/keycloak-admin/representation/group_representation.rb +1 -0
- data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +1 -0
- data/lib/keycloak-admin/representation/identity_provider_representation.rb +1 -0
- data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +1 -0
- data/lib/keycloak-admin/representation/impersonation_representation.rb +1 -0
- data/lib/keycloak-admin/representation/member_representation.rb +1 -0
- data/lib/keycloak-admin/representation/organization_domain_representation.rb +1 -0
- data/lib/keycloak-admin/representation/organization_representation.rb +1 -1
- data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +1 -0
- data/lib/keycloak-admin/representation/realm_representation.rb +1 -0
- data/lib/keycloak-admin/representation/representation.rb +7 -5
- data/lib/keycloak-admin/representation/role_representation.rb +2 -1
- data/lib/keycloak-admin/representation/session_representation.rb +2 -1
- data/lib/keycloak-admin/representation/token_representation.rb +1 -0
- data/lib/keycloak-admin/representation/user_representation.rb +1 -0
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +4 -1
- data/lib/keycloak-admin/resource/group_resource.rb +1 -0
- data/lib/keycloak-admin/resource/user_resource.rb +1 -0
- data/lib/keycloak-admin/version.rb +2 -1
- data/lib/keycloak-admin.rb +3 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c5abdd787b09a456ad094161dd8d61d1908937d1461086481059ae40cc064eea
|
|
4
|
+
data.tar.gz: f01144dcf8ab3e193f22644e979c36a88f7cd9738bc98cda7465a88c3d05d3c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 250bf4f4bc7471eee8c96d7b84c413ab608ef0c35b1dfebb301f8838c674ebeed93ec571bf918d3b3837543067d3c151cc3acdf992cbe390da36bf4e761b2570
|
|
7
|
+
data.tar.gz: edcec9055546f2d8ee9a756e2f9fce7a5f29feb8ffc87ce452a98e8f5b554055b1e8dd03df03f6459a93592bf79a6c1d961acb31468db371d395e49f360d6144
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,33 @@ 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
|
+
## [2.0.3] - 2026-08-03
|
|
9
|
+
|
|
10
|
+
* [Performance] Added `# frozen_string_literal: true` across all Ruby files to significantly reduce string object allocations and lower memory consumption.
|
|
11
|
+
* [Performance] Refactored `Representation` JSON serialization (`as_json` and `to_json`) to eliminate intermediate Array and Hash allocations, improving CPU performance and memory footprint.
|
|
12
|
+
* [Fix] `Representation#as_json` now strips `nil` values when generating JSON payloads. This fixes `HTTP 400 Bad Request` errors caused by strict API requirements in Keycloak 19+ (such as refusing `null` for `subGroupCount` and other restricted fields).
|
|
13
|
+
* [Chore] Expanded the integration test suite to cover 100% of the REST clients against live Keycloak instances.
|
|
14
|
+
* [Chore] Fixed the integration test suite against Keycloak 25 and 26. The `dummy` realm now enables internationalization and unmanaged user attributes, both required since Keycloak 24 for `locale` and custom attributes to be persisted; authorization permissions are deleted before the policy they depend on, since Keycloak 25 cascades that deletion; and permissions are asserted by name rather than by total count, which Keycloak 25 inflates with a seeded `Default Permission`. Each integration spec now loads the integration helper itself, instead of relying on another spec file having loaded it first.
|
|
15
|
+
* [Fix] `Configuration#inspect` no longer renders `client_secret`, `password` or the cached access token, showing `[FILTERED]` instead. The default `#inspect` printed every attribute, so these credentials travelled into console sessions, `pp` output, and whatever local-variable dump an exception reporter attaches to a crash. A credential that is not set still renders as `nil`, so an inspect stays useful when authentication misbehaves.
|
|
16
|
+
* [Fix] The access token cache introduced in 2.0.1 is now thread-safe.
|
|
17
|
+
* [Fix] Identifiers are now percent-encoded before being interpolated into a URL path.
|
|
18
|
+
* [Feature] `UserClient#update_password` accepts an optional `temporary:` keyword.
|
|
19
|
+
* [Performance] `ClientClient#find_by_client_id` now has Keycloak filter with `?clientId=` instead of listing every client of the realm and comparing in Ruby
|
|
20
|
+
* [Feature] `UserClient#list` and `GroupClient#list` accept optional `first:` and `max:` keywords. Keycloak answers `GET /users` with at most 100 entries when `max` is absent, so `users.list` silently returned a truncated realm with no way to ask for more; `GET /groups` applies no such cap, but both endpoints now page the same way. Calling either `list` with no argument sends no query parameter and is unchanged. `GroupClient#list` pairs a lone `max` with `first=0`, because Keycloak 19 only paginates that endpoint when both bounds are present and ignores `max` on its own; this is a no-op from Keycloak 23 on. Verified against live Keycloak 19.0, 23.0 and 26.7.0.
|
|
21
|
+
* [Feature] `config.faraday_adapter` selects the Faraday adapter requests run through.
|
|
22
|
+
* [Fix] `UserClient#impersonate` now takes part in the `401` replay introduced in 2.0.2. It called `get_redirect_impersonation` outside `execute_http`, so its `Authorization` header was built before the replay cleared the cached token: the second attempt resent the very bearer that had just been rejected and failed with the same `401`. It was the last call in the gem where the replay was inert.
|
|
23
|
+
* [Fix] `CamelJson#camelize` no longer raises `NoMethodError` on an empty word.
|
|
24
|
+
* [Fix] Query parameters built from an Array are now rendered as the key repeated once per element, instead of the array's Ruby `inspect` form: a list value used to be sent as `name=%5B%22a%22%2C%20%22b%22%5D`. An empty array now contributes no parameter at all; a `nil` still renders as `name=`, unchanged.
|
|
25
|
+
* [Breaking] `ClientAuthzResourceClient#update` now replaces the submitted `uris` and `scopes` instead of merging them with the ones already stored. It used to union both, so updating twice with the same uri accumulated duplicates and no uri or scope could ever be removed. A key absent from the submitted hash still leaves the stored value untouched; presence is now what decides, not truthiness, so `uris: []` clears the uris and `owner_managed_access: false` is honoured rather than read as "not submitted". The method also no longer raises a bare `RuntimeError` when a scope has no `:name`, but a `KeycloakAdmin`-consistent `ArgumentError`, and no longer raises `TypeError` when the stored resource has no `uris` at all.
|
|
26
|
+
* [Fix] `ClientRepresentation.from_hash` no longer produces wrongly typed defaults when the payload omits a field.
|
|
27
|
+
* [Fix] `RoleRepresentation` and `SessionRepresentation` no longer define spurious `from_hash` and `from_hash=` instance accessors. A trailing comma after the last symbol of their `attr_accessor` list continued the argument list into the following `def`, which evaluates to a Symbol, so `attr_accessor` also received `:from_hash`. The class method `self.from_hash` was never shadowed, so parsing was unaffected.
|
|
28
|
+
|
|
29
|
+
* [Fix] `UserClient#update`, `#add_group` and `#remove_group` built their request outside `execute_http`. They were the only methods on this client that raised a bare `Faraday::Error` instead of the documented `KeycloakAdmin::ApiError` hierarchy, and the only ones that did not replay a request rejected on a stale `401`.
|
|
30
|
+
* [Fix] `UserClient#create!` could return a different user than the one it had just created. It looked the new user up with `search(email)`, and Keycloak's `search` parameter matches a *substring* of the username, email, first name or last name: creating `pioupioux@email.com` while `vieuxpioupioux@email.com` already existed returned the pre-existing account. The new user's id is now read from the `Location` header of the creation response, like `GroupClient#create!` already did. Two consequences: a creation not answered with `201 Created` now raises `KeycloakAdmin::UnexpectedResponseError` instead of returning `nil`, and the returned representation is fetched by id.
|
|
31
|
+
* [Fix] `UserClient#create!` wrote the `locale` into the very `attributes` hash it was given, mutating the caller's object.
|
|
32
|
+
* [Fix] `UserClient#execute_actions_email` (and `#forgot_password`) ignored `config.faraday_options`. It was the only call in the gem running with no timeout, and any configured SSL or proxy setting was silently dropped. The internal `KeycloakAdmin::Resource.put` shorthand it relied on is removed; its signature could not carry connection options.
|
|
33
|
+
* [Chore] Migrated test suites to use WebMock `stub_request` instead of stubbing `KeycloakAdmin::Resource` directly, ensuring tests validate the actual network payload.
|
|
34
|
+
|
|
8
35
|
## [2.0.2] - 2026-08-01
|
|
9
36
|
|
|
10
37
|
* [Breaking] HTTP failures now raise a `KeycloakAdmin::ApiError` subclass instead of a bare `RuntimeError`.
|
data/MIT-LICENSE
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
3
|
+
Copyright (c) 2026 Lorent Lempereur
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -16,7 +16,7 @@ This gem *does not* require Rails.
|
|
|
16
16
|
For example, using `bundle`, add this line to your Gemfile.
|
|
17
17
|
|
|
18
18
|
```ruby
|
|
19
|
-
gem "keycloak-admin", "2.0.
|
|
19
|
+
gem "keycloak-admin", "2.0.3"
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Login
|
|
@@ -107,6 +107,30 @@ All options have a default value. However, all of them can be changed in your in
|
|
|
107
107
|
| `password` | `nil`| String | Optional | Clear password to access the Admin REST API. Recommended if `user_service_account` is set to `false`. | `bobby` |
|
|
108
108
|
| `logger` | `Logger.new(STDOUT)`| Logger | Optional | The logger used by `keycloak-admin` | `Rails.logger` |
|
|
109
109
|
| `faraday_options` | `{}`| Hash | Optional | Options to pass to `Faraday.new` (e.g. `request:`, `ssl:`, `proxy:`) | `{ request: { timeout: 5 } }` |
|
|
110
|
+
| `faraday_adapter` | `nil`| Symbol or Array | Optional | Faraday adapter to run requests through. `nil` uses `Faraday.default_adapter`. See _Connection reuse_ below. | `:net_http_persistent` |
|
|
111
|
+
|
|
112
|
+
### Connection reuse
|
|
113
|
+
|
|
114
|
+
By default this gem runs on `Faraday.default_adapter` (`net_http`), which wraps every request in `Net::HTTP#start`: the TCP connection is opened and closed again for each call. On a loop of admin calls, that handshake dominates the time spent.
|
|
115
|
+
|
|
116
|
+
Set `faraday_adapter` to a pooling adapter to keep connections alive between calls. The adapter is not bundled, so add its gem to your own `Gemfile` alongside this one:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
# Gemfile
|
|
120
|
+
gem "faraday-net_http_persistent"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
KeycloakAdmin.configure do |config|
|
|
125
|
+
config.faraday_adapter = :net_http_persistent
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
An adapter needing arguments is given as an array, splatted into Faraday's `adapter` call:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
config.faraday_adapter = [:net_http_persistent, { pool_size: 5 }]
|
|
133
|
+
```
|
|
110
134
|
|
|
111
135
|
|
|
112
136
|
## Error handling
|
|
@@ -224,6 +248,13 @@ Returns an array of `KeycloakAdmin::UserRepresentation`.
|
|
|
224
248
|
KeycloakAdmin.realm("a_realm").users.list
|
|
225
249
|
```
|
|
226
250
|
|
|
251
|
+
Keycloak answers this endpoint with **at most 100 users** unless told otherwise, so a bare `list` silently truncates a larger realm. Pass `max` (and `first` to walk the pages) to go past it:
|
|
252
|
+
|
|
253
|
+
```ruby
|
|
254
|
+
KeycloakAdmin.realm("a_realm").users.list(max: 500)
|
|
255
|
+
KeycloakAdmin.realm("a_realm").users.list(first: 100, max: 100)
|
|
256
|
+
```
|
|
257
|
+
|
|
227
258
|
### Save a user
|
|
228
259
|
|
|
229
260
|
Returns the provided `user`, which must be of type `KeycloakAdmin::UserRepresentation`.
|
|
@@ -274,6 +305,14 @@ new_password = "coco"
|
|
|
274
305
|
KeycloakAdmin.realm("a_realm").users.update_password(user_id, new_password)
|
|
275
306
|
```
|
|
276
307
|
|
|
308
|
+
Pass `temporary: true` to force the user to choose a new password at their next login. Keycloak
|
|
309
|
+
records this as an `UPDATE_PASSWORD` required action on the account; a later permanent reset
|
|
310
|
+
clears it.
|
|
311
|
+
|
|
312
|
+
```ruby
|
|
313
|
+
KeycloakAdmin.realm("a_realm").users.update_password(user_id, new_password, temporary: true)
|
|
314
|
+
```
|
|
315
|
+
|
|
277
316
|
### List credentials
|
|
278
317
|
|
|
279
318
|
```ruby
|
|
@@ -380,11 +419,17 @@ Returns an array of `KeycloakAdmin::GroupRepresentation`.
|
|
|
380
419
|
KeycloakAdmin.realm("a_realm").groups.list
|
|
381
420
|
```
|
|
382
421
|
|
|
422
|
+
This endpoint applies no default cap, so a bare `list` already returns every group. `first` and `max` are still accepted, to page through a realm holding a lot of them:
|
|
423
|
+
|
|
424
|
+
```ruby
|
|
425
|
+
KeycloakAdmin.realm("a_realm").groups.list(first: 0, max: 100)
|
|
426
|
+
```
|
|
427
|
+
|
|
383
428
|
### Search for a group
|
|
384
429
|
|
|
385
430
|
Returns an array of `KeycloakAdmin::GroupRepresentation`.
|
|
386
431
|
|
|
387
|
-
According to [the documentation](https://www.keycloak.org/docs-api/
|
|
432
|
+
According to [the documentation](https://www.keycloak.org/docs-api/latest/rest-api/index.html#_groups):
|
|
388
433
|
* When providing a `String` parameter, this produces an arbitrary search string
|
|
389
434
|
* When providing a `Hash`, you can specify other fields (_e.g_ q, max, first)
|
|
390
435
|
|
|
@@ -915,7 +960,23 @@ KeycloakAdmin.realm("a_realm").client_scope_protocol_mappers(client_scope_id).de
|
|
|
915
960
|
|
|
916
961
|
## How to execute library tests
|
|
917
962
|
|
|
918
|
-
|
|
963
|
+
Unit tests need nothing but the gems:
|
|
964
|
+
|
|
965
|
+
```
|
|
966
|
+
$ bundle install
|
|
967
|
+
$ bundle exec rake spec
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
Integration tests run against a real Keycloak. `docker-compose.yml` boots one configured like the one CI uses, so a green run locally means the same thing as a green run in CI:
|
|
971
|
+
|
|
972
|
+
```
|
|
973
|
+
$ docker compose up -d
|
|
974
|
+
$ bundle exec rake integration
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
To reproduce a failure specific to an older Keycloak, pin `image:` in `docker-compose.yml` to that version and start over with `docker compose down -v && docker compose up -d`. The suite is exercised in CI against Keycloak 19.0, 21.0, 23.0, 25.0 and 26.7.0.
|
|
978
|
+
|
|
979
|
+
Everything can also run inside a container:
|
|
919
980
|
|
|
920
981
|
```
|
|
921
982
|
$ docker build . -t keycloak-admin:test
|
|
@@ -934,6 +995,6 @@ scoped RubyGems credential.
|
|
|
934
995
|
3. Tag the commit and push the tag:
|
|
935
996
|
|
|
936
997
|
```
|
|
937
|
-
$ git tag -a v2.0.
|
|
938
|
-
$ git push origin v2.0.
|
|
998
|
+
$ git tag -a v2.0.3 -m "Version 2.0.3"
|
|
999
|
+
$ git push origin v2.0.3
|
|
939
1000
|
```
|
data/keycloak-admin.gemspec
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class AttackDetectionClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -33,7 +34,7 @@ module KeycloakAdmin
|
|
|
33
34
|
|
|
34
35
|
def brute_force_url(user_id = nil)
|
|
35
36
|
if user_id
|
|
36
|
-
"#{@realm_client.realm_admin_url}/attack-detection/brute-force/users/#{user_id}"
|
|
37
|
+
"#{@realm_client.realm_admin_url}/attack-detection/brute-force/users/#{encode_segment(user_id)}"
|
|
37
38
|
else
|
|
38
39
|
"#{@realm_client.realm_admin_url}/attack-detection/brute-force/users"
|
|
39
40
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require "uri"
|
|
2
3
|
|
|
3
4
|
module KeycloakAdmin
|
|
4
5
|
class Client
|
|
6
|
+
include PathEncoding
|
|
5
7
|
|
|
6
8
|
def initialize(configuration)
|
|
7
9
|
@configuration = configuration
|
|
@@ -15,7 +17,7 @@ module KeycloakAdmin
|
|
|
15
17
|
# created for nearly every call (e.g. KeycloakAdmin.realm(x).users creates a fresh
|
|
16
18
|
# UserClient) - caching here alone would fetch a new token on almost every request.
|
|
17
19
|
def current_token
|
|
18
|
-
@configuration.
|
|
20
|
+
@configuration.fetch_token_once { fetch_token }
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def headers
|
|
@@ -63,8 +65,10 @@ module KeycloakAdmin
|
|
|
63
65
|
private
|
|
64
66
|
|
|
65
67
|
def build_query(parameters)
|
|
66
|
-
parameters.
|
|
67
|
-
|
|
68
|
+
parameters.flat_map do |name, value|
|
|
69
|
+
encoded_name = URI.encode_uri_component(name.to_s)
|
|
70
|
+
values = value.is_a?(Array) ? value : [value]
|
|
71
|
+
values.map { |single_value| "#{encoded_name}=#{URI.encode_uri_component(single_value.to_s)}" }
|
|
68
72
|
end.join("&")
|
|
69
73
|
end
|
|
70
74
|
|
|
@@ -72,8 +76,17 @@ module KeycloakAdmin
|
|
|
72
76
|
KeycloakAdmin.create_client(@configuration, @configuration.client_realm_name).token.get
|
|
73
77
|
end
|
|
74
78
|
|
|
79
|
+
def connection_options
|
|
80
|
+
adapter = @configuration.faraday_adapter
|
|
81
|
+
if adapter.nil?
|
|
82
|
+
@configuration.faraday_options
|
|
83
|
+
else
|
|
84
|
+
@configuration.faraday_options.merge(adapter: adapter)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
75
88
|
def resource(url)
|
|
76
|
-
Resource.new(url,
|
|
89
|
+
Resource.new(url, connection_options, @configuration.logger)
|
|
77
90
|
end
|
|
78
91
|
end
|
|
79
92
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientAuthzPermissionClient < Client
|
|
3
4
|
def initialize(configuration, realm_client, client_id, type, resource_id = nil)
|
|
@@ -55,11 +56,11 @@ module KeycloakAdmin
|
|
|
55
56
|
|
|
56
57
|
def authz_permission_url(client_id, resource_id = nil, type = nil, id = nil)
|
|
57
58
|
if resource_id
|
|
58
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/resource/#{resource_id}/permissions"
|
|
59
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/resource/#{encode_segment(resource_id)}/permissions"
|
|
59
60
|
elsif id
|
|
60
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/permission/#{type}/#{id}"
|
|
61
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/permission/#{encode_segment(type)}/#{encode_segment(id)}"
|
|
61
62
|
else
|
|
62
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/permission/#{type}"
|
|
63
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/permission/#{encode_segment(type)}"
|
|
63
64
|
end
|
|
64
65
|
end
|
|
65
66
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientAuthzPolicyClient < Client
|
|
3
4
|
def initialize(configuration, realm_client, client_id, type)
|
|
@@ -55,9 +56,9 @@ module KeycloakAdmin
|
|
|
55
56
|
|
|
56
57
|
def authz_policy_url(client_id, type, id = nil)
|
|
57
58
|
if id
|
|
58
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/policy/#{type}/#{id}"
|
|
59
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/policy/#{encode_segment(type)}/#{encode_segment(id)}"
|
|
59
60
|
else
|
|
60
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/policy/#{type}?permission=false"
|
|
61
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/policy/#{encode_segment(type)}?permission=false"
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientAuthzResourceClient < Client
|
|
3
4
|
def initialize(configuration, realm_client, client_id)
|
|
@@ -22,17 +23,20 @@ module KeycloakAdmin
|
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def update(resource_id, client_authz_resource_representation)
|
|
25
|
-
|
|
26
|
+
submitted = client_authz_resource_representation || {}
|
|
27
|
+
if submitted[:scopes]&.any? { |scope| !scope[:name] }
|
|
28
|
+
raise ArgumentError.new("scope[:name] is mandatory and the only necessary attribute to add scope to resource")
|
|
29
|
+
end
|
|
26
30
|
|
|
27
31
|
existing_resource = get(resource_id)
|
|
28
32
|
new_resource = build(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
33
|
+
submitted.fetch(:name, existing_resource.name),
|
|
34
|
+
submitted.fetch(:type, existing_resource.type),
|
|
35
|
+
submitted.fetch(:uris, existing_resource.uris),
|
|
36
|
+
submitted.fetch(:owner_managed_access, existing_resource.owner_managed_access),
|
|
37
|
+
submitted.fetch(:display_name, existing_resource.display_name),
|
|
38
|
+
submitted.fetch(:scopes, existing_resource.scopes.map { |scope| {name: scope.name} }),
|
|
39
|
+
submitted.fetch(:attributes, existing_resource.attributes)
|
|
36
40
|
)
|
|
37
41
|
|
|
38
42
|
execute_http do
|
|
@@ -69,9 +73,9 @@ module KeycloakAdmin
|
|
|
69
73
|
|
|
70
74
|
def authz_resources_url(client_id, id = nil)
|
|
71
75
|
if id
|
|
72
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/resource/#{id}"
|
|
76
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/resource/#{encode_segment(id)}"
|
|
73
77
|
else
|
|
74
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/resource"
|
|
78
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/resource"
|
|
75
79
|
end
|
|
76
80
|
end
|
|
77
81
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientAuthzScopeClient < Client
|
|
3
4
|
def initialize(configuration, realm_client, client_id, resource_id = nil)
|
|
@@ -44,11 +45,11 @@ module KeycloakAdmin
|
|
|
44
45
|
|
|
45
46
|
def authz_scopes_url(client_id, resource_id = nil, id = nil)
|
|
46
47
|
if resource_id
|
|
47
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/resource/#{resource_id}/scopes"
|
|
48
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/resource/#{encode_segment(resource_id)}/scopes"
|
|
48
49
|
elsif id
|
|
49
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/scope/#{id}"
|
|
50
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/scope/#{encode_segment(id)}"
|
|
50
51
|
else
|
|
51
|
-
"#{@realm_client.realm_admin_url}/clients/#{client_id}/authz/resource-server/scope"
|
|
52
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/scope"
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -29,7 +30,10 @@ module KeycloakAdmin
|
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def find_by_client_id(client_id)
|
|
32
|
-
|
|
33
|
+
response = execute_http do
|
|
34
|
+
resource("#{clients_url}?#{build_query(clientId: client_id)}").get(headers)
|
|
35
|
+
end
|
|
36
|
+
JSON.parse(response).map { |client_as_hash| ClientRepresentation.from_hash(client_as_hash) }.first
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
def delete(id)
|
|
@@ -58,7 +62,7 @@ module KeycloakAdmin
|
|
|
58
62
|
|
|
59
63
|
def clients_url(id=nil)
|
|
60
64
|
if id
|
|
61
|
-
"#{@realm_client.realm_admin_url}/clients/#{id}"
|
|
65
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(id)}"
|
|
62
66
|
else
|
|
63
67
|
"#{@realm_client.realm_admin_url}/clients"
|
|
64
68
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientRoleClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -14,7 +15,7 @@ module KeycloakAdmin
|
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def clients_url(id)
|
|
17
|
-
"#{@realm_client.realm_admin_url}/clients/#{id}/roles"
|
|
18
|
+
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(id)}/roles"
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientRoleMappingsClient < Client
|
|
3
4
|
def initialize(configuration, user_resource, client_id)
|
|
@@ -22,11 +23,11 @@ module KeycloakAdmin
|
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def list_available_url
|
|
25
|
-
"#{@user_resource.resource_url}/role-mappings/clients/#{@client_id}/available"
|
|
26
|
+
"#{@user_resource.resource_url}/role-mappings/clients/#{encode_segment(@client_id)}/available"
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def base_url
|
|
29
|
-
"#{@user_resource.resource_url}/role-mappings/clients/#{@client_id}"
|
|
30
|
+
"#{@user_resource.resource_url}/role-mappings/clients/#{encode_segment(@client_id)}"
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientScopeClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -59,7 +60,7 @@ module KeycloakAdmin
|
|
|
59
60
|
def client_scopes_url(client_scope_id = nil)
|
|
60
61
|
base = "#{@realm_client.realm_admin_url}/client-scopes"
|
|
61
62
|
|
|
62
|
-
client_scope_id ? "#{base}/#{client_scope_id}" : base
|
|
63
|
+
client_scope_id ? "#{base}/#{encode_segment(client_scope_id)}" : base
|
|
63
64
|
end
|
|
64
65
|
end
|
|
65
66
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ClientScopeProtocolMapperClient < Client
|
|
3
4
|
def initialize(configuration, realm_client, client_scope_id)
|
|
@@ -54,9 +55,9 @@ module KeycloakAdmin
|
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
def protocol_mappers_url(mapper_id = nil)
|
|
57
|
-
base = "#{@realm_client.realm_admin_url}/client-scopes/#{@client_scope_id}/protocol-mappers/models"
|
|
58
|
+
base = "#{@realm_client.realm_admin_url}/client-scopes/#{encode_segment(@client_scope_id)}/protocol-mappers/models"
|
|
58
59
|
|
|
59
|
-
mapper_id ? "#{base}/#{mapper_id}" : base
|
|
60
|
+
mapper_id ? "#{base}/#{encode_segment(mapper_id)}" : base
|
|
60
61
|
end
|
|
61
62
|
end
|
|
62
63
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class ConfigurableTokenClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -17,7 +18,7 @@ module KeycloakAdmin
|
|
|
17
18
|
def exchange_with(user_access_token, token_lifespan_in_seconds)
|
|
18
19
|
response = execute_http do
|
|
19
20
|
Resource.execute(
|
|
20
|
-
|
|
21
|
+
connection_options.merge(
|
|
21
22
|
method: :post,
|
|
22
23
|
url: token_url,
|
|
23
24
|
payload: { tokenLifespanInSeconds: token_lifespan_in_seconds }.to_json,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class GroupClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -21,8 +22,16 @@ module KeycloakAdmin
|
|
|
21
22
|
JSON.parse(response).map { |group_as_hash| GroupRepresentation.from_hash(group_as_hash) }
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
# Unlike the users endpoint, this one applies no default cap: a bare list already returns
|
|
26
|
+
# every group. Passing neither bound sends no query parameter at all, exactly as before.
|
|
27
|
+
#
|
|
28
|
+
# Keycloak 19 only paginates here when both bounds are present - a lone `max` is ignored and
|
|
29
|
+
# the whole list comes back. Sending `first=0` alongside it makes the call behave the same on
|
|
30
|
+
# every supported version, and is a no-op from Keycloak 23 on.
|
|
31
|
+
def list(first: nil, max: nil)
|
|
32
|
+
first = 0 if first.nil? && !max.nil?
|
|
33
|
+
pagination = {first: first, max: max}.compact
|
|
34
|
+
search(pagination.empty? ? nil : pagination)
|
|
26
35
|
end
|
|
27
36
|
|
|
28
37
|
def search(query)
|
|
@@ -111,7 +120,7 @@ module KeycloakAdmin
|
|
|
111
120
|
url = "#{groups_url(group_id)}/role-mappings/realm"
|
|
112
121
|
execute_http do
|
|
113
122
|
Resource.execute(
|
|
114
|
-
|
|
123
|
+
connection_options.merge(
|
|
115
124
|
url: url,
|
|
116
125
|
method: :delete,
|
|
117
126
|
payload: create_payload([role_representation]),
|
|
@@ -125,7 +134,7 @@ module KeycloakAdmin
|
|
|
125
134
|
|
|
126
135
|
def groups_url(id=nil)
|
|
127
136
|
if id
|
|
128
|
-
"#{@realm_client.realm_admin_url}/groups/#{id}"
|
|
137
|
+
"#{@realm_client.realm_admin_url}/groups/#{encode_segment(id)}"
|
|
129
138
|
else
|
|
130
139
|
"#{@realm_client.realm_admin_url}/groups"
|
|
131
140
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class IdentityProviderClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -38,7 +39,7 @@ module KeycloakAdmin
|
|
|
38
39
|
|
|
39
40
|
def identity_providers_url(internal_id_or_alias=nil)
|
|
40
41
|
if internal_id_or_alias
|
|
41
|
-
"#{@realm_client.realm_admin_url}/identity-provider/instances/#{internal_id_or_alias}"
|
|
42
|
+
"#{@realm_client.realm_admin_url}/identity-provider/instances/#{encode_segment(internal_id_or_alias)}"
|
|
42
43
|
else
|
|
43
44
|
"#{@realm_client.realm_admin_url}/identity-provider/instances"
|
|
44
45
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class OrganizationClient < Client
|
|
3
4
|
def initialize(configuration, realm_client)
|
|
@@ -69,7 +70,7 @@ module KeycloakAdmin
|
|
|
69
70
|
def get_identity_provider(organization_id, identity_provider_alias)
|
|
70
71
|
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
|
|
71
72
|
response = execute_http do
|
|
72
|
-
resource(
|
|
73
|
+
resource(identity_provider_url(organization_id, identity_provider_alias)).get(headers)
|
|
73
74
|
end
|
|
74
75
|
IdentityProviderRepresentation.from_hash(JSON.parse(response))
|
|
75
76
|
end
|
|
@@ -157,7 +158,7 @@ module KeycloakAdmin
|
|
|
157
158
|
|
|
158
159
|
def organization_url(organization_id)
|
|
159
160
|
raise ArgumentError.new("organization_id must be defined") if organization_id.nil?
|
|
160
|
-
"#{organizations_url}/#{organization_id}"
|
|
161
|
+
"#{organizations_url}/#{encode_segment(organization_id)}"
|
|
161
162
|
end
|
|
162
163
|
|
|
163
164
|
def identity_providers_url(organization_id)
|
|
@@ -166,7 +167,7 @@ module KeycloakAdmin
|
|
|
166
167
|
|
|
167
168
|
def identity_provider_url(organization_id, identity_provider_alias)
|
|
168
169
|
raise ArgumentError.new("identity_provider_alias must be defined") if identity_provider_alias.nil?
|
|
169
|
-
"#{identity_providers_url(organization_id)}/#{identity_provider_alias}"
|
|
170
|
+
"#{identity_providers_url(organization_id)}/#{encode_segment(identity_provider_alias)}"
|
|
170
171
|
end
|
|
171
172
|
|
|
172
173
|
def count_url(exact, query, search)
|
|
@@ -187,7 +188,7 @@ module KeycloakAdmin
|
|
|
187
188
|
end
|
|
188
189
|
|
|
189
190
|
def associated_with_member_url(member_id, brief_representation=true)
|
|
190
|
-
"#{organizations_url}/members/#{member_id}/organizations?#{build_query(briefRepresentation: brief_representation)}"
|
|
191
|
+
"#{organizations_url}/members/#{encode_segment(member_id)}/organizations?#{build_query(briefRepresentation: brief_representation)}"
|
|
191
192
|
end
|
|
192
193
|
|
|
193
194
|
def members_count_url(organization_id)
|
|
@@ -196,7 +197,7 @@ module KeycloakAdmin
|
|
|
196
197
|
|
|
197
198
|
def member_url(organization_id, member_id)
|
|
198
199
|
raise ArgumentError.new("member_id must be defined") if member_id.nil?
|
|
199
|
-
"#{organization_url(organization_id)}/members/#{member_id}"
|
|
200
|
+
"#{organization_url(organization_id)}/members/#{encode_segment(member_id)}"
|
|
200
201
|
end
|
|
201
202
|
|
|
202
203
|
def invite_existing_user_url(organization_id)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module KeycloakAdmin
|
|
2
3
|
class RealmClient < Client
|
|
3
4
|
def initialize(configuration, realm_name=nil)
|
|
@@ -37,7 +38,7 @@ module KeycloakAdmin
|
|
|
37
38
|
|
|
38
39
|
def realm_url
|
|
39
40
|
if @realm_name
|
|
40
|
-
"#{server_url}/realms/#{@realm_name}"
|
|
41
|
+
"#{server_url}/realms/#{encode_segment(@realm_name)}"
|
|
41
42
|
else
|
|
42
43
|
"#{server_url}/realms"
|
|
43
44
|
end
|
|
@@ -45,7 +46,7 @@ module KeycloakAdmin
|
|
|
45
46
|
|
|
46
47
|
def realm_admin_url
|
|
47
48
|
if @realm_name
|
|
48
|
-
"#{server_url}/admin/realms/#{@realm_name}"
|
|
49
|
+
"#{server_url}/admin/realms/#{encode_segment(@realm_name)}"
|
|
49
50
|
else
|
|
50
51
|
"#{server_url}/admin/realms"
|
|
51
52
|
end
|