keycloak-admin 1.1.4 → 1.1.5

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/Dockerfile +24 -24
  3. data/.github/workflows/ci.yml +80 -80
  4. data/.gitignore +9 -9
  5. data/.rspec +2 -2
  6. data/CHANGELOG.md +6 -0
  7. data/Dockerfile +12 -12
  8. data/Gemfile +3 -3
  9. data/Gemfile.lock +1 -1
  10. data/MIT-LICENSE +20 -20
  11. data/README.md +9 -1
  12. data/bin/console +9 -9
  13. data/keycloak-admin.gemspec +24 -24
  14. data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
  15. data/lib/keycloak-admin/client/client.rb +56 -56
  16. data/lib/keycloak-admin/client/client_authz_permission_client.rb +80 -80
  17. data/lib/keycloak-admin/client/client_authz_policy_client.rb +75 -75
  18. data/lib/keycloak-admin/client/client_authz_resource_client.rb +92 -92
  19. data/lib/keycloak-admin/client/client_authz_scope_client.rb +70 -70
  20. data/lib/keycloak-admin/client/client_client.rb +71 -71
  21. data/lib/keycloak-admin/client/client_role_client.rb +20 -20
  22. data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
  23. data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
  24. data/lib/keycloak-admin/client/group_client.rb +148 -148
  25. data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
  26. data/lib/keycloak-admin/client/realm_client.rb +122 -122
  27. data/lib/keycloak-admin/client/role_client.rb +59 -59
  28. data/lib/keycloak-admin/client/role_mapper_client.rb +47 -47
  29. data/lib/keycloak-admin/client/token_client.rb +29 -29
  30. data/lib/keycloak-admin/client/user_client.rb +278 -266
  31. data/lib/keycloak-admin/configuration.rb +52 -52
  32. data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
  33. data/lib/keycloak-admin/representation/camel_json.rb +12 -12
  34. data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +33 -33
  35. data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +14 -14
  36. data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +26 -26
  37. data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +25 -25
  38. data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +16 -16
  39. data/lib/keycloak-admin/representation/client_representation.rb +71 -71
  40. data/lib/keycloak-admin/representation/credential_representation.rb +71 -38
  41. data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
  42. data/lib/keycloak-admin/representation/group_representation.rb +21 -21
  43. data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
  44. data/lib/keycloak-admin/representation/identity_provider_representation.rb +67 -67
  45. data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
  46. data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
  47. data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
  48. data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
  49. data/lib/keycloak-admin/representation/representation.rb +23 -23
  50. data/lib/keycloak-admin/representation/role_representation.rb +19 -19
  51. data/lib/keycloak-admin/representation/session_representation.rb +22 -22
  52. data/lib/keycloak-admin/representation/token_representation.rb +39 -39
  53. data/lib/keycloak-admin/representation/user_representation.rb +47 -47
  54. data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
  55. data/lib/keycloak-admin/resource/group_resource.rb +11 -11
  56. data/lib/keycloak-admin/resource/user_resource.rb +7 -7
  57. data/lib/keycloak-admin/version.rb +3 -3
  58. data/lib/keycloak-admin.rb +84 -84
  59. data/spec/client/attack_detection_client_spec.rb +102 -102
  60. data/spec/client/client_authz_permission_client_spec.rb +170 -170
  61. data/spec/client/client_authz_policy_client_spec.rb +169 -169
  62. data/spec/client/client_authz_resource_client_spec.rb +150 -150
  63. data/spec/client/client_authz_scope_client_spec.rb +133 -133
  64. data/spec/client/client_client_spec.rb +133 -133
  65. data/spec/client/client_role_mappings_client_spec.rb +82 -82
  66. data/spec/client/client_spec.rb +28 -28
  67. data/spec/client/configurable_token_client_spec.rb +34 -34
  68. data/spec/client/group_client_spec.rb +328 -328
  69. data/spec/client/identity_provider_client_spec.rb +92 -92
  70. data/spec/client/realm_client_spec.rb +155 -155
  71. data/spec/client/role_client_spec.rb +79 -79
  72. data/spec/client/role_mapper_client_spec.rb +113 -113
  73. data/spec/client/token_client_spec.rb +68 -68
  74. data/spec/client/user_client_spec.rb +418 -373
  75. data/spec/configuration_spec.rb +113 -113
  76. data/spec/integration/client_authorization_spec.rb +93 -93
  77. data/spec/representation/attack_detection_representation_spec.rb +15 -15
  78. data/spec/representation/client_authz_permission_representation_spec.rb +52 -52
  79. data/spec/representation/client_authz_policy_representation_spec.rb +46 -46
  80. data/spec/representation/client_authz_resource_representation_spec.rb +33 -33
  81. data/spec/representation/client_authz_scope_representation_spec.rb +18 -18
  82. data/spec/representation/client_representation_spec.rb +119 -119
  83. data/spec/representation/credential_representation_spec.rb +68 -0
  84. data/spec/representation/group_representation_spec.rb +22 -22
  85. data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
  86. data/spec/representation/identity_provider_representation_spec.rb +113 -113
  87. data/spec/representation/impersonation_representation_spec.rb +163 -163
  88. data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
  89. data/spec/representation/role_representation_spec.rb +37 -37
  90. data/spec/representation/session_representation_spec.rb +15 -15
  91. data/spec/representation/user_representation_spec.rb +15 -15
  92. data/spec/resource/group_resource_spec.rb +14 -14
  93. data/spec/resource/user_resource_spec.rb +14 -14
  94. data/spec/spec_helper.rb +37 -37
  95. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a699842f0de47c278828c7874187d0249313d7ff871642a6f26bef4aa202999e
4
- data.tar.gz: 6cd358f9db2f837705326e35b6bc00064575ca41e41e08a0fbf04d71d7a76dd1
3
+ metadata.gz: dc70b33efe8f4293f7eb0f60eeb30f9468d7866a08e20180b6a3b66c35c96ea8
4
+ data.tar.gz: f9cfd0bec183db13053ecd034c4c0c180a8564c116fdb6ace4271a086622f18b
5
5
  SHA512:
6
- metadata.gz: 849ddd89962850c4e7b541591072e50f34d639b1c2d6dc0fe5e189d4f64ed9e2aa3354d20ffec8097fe5737d6aa0b7117aeb7dd9c0fd93f23ca2a6e6cf0ac2b3
7
- data.tar.gz: 2d6057ebd0fea9d52c096be0c8bd4ecfc209cabad8b5e9d7edb95d5fddcd391c7bba3ddde127a51ff313ba42a7ccd213ff9abdf1fafdf57640f5fdc013aa66a7
6
+ metadata.gz: a3a4bf1e49ea91c845458186565f68636244e515a7ad78d12e69c50ad190de94fd38050a3222ed16eb33f0b5a13d5e1aa65e496ebb48fb732a5248ff6c227953
7
+ data.tar.gz: b60ee39f400e84c57f1627042abbb07b0ca820471d3fe53448c09a2ef8b4cc1acb193ea4f11d63d4b60941f0ee9496ecb6a5fc89bc6007fa1c1eca69a5b37925
@@ -1,24 +1,24 @@
1
- ### Dockerfile for: tillawy/keycloak-github-actions
2
- ##
3
- ## To build & push
4
- # docker buildx build . --platform linux/amd64 -t tillawy/keycloak-github-actions:25.0.1
5
- # docker push tillawy/keycloak-github-actions:25.0.1
6
- #
7
- ## To Run Locally
8
- # docker run \
9
- # --rm \
10
- # -p 8080:8080 \
11
- # -e KEYCLOAK_ADMIN="admin" \
12
- # -e KEYCLOAK_ADMIN_PASSWORD="admin" \
13
- # -e KC_HOSTNAME="http://localhost:8080" \
14
- # -e KC_HOSTNAME_ADMIN="http://localhost:8080" \
15
- # -e KC_HTTP_ENABLED="true" \
16
- # -e KC_DB="dev-file" \
17
- # tillawy/keycloak-github-actions:25.0.1
18
-
19
- FROM quay.io/keycloak/keycloak:25.0.1
20
-
21
- ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
22
-
23
- CMD ["start-dev", "--hostname=http://localhost:8080" , "--hostname-admin=http://localhost:8080" , "--http-enabled=true", "--verbose"]
24
-
1
+ ### Dockerfile for: tillawy/keycloak-github-actions
2
+ ##
3
+ ## To build & push
4
+ # docker buildx build . --platform linux/amd64 -t tillawy/keycloak-github-actions:25.0.1
5
+ # docker push tillawy/keycloak-github-actions:25.0.1
6
+ #
7
+ ## To Run Locally
8
+ # docker run \
9
+ # --rm \
10
+ # -p 8080:8080 \
11
+ # -e KEYCLOAK_ADMIN="admin" \
12
+ # -e KEYCLOAK_ADMIN_PASSWORD="admin" \
13
+ # -e KC_HOSTNAME="http://localhost:8080" \
14
+ # -e KC_HOSTNAME_ADMIN="http://localhost:8080" \
15
+ # -e KC_HTTP_ENABLED="true" \
16
+ # -e KC_DB="dev-file" \
17
+ # tillawy/keycloak-github-actions:25.0.1
18
+
19
+ FROM quay.io/keycloak/keycloak:25.0.1
20
+
21
+ ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
22
+
23
+ CMD ["start-dev", "--hostname=http://localhost:8080" , "--hostname-admin=http://localhost:8080" , "--http-enabled=true", "--verbose"]
24
+
@@ -1,80 +1,80 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
- name: Ruby
9
-
10
- on:
11
- push:
12
- branches: [ "main" ]
13
- pull_request:
14
- branches: [ "main" ]
15
-
16
- permissions:
17
- contents: read
18
-
19
- jobs:
20
- test:
21
- runs-on: ubuntu-latest
22
- services:
23
- keycloak:
24
- image: tillawy/keycloak-github-actions:25.0.1
25
- ports:
26
- - 8080:8080
27
- options: '--health-cmd "exec 3<>/dev/tcp/localhost/8080" --health-interval 5s --health-timeout 5s --health-retries 10 --health-start-period 100s'
28
- env:
29
- KEYCLOAK_ADMIN: "admin"
30
- KEYCLOAK_ADMIN_PASSWORD: "admin"
31
- KC_HOSTNAME: "http://localhost:8080"
32
- KC_HOSTNAME_ADMIN: "http://localhost:8080"
33
- KC_HTTP_ENABLED: "true"
34
- KC_DB: "dev-file"
35
-
36
- strategy:
37
- matrix:
38
- ruby-version: ['3.2']
39
-
40
- steps:
41
- - name: create realm
42
- run: |
43
- TOKEN=$(curl --silent --location --request POST "http://localhost:8080/realms/master/protocol/openid-connect/token" \
44
- --header 'Content-Type: application/x-www-form-urlencoded' \
45
- --data-urlencode 'grant_type=password' \
46
- --data-urlencode 'username=admin' \
47
- --data-urlencode 'password=admin' \
48
- --data-urlencode 'client_id=admin-cli' | jq -r '.access_token')
49
-
50
- curl --silent --show-error -L -X POST "http://localhost:8080/admin/realms" \
51
- --header "Content-Type: application/json" \
52
- --header "Authorization: Bearer ${TOKEN}" \
53
- --data '{"realm":"dummy","enabled":true}'
54
-
55
- curl --silent --show-error --request POST 'http://localhost:8080/admin/realms/dummy/clients' \
56
- --header 'Authorization: Bearer '$TOKEN \
57
- --header 'Content-Type: application/json' \
58
- --data-raw '{
59
- "clientId":"dummy-client",
60
- "enabled":true,
61
- "consentRequired": false,
62
- "attributes":{},
63
- "serviceAccountsEnabled": true,
64
- "protocol":"openid-connect",
65
- "publicClient":false,
66
- "authorizationServicesEnabled": true,
67
- "clientAuthenticatorType":"client-secret",
68
- "redirectUris":["http://localhost:8180/demo"]
69
- }'
70
-
71
- - uses: actions/checkout@v4
72
- - name: Set up Ruby
73
- uses: ruby/setup-ruby@v1
74
- with:
75
- ruby-version: ${{ matrix.ruby-version }}
76
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
77
- - name: Run tests
78
- run: bundle exec rspec
79
- env:
80
- GITHUB_ACTIONS: true
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "main" ]
13
+ pull_request:
14
+ branches: [ "main" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+ runs-on: ubuntu-latest
22
+ services:
23
+ keycloak:
24
+ image: tillawy/keycloak-github-actions:25.0.1
25
+ ports:
26
+ - 8080:8080
27
+ options: '--health-cmd "exec 3<>/dev/tcp/localhost/8080" --health-interval 5s --health-timeout 5s --health-retries 10 --health-start-period 100s'
28
+ env:
29
+ KEYCLOAK_ADMIN: "admin"
30
+ KEYCLOAK_ADMIN_PASSWORD: "admin"
31
+ KC_HOSTNAME: "http://localhost:8080"
32
+ KC_HOSTNAME_ADMIN: "http://localhost:8080"
33
+ KC_HTTP_ENABLED: "true"
34
+ KC_DB: "dev-file"
35
+
36
+ strategy:
37
+ matrix:
38
+ ruby-version: ['3.2']
39
+
40
+ steps:
41
+ - name: create realm
42
+ run: |
43
+ TOKEN=$(curl --silent --location --request POST "http://localhost:8080/realms/master/protocol/openid-connect/token" \
44
+ --header 'Content-Type: application/x-www-form-urlencoded' \
45
+ --data-urlencode 'grant_type=password' \
46
+ --data-urlencode 'username=admin' \
47
+ --data-urlencode 'password=admin' \
48
+ --data-urlencode 'client_id=admin-cli' | jq -r '.access_token')
49
+
50
+ curl --silent --show-error -L -X POST "http://localhost:8080/admin/realms" \
51
+ --header "Content-Type: application/json" \
52
+ --header "Authorization: Bearer ${TOKEN}" \
53
+ --data '{"realm":"dummy","enabled":true}'
54
+
55
+ curl --silent --show-error --request POST 'http://localhost:8080/admin/realms/dummy/clients' \
56
+ --header 'Authorization: Bearer '$TOKEN \
57
+ --header 'Content-Type: application/json' \
58
+ --data-raw '{
59
+ "clientId":"dummy-client",
60
+ "enabled":true,
61
+ "consentRequired": false,
62
+ "attributes":{},
63
+ "serviceAccountsEnabled": true,
64
+ "protocol":"openid-connect",
65
+ "publicClient":false,
66
+ "authorizationServicesEnabled": true,
67
+ "clientAuthenticatorType":"client-secret",
68
+ "redirectUris":["http://localhost:8180/demo"]
69
+ }'
70
+
71
+ - uses: actions/checkout@v4
72
+ - name: Set up Ruby
73
+ uses: ruby/setup-ruby@v1
74
+ with:
75
+ ruby-version: ${{ matrix.ruby-version }}
76
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
77
+ - name: Run tests
78
+ run: bundle exec rspec
79
+ env:
80
+ GITHUB_ACTIONS: true
data/.gitignore CHANGED
@@ -1,10 +1,10 @@
1
- .bundle/
2
- log/*.log
3
- pkg/
4
- test/dummy/db/*.sqlite3
5
- test/dummy/db/*.sqlite3-journal
6
- test/dummy/log/*.log
7
- test/dummy/tmp/
8
- *.gem
9
- .idea/
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ *.gem
9
+ .idea/
10
10
  .byebug_history
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --color
2
- --require spec_helper
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ 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.1.5] - 2026-01-05
9
+
10
+ * [Feature] Added the ability to list credentials for a given user.
11
+ * [Fix] Implemented safe parsing for nested JSON elements within `CredentialRepresentation` (handling both `credentialData` and `secretData` fields). Please refer to [the official documentation](https://www.keycloak.org/docs-api/latest/rest-api/index.html#CredentialRepresentation).
12
+ * [Breaking] Renamed `CredentialRepresentation` attribute `created_date` $\rightarrow$ `createdDate` to align with the Keycloak Admin API.
13
+
8
14
  ## [1.1.4] - 2025-11-08
9
15
 
10
16
  * Add remove_realm_level_role_name! action on a GroupClient (thanks to @mkrawc)
data/Dockerfile CHANGED
@@ -1,13 +1,13 @@
1
- FROM ruby:3.2.2-slim-bullseye
2
-
3
- RUN apt-get update -qq && apt-get install -y build-essential git ruby-dev && apt-get clean && \
4
- mkdir -p /usr/src/app/lib/keycloak-admin
5
- WORKDIR /usr/src/app
6
-
7
- COPY Gemfile /usr/src/app/
8
- COPY Gemfile.lock /usr/src/app/
9
- COPY keycloak-admin.gemspec /usr/src/app/
10
- COPY lib/keycloak-admin/version.rb /usr/src/app/lib/keycloak-admin/
11
- RUN bundle install
12
- COPY . /usr/src/app
1
+ FROM ruby:3.2.2-slim-bullseye
2
+
3
+ RUN apt-get update -qq && apt-get install -y build-essential git ruby-dev && apt-get clean && \
4
+ mkdir -p /usr/src/app/lib/keycloak-admin
5
+ WORKDIR /usr/src/app
6
+
7
+ COPY Gemfile /usr/src/app/
8
+ COPY Gemfile.lock /usr/src/app/
9
+ COPY keycloak-admin.gemspec /usr/src/app/
10
+ COPY lib/keycloak-admin/version.rb /usr/src/app/lib/keycloak-admin/
11
+ RUN bundle install
12
+ COPY . /usr/src/app
13
13
  RUN bundle install
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keycloak-admin (1.1.4)
4
+ keycloak-admin (1.1.5)
5
5
  http-cookie (~> 1.0, >= 1.0.3)
6
6
  rest-client (~> 2.0)
7
7
 
data/MIT-LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright 2018
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
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:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright 2018
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
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:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.1.4"
15
+ gem "keycloak-admin", "1.1.5"
16
16
  ```
17
17
 
18
18
  ## Login
@@ -112,6 +112,7 @@ All options have a default value. However, all of them can be changed in your in
112
112
  * Get an access token
113
113
  * Create/update/get/delete a user
114
114
  * Get list of users, search for user(s)
115
+ * List credentials of a user
115
116
  * Reset credentials
116
117
  * Impersonate a user
117
118
  * Exchange a configurable token
@@ -226,6 +227,13 @@ new_password = "coco"
226
227
  KeycloakAdmin.realm("a_realm").users.update_password(user_id, new_password)
227
228
  ```
228
229
 
230
+ ### List credentials
231
+
232
+ ```ruby
233
+ user_id = "95985b21-d884-4bbd-b852-cb8cd365afc2"
234
+ KeycloakAdmin.realm("a_realm").users.credentials(user_id)
235
+ ```
236
+
229
237
  ### Impersonate a password directly
230
238
 
231
239
  Returns an instance of `KeycloakAdmin::ImpersonationRepresentation`.
data/bin/console CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "keycloak-admin"
6
- require "byebug"
7
-
8
- require "irb"
9
- IRB.start
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "keycloak-admin"
6
+ require "byebug"
7
+
8
+ require "irb"
9
+ IRB.start
@@ -1,24 +1,24 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
-
3
- require "keycloak-admin/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "keycloak-admin"
7
- spec.version = KeycloakAdmin::VERSION
8
- spec.authors = ["Lorent Lempereur"]
9
- spec.email = ["lorent.lempereur.dev@gmail.com"]
10
- spec.homepage = "https://github.com/looorent/keycloak-admin-ruby"
11
- spec.summary = "Keycloak Admin REST API client written in Ruby"
12
- spec.description = "Keycloak Admin REST API client written in Ruby"
13
- spec.license = "MIT"
14
-
15
- spec.files = `git ls-files -z`.split("\x0")
16
- spec.require_paths = ["lib"]
17
-
18
- spec.required_ruby_version = '>= 2.3'
19
-
20
- spec.add_dependency "http-cookie", "~> 1.0", ">= 1.0.3"
21
- spec.add_dependency "rest-client", "~> 2.0"
22
- spec.add_development_dependency "rspec", "3.13.2"
23
- spec.add_development_dependency "byebug", "12.0.0"
24
- end
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "keycloak-admin/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "keycloak-admin"
7
+ spec.version = KeycloakAdmin::VERSION
8
+ spec.authors = ["Lorent Lempereur"]
9
+ spec.email = ["lorent.lempereur.dev@gmail.com"]
10
+ spec.homepage = "https://github.com/looorent/keycloak-admin-ruby"
11
+ spec.summary = "Keycloak Admin REST API client written in Ruby"
12
+ spec.description = "Keycloak Admin REST API client written in Ruby"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = '>= 2.3'
19
+
20
+ spec.add_dependency "http-cookie", "~> 1.0", ">= 1.0.3"
21
+ spec.add_dependency "rest-client", "~> 2.0"
22
+ spec.add_development_dependency "rspec", "3.13.2"
23
+ spec.add_development_dependency "byebug", "12.0.0"
24
+ end
@@ -1,42 +1,42 @@
1
- module KeycloakAdmin
2
- class AttackDetectionClient < Client
3
- def initialize(configuration, realm_client)
4
- super(configuration)
5
- raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
6
- @realm_client = realm_client
7
- end
8
-
9
- def lock_status(user_id)
10
- raise ArgumentError.new("user_id must be defined") if user_id.nil?
11
-
12
- response = execute_http do
13
- RestClient::Resource.new(brute_force_url(user_id), @configuration.rest_client_options).get(headers)
14
- end
15
- AttackDetectionRepresentation.from_hash(JSON.parse(response))
16
- end
17
-
18
- def unlock_user(user_id)
19
- raise ArgumentError.new("user_id must be defined") if user_id.nil?
20
-
21
- execute_http do
22
- RestClient::Resource.new(brute_force_url(user_id), @configuration.rest_client_options).delete(headers)
23
- end
24
- true
25
- end
26
-
27
- def unlock_users
28
- execute_http do
29
- RestClient::Resource.new(brute_force_url, @configuration.rest_client_options).delete(headers)
30
- end
31
- true
32
- end
33
-
34
- def brute_force_url(user_id = nil)
35
- if user_id
36
- "#{@realm_client.realm_admin_url}/attack-detection/brute-force/users/#{user_id}"
37
- else
38
- "#{@realm_client.realm_admin_url}/attack-detection/brute-force/users"
39
- end
40
- end
41
- end
1
+ module KeycloakAdmin
2
+ class AttackDetectionClient < Client
3
+ def initialize(configuration, realm_client)
4
+ super(configuration)
5
+ raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
6
+ @realm_client = realm_client
7
+ end
8
+
9
+ def lock_status(user_id)
10
+ raise ArgumentError.new("user_id must be defined") if user_id.nil?
11
+
12
+ response = execute_http do
13
+ RestClient::Resource.new(brute_force_url(user_id), @configuration.rest_client_options).get(headers)
14
+ end
15
+ AttackDetectionRepresentation.from_hash(JSON.parse(response))
16
+ end
17
+
18
+ def unlock_user(user_id)
19
+ raise ArgumentError.new("user_id must be defined") if user_id.nil?
20
+
21
+ execute_http do
22
+ RestClient::Resource.new(brute_force_url(user_id), @configuration.rest_client_options).delete(headers)
23
+ end
24
+ true
25
+ end
26
+
27
+ def unlock_users
28
+ execute_http do
29
+ RestClient::Resource.new(brute_force_url, @configuration.rest_client_options).delete(headers)
30
+ end
31
+ true
32
+ end
33
+
34
+ def brute_force_url(user_id = nil)
35
+ if user_id
36
+ "#{@realm_client.realm_admin_url}/attack-detection/brute-force/users/#{user_id}"
37
+ else
38
+ "#{@realm_client.realm_admin_url}/attack-detection/brute-force/users"
39
+ end
40
+ end
41
+ end
42
42
  end
@@ -1,56 +1,56 @@
1
- module KeycloakAdmin
2
- class Client
3
-
4
- def initialize(configuration)
5
- @configuration = configuration
6
- end
7
-
8
- def server_url
9
- @configuration.server_url
10
- end
11
-
12
- def current_token
13
- @current_token ||= KeycloakAdmin.create_client(@configuration, @configuration.client_realm_name).token.get
14
- end
15
-
16
- def headers
17
- {
18
- Authorization: "Bearer #{current_token.access_token}",
19
- content_type: :json,
20
- accept: :json
21
- }
22
- end
23
-
24
- def execute_http
25
- yield
26
- rescue RestClient::Exceptions::Timeout => e
27
- raise
28
- rescue RestClient::ExceptionWithResponse => e
29
- http_error(e.response)
30
- end
31
-
32
- def created_id(response)
33
- unless response.net_http_res.is_a? Net::HTTPCreated
34
- raise "Create method returned status #{response.net_http_res.message} (Code: #{response.net_http_res.code}); expected status: Created (201)"
35
- end
36
- (_head, _separator, id) = response.headers[:location].rpartition("/")
37
- id
38
- end
39
-
40
- def create_payload(value)
41
- if value.nil?
42
- ""
43
- elsif value.kind_of?(Array)
44
- "[#{value.map(&:to_json) * ","}]"
45
- else
46
- value.to_json
47
- end
48
- end
49
-
50
- private
51
-
52
- def http_error(response)
53
- raise "Keycloak: The request failed with response code #{response.code} and message: #{response.body}"
54
- end
55
- end
56
- end
1
+ module KeycloakAdmin
2
+ class Client
3
+
4
+ def initialize(configuration)
5
+ @configuration = configuration
6
+ end
7
+
8
+ def server_url
9
+ @configuration.server_url
10
+ end
11
+
12
+ def current_token
13
+ @current_token ||= KeycloakAdmin.create_client(@configuration, @configuration.client_realm_name).token.get
14
+ end
15
+
16
+ def headers
17
+ {
18
+ Authorization: "Bearer #{current_token.access_token}",
19
+ content_type: :json,
20
+ accept: :json
21
+ }
22
+ end
23
+
24
+ def execute_http
25
+ yield
26
+ rescue RestClient::Exceptions::Timeout => e
27
+ raise
28
+ rescue RestClient::ExceptionWithResponse => e
29
+ http_error(e.response)
30
+ end
31
+
32
+ def created_id(response)
33
+ unless response.net_http_res.is_a? Net::HTTPCreated
34
+ raise "Create method returned status #{response.net_http_res.message} (Code: #{response.net_http_res.code}); expected status: Created (201)"
35
+ end
36
+ (_head, _separator, id) = response.headers[:location].rpartition("/")
37
+ id
38
+ end
39
+
40
+ def create_payload(value)
41
+ if value.nil?
42
+ ""
43
+ elsif value.kind_of?(Array)
44
+ "[#{value.map(&:to_json) * ","}]"
45
+ else
46
+ value.to_json
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def http_error(response)
53
+ raise "Keycloak: The request failed with response code #{response.code} and message: #{response.body}"
54
+ end
55
+ end
56
+ end