keycloak-admin 1.0.7 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1c9e5505dc0883709f4b37f86e2344d352d9994474c316e2f5dabef44494dfb
4
- data.tar.gz: 8046d950cbd37f43afd97764339a581ca9f98ffd311189b7504e1144e9e3e1e0
3
+ metadata.gz: 7ccf7a2ad66682e3a4ed21b48fb816b8b3b179fc20b22d77ee5e6081381b360d
4
+ data.tar.gz: 497ca95848d65d72164b121210b122c1a068fce5c8123614b2801ff878ee9395
5
5
  SHA512:
6
- metadata.gz: '0875ad8a22ab4495faa6d21e842b6cf4f28cdf7fffdcf79cefd49e8d7c6178b8beb651f5e7ce8f8557c8b2431b8c07ffd482cca7710f53088a64ca1710eacfaf'
7
- data.tar.gz: 23ab8ac413cd13cd94eec79ca45a7744a057d40b876af7c4e6432ef343cb5ca9a881182172eb8c97e842c4103fd248a8b2899d8e97998abcf043909e129df124
6
+ metadata.gz: e7c9feea764166e7880cc964a03901e4cd4fa271ee97a3cb84cd23f7f87be650ffd7002bb82dd78fe2a34611083542445440e368216ee2ec3df22dc0a9457fa8
7
+ data.tar.gz: 63baea81ba99dfb815aa6e6dc41256fb1d21c385f59db22f1128a8916356bd5b850f42a4874438c7a2a806edcb8c2b287f76c8db0030d22f9e689b3b8cf3a4cc
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.13] - 2022-03-13
9
+
10
+ * Add client role on users
11
+ * List client roles
8
12
 
9
13
  ## [1.0.7] - 2022-03-13
10
14
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keycloak-admin (1.0.6)
4
+ keycloak-admin (1.0.13)
5
5
  http-cookie (~> 1.0, >= 1.0.3)
6
6
  rest-client (~> 2.0)
7
7
 
data/README.md CHANGED
@@ -12,7 +12,7 @@ This gem *does not* require Rails.
12
12
  For example, using `bundle`, add this line to your Gemfile.
13
13
 
14
14
  ```ruby
15
- gem "keycloak-admin", "1.0.7"
15
+ gem "keycloak-admin", "1.0.13"
16
16
  ```
17
17
 
18
18
  ## Login
@@ -0,0 +1,20 @@
1
+ module KeycloakAdmin
2
+ class ClientRoleClient < 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 list(client_id)
10
+ response = execute_http do
11
+ RestClient::Resource.new(clients_url(client_id), @configuration.rest_client_options).get(headers)
12
+ end
13
+ JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
14
+ end
15
+
16
+ def clients_url(id)
17
+ "#{@realm_client.realm_admin_url}/clients/#{id}/roles"
18
+ end
19
+ end
20
+ end
@@ -79,6 +79,10 @@ module KeycloakAdmin
79
79
  RoleClient.new(@configuration, self)
80
80
  end
81
81
 
82
+ def client_roles
83
+ ClientRoleClient.new(@configuration, self)
84
+ end
85
+
82
86
  def users
83
87
  UserClient.new(@configuration, self)
84
88
  end
@@ -6,8 +6,8 @@ module KeycloakAdmin
6
6
  @realm_client = realm_client
7
7
  end
8
8
 
9
- def create!(username, email, password, email_verified, locale)
10
- user = save(build(username, email, password, email_verified, locale))
9
+ def create!(username, email, password, email_verified, locale, attributes={})
10
+ user = save(build(username, email, password, email_verified, locale, attributes))
11
11
  search(user.email)&.first
12
12
  end
13
13
 
@@ -52,6 +52,14 @@ module KeycloakAdmin
52
52
  )
53
53
  end
54
54
 
55
+ def add_client_roles_on_user(user_id, client_id, role_representations)
56
+ execute_http do
57
+ RestClient::Resource.new(user_client_role_mappings_url(user_id, client_id), @configuration.rest_client_options).post(
58
+ create_payload(role_representations), headers
59
+ )
60
+ end
61
+ end
62
+
55
63
  def get(user_id)
56
64
  response = execute_http do
57
65
  RestClient::Resource.new(users_url(user_id), @configuration.rest_client_options).get(headers)
@@ -176,6 +184,10 @@ module KeycloakAdmin
176
184
  end
177
185
  end
178
186
 
187
+ def user_client_role_mappings_url(user_id, client_id)
188
+ "#{users_url(user_id)}/role-mappings/clients/#{client_id}"
189
+ end
190
+
179
191
  def reset_password_url(user_id)
180
192
  raise ArgumentError.new("user_id must be defined") if user_id.nil?
181
193
  "#{users_url(user_id)}/reset-password"
@@ -204,13 +216,13 @@ module KeycloakAdmin
204
216
 
205
217
  private
206
218
 
207
- def build(username, email, password, email_verified, locale)
219
+ def build(username, email, password, email_verified, locale, attributes={})
208
220
  user = UserRepresentation.new
209
221
  user.email = email
210
222
  user.username = username
211
223
  user.email_verified = email_verified
212
224
  user.enabled = true
213
- user.attributes = {}
225
+ user.attributes = attributes || {}
214
226
  user.attributes[:locale] = locale if locale
215
227
  user.add_credential(CredentialRepresentation.from_password(password))
216
228
  user
@@ -4,7 +4,7 @@ module KeycloakAdmin
4
4
  :id,
5
5
  :name,
6
6
  :protocol,
7
- :protocol_mapper
7
+ :protocolMapper
8
8
 
9
9
  def self.from_hash(hash)
10
10
  rep = new
@@ -12,7 +12,7 @@ module KeycloakAdmin
12
12
  rep.config = hash["config"]
13
13
  rep.name = hash["name"]
14
14
  rep.protocol = hash["protocol"]
15
- rep.protocol_mapper = hash["protocolMapper"]
15
+ rep.protocolMapper = hash["protocolMapper"]
16
16
  rep
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.13"
3
3
  end
@@ -3,6 +3,7 @@ require "logger"
3
3
  require_relative "keycloak-admin/configuration"
4
4
  require_relative "keycloak-admin/client/client"
5
5
  require_relative "keycloak-admin/client/client_client"
6
+ require_relative "keycloak-admin/client/client_role_client"
6
7
  require_relative "keycloak-admin/client/client_role_mappings_client"
7
8
  require_relative "keycloak-admin/client/group_client"
8
9
  require_relative "keycloak-admin/client/realm_client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycloak-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorent Lempereur
@@ -91,6 +91,7 @@ files:
91
91
  - lib/keycloak-admin.rb
92
92
  - lib/keycloak-admin/client/client.rb
93
93
  - lib/keycloak-admin/client/client_client.rb
94
+ - lib/keycloak-admin/client/client_role_client.rb
94
95
  - lib/keycloak-admin/client/client_role_mappings_client.rb
95
96
  - lib/keycloak-admin/client/configurable_token_client.rb
96
97
  - lib/keycloak-admin/client/group_client.rb