keycloak-admin 1.0.4 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ee26761041b21a26002eedbd5f204e031a81e3b46b2a0942e3007873a95fd87
4
- data.tar.gz: 1933430211e65e88fc358b90dab200606e9b02e3870dc717ce0a57e977669e1c
3
+ metadata.gz: b1c9e5505dc0883709f4b37f86e2344d352d9994474c316e2f5dabef44494dfb
4
+ data.tar.gz: 8046d950cbd37f43afd97764339a581ca9f98ffd311189b7504e1144e9e3e1e0
5
5
  SHA512:
6
- metadata.gz: f9a2863c392f7bf68fb3a044ac30fc5bd183dc0e467595dcbe3999bbb82dca75d15eaeccf108b0ed5a6da147292b80db78e45ff8d5cbcc978a607cac8f1a98d4
7
- data.tar.gz: 163f9ccd4275159c64fb07e833413c40dc4f02f0d7dfced9300c4f776dade9ebb00184c7cfca72897dcc0ce9398ac772ee5e95cc007a2625f3f48ceca2cd3138
6
+ metadata.gz: '0875ad8a22ab4495faa6d21e842b6cf4f28cdf7fffdcf79cefd49e8d7c6178b8beb651f5e7ce8f8557c8b2431b8c07ffd482cca7710f53088a64ca1710eacfaf'
7
+ data.tar.gz: 23ab8ac413cd13cd94eec79ca45a7744a057d40b876af7c4e6432ef343cb5ca9a881182172eb8c97e842c4103fd248a8b2899d8e97998abcf043909e129df124
data/CHANGELOG.md CHANGED
@@ -5,11 +5,21 @@ 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.3] - 2022-03-11
8
+
9
+ ## [1.0.7] - 2022-03-13
10
+
11
+ * Allow to use multiple `KeycloakAdmin::Client` in the same environment
12
+
13
+ ## [1.0.6] - 2022-03-13
14
+
15
+ * When serializing an array to JSON, force the serialization to use `to_json` for each element. In several contexts (e.g. Rails), `to_json` is not used.
16
+
17
+ ## [1.0.5] - 2022-03-11
9
18
 
10
19
  * Create `Client`
11
20
  * Create `Identity Provider` (Breaking change: `IdentityProviderRepresentation.configuration` has been renamed to `IdentityProviderRepresentation.config`)
12
21
  * Add `Identity Provider Mapping`
22
+ * Find service account for a `Client`
13
23
 
14
24
  ## [1.0.1] - 2021-10-14
15
25
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keycloak-admin (1.0.4)
4
+ keycloak-admin (1.0.6)
5
5
  http-cookie (~> 1.0, >= 1.0.3)
6
6
  rest-client (~> 2.0)
7
7
 
@@ -39,7 +39,7 @@ GEM
39
39
  rspec-support (3.7.0)
40
40
  unf (0.1.4)
41
41
  unf_ext
42
- unf_ext (0.0.8)
42
+ unf_ext (0.0.8.1)
43
43
 
44
44
  PLATFORMS
45
45
  ruby
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.4"
15
+ gem "keycloak-admin", "1.0.7"
16
16
  ```
17
17
 
18
18
  ## Login
@@ -10,7 +10,7 @@ module KeycloakAdmin
10
10
  end
11
11
 
12
12
  def current_token
13
- @current_token ||= KeycloakAdmin.realm(@configuration.client_realm_name).token.get
13
+ @current_token ||= KeycloakAdmin.create_client(@configuration, @configuration.client_realm_name).token.get
14
14
  end
15
15
 
16
16
  def headers
@@ -37,6 +37,16 @@ module KeycloakAdmin
37
37
  id
38
38
  end
39
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
+
40
50
  private
41
51
 
42
52
  def http_error(response)
@@ -9,7 +9,7 @@ module KeycloakAdmin
9
9
  def save(client_representation)
10
10
  execute_http do
11
11
  RestClient::Resource.new(clients_url, @configuration.rest_client_options).post(
12
- client_representation.to_json, headers
12
+ create_payload(client_representation), headers
13
13
  )
14
14
  end
15
15
  end
@@ -21,6 +21,13 @@ module KeycloakAdmin
21
21
  JSON.parse(response).map { |client_as_hash| ClientRepresentation.from_hash(client_as_hash) }
22
22
  end
23
23
 
24
+ def get_service_account_user(client_id)
25
+ response = execute_http do
26
+ RestClient::Resource.new(service_account_user_url(client_id), @configuration.rest_client_options).get(headers)
27
+ end
28
+ UserRepresentation.from_hash(JSON.parse(response))
29
+ end
30
+
24
31
  def clients_url(id=nil)
25
32
  if id
26
33
  "#{@realm_client.realm_admin_url}/clients/#{id}"
@@ -28,5 +35,9 @@ module KeycloakAdmin
28
35
  "#{@realm_client.realm_admin_url}/clients"
29
36
  end
30
37
  end
38
+
39
+ def service_account_user_url(client_id)
40
+ "#{clients_url(client_id)}/service-account-user"
41
+ end
31
42
  end
32
43
  end
@@ -16,7 +16,7 @@ module KeycloakAdmin
16
16
  def save(role_representation_list)
17
17
  execute_http do
18
18
  RestClient::Resource.new(base_url, @configuration.rest_client_options).post(
19
- role_representation_list.to_json, headers
19
+ create_payload(role_representation_list), headers
20
20
  )
21
21
  end
22
22
  end
@@ -21,7 +21,7 @@ module KeycloakAdmin
21
21
  def save(group_representation)
22
22
  execute_http do
23
23
  RestClient::Resource.new(groups_url, @configuration.rest_client_options).post(
24
- group_representation.to_json, headers
24
+ create_payload(group_representation), headers
25
25
  )
26
26
  end
27
27
  end
@@ -9,7 +9,7 @@ module KeycloakAdmin
9
9
  def create(identity_provider_representation)
10
10
  execute_http do
11
11
  RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).post(
12
- identity_provider_representation.to_json, headers
12
+ create_payload(identity_provider_representation), headers
13
13
  )
14
14
  end
15
15
  end
@@ -17,7 +17,7 @@ module KeycloakAdmin
17
17
  def add_mapping(identity_provider_alias, identity_provider_mapping_representation)
18
18
  execute_http do
19
19
  RestClient::Resource.new(identity_provider_mappers_url(identity_provider_alias), @configuration.rest_client_options).post(
20
- identity_provider_mapping_representation.to_json, headers
20
+ create_payload(identity_provider_mapping_representation), headers
21
21
  )
22
22
  end
23
23
  end
@@ -22,7 +22,7 @@ module KeycloakAdmin
22
22
  def save(realm_representation)
23
23
  execute_http do
24
24
  RestClient::Resource.new(realm_list_url, @configuration.rest_client_options).post(
25
- realm_representation.to_json, headers
25
+ create_payload(realm_representation), headers
26
26
  )
27
27
  end
28
28
  end
@@ -30,7 +30,7 @@ module KeycloakAdmin
30
30
  def update(realm_representation_body)
31
31
  execute_http do
32
32
  RestClient::Resource.new(realm_admin_url, @configuration.rest_client_options).put(
33
- realm_representation_body.to_json, headers
33
+ create_payload(realm_representation_body), headers
34
34
  )
35
35
  end
36
36
  end
@@ -16,7 +16,7 @@ module KeycloakAdmin
16
16
  def save(role_representation)
17
17
  execute_http do
18
18
  RestClient::Resource.new(roles_url, @configuration.rest_client_options).post(
19
- role_representation.to_json, headers
19
+ create_payload(role_representation), headers
20
20
  )
21
21
  end
22
22
  end
@@ -8,7 +8,7 @@ module KeycloakAdmin
8
8
  def save_realm_level(role_representation_list)
9
9
  execute_http do
10
10
  RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).post(
11
- role_representation_list.to_json, headers
11
+ create_payload(role_representation_list), headers
12
12
  )
13
13
  end
14
14
  end
@@ -14,7 +14,7 @@ module KeycloakAdmin
14
14
  def save(user_representation)
15
15
  execute_http do
16
16
  RestClient::Resource.new(users_url, @configuration.rest_client_options).post(
17
- user_representation.to_json, headers
17
+ create_payload(user_representation), headers
18
18
  )
19
19
  end
20
20
  user_representation
@@ -25,7 +25,7 @@ module KeycloakAdmin
25
25
  @configuration.rest_client_options.merge(
26
26
  method: :put,
27
27
  url: users_url(user_id),
28
- payload: user_representation_body.to_json,
28
+ payload: create_payload(user_representation_body),
29
29
  headers: headers
30
30
  )
31
31
  )
@@ -120,7 +120,7 @@ module KeycloakAdmin
120
120
  def execute_actions_email(user_id, actions=[], lifespan=nil)
121
121
  execute_http do
122
122
  lifespan_param = lifespan.nil? ? "" : "lifespan=#{lifespan.seconds}"
123
- RestClient.put("#{execute_actions_email_url(user_id)}?#{lifespan_param}", actions.to_json, headers)
123
+ RestClient.put("#{execute_actions_email_url(user_id)}?#{lifespan_param}", create_payload(actions), headers)
124
124
  end
125
125
  user_id
126
126
  end
@@ -4,15 +4,15 @@ module KeycloakAdmin
4
4
  :id,
5
5
  :name,
6
6
  :protocol,
7
- :protocolMapper
7
+ :protocol_mapper
8
8
 
9
9
  def self.from_hash(hash)
10
- rep = new
11
- rep.id = hash["id"]
12
- rep.config = hash["config"]
13
- rep.name = hash["name"]
14
- rep.protocol = hash["protocol"]
15
- rep.protocolMapper = hash["protocolMapper"]
10
+ rep = new
11
+ rep.id = hash["id"]
12
+ rep.config = hash["config"]
13
+ rep.name = hash["name"]
14
+ rep.protocol = hash["protocol"]
15
+ rep.protocol_mapper = hash["protocolMapper"]
16
16
  rep
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -42,7 +42,11 @@ module KeycloakAdmin
42
42
  end
43
43
 
44
44
  def self.realm(realm_name)
45
- RealmClient.new(@configuration, realm_name)
45
+ create_client(@configuration, realm_name)
46
+ end
47
+
48
+ def self.create_client(configuration, realm_name)
49
+ RealmClient.new(configuration, realm_name)
46
50
  end
47
51
 
48
52
  def self.logger
@@ -0,0 +1,57 @@
1
+ RSpec.describe KeycloakAdmin::ProtocolMapperRepresentation do
2
+ describe "#to_json" do
3
+ before(:each) do
4
+ @mapper = KeycloakAdmin::ProtocolMapperRepresentation.from_hash(
5
+ {
6
+ "id" => "hello",
7
+ "name" => "abcd",
8
+ "protocol" => "openid-connect",
9
+ "protocolMapper" => "oidc-hardcoded-claim-mapper",
10
+ "consentRequired" => false,
11
+ "config" => {
12
+ "claim.value" => "123456",
13
+ "userinfo.token.claim" => "false",
14
+ "id.token.claim" => "false",
15
+ "access.token.claim" => "true",
16
+ "claim.name" => "abcd",
17
+ "jsonType.label" => "String",
18
+ "access.tokenResponse.claim" => "false"
19
+ }
20
+ }
21
+ )
22
+ end
23
+
24
+ it "can convert to json" do
25
+ expect(@mapper.to_json).to eq "{\"id\":\"hello\",\"config\":{\"claim.value\":\"123456\",\"userinfo.token.claim\":\"false\",\"id.token.claim\":\"false\",\"access.token.claim\":\"true\",\"claim.name\":\"abcd\",\"jsonType.label\":\"String\",\"access.tokenResponse.claim\":\"false\"},\"name\":\"abcd\",\"protocol\":\"openid-connect\",\"protocolMapper\":\"oidc-hardcoded-claim-mapper\"}"
26
+ end
27
+ end
28
+
29
+ describe "array#to_json" do
30
+ before(:each) do
31
+ @mapper = [
32
+ KeycloakAdmin::ProtocolMapperRepresentation.from_hash(
33
+ {
34
+ "id" => "hello",
35
+ "name" => "abcd",
36
+ "protocol" => "openid-connect",
37
+ "protocolMapper" => "oidc-hardcoded-claim-mapper",
38
+ "consentRequired" => false,
39
+ "config" => {
40
+ "claim.value" => "123456",
41
+ "userinfo.token.claim" => "false",
42
+ "id.token.claim" => "false",
43
+ "access.token.claim" => "true",
44
+ "claim.name" => "abcd",
45
+ "jsonType.label" => "String",
46
+ "access.tokenResponse.claim" => "false"
47
+ }
48
+ }
49
+ )
50
+ ]
51
+ end
52
+
53
+ it "can convert to json" do
54
+ expect(@mapper.to_json).to eq "[{\"id\":\"hello\",\"config\":{\"claim.value\":\"123456\",\"userinfo.token.claim\":\"false\",\"id.token.claim\":\"false\",\"access.token.claim\":\"true\",\"claim.name\":\"abcd\",\"jsonType.label\":\"String\",\"access.tokenResponse.claim\":\"false\"},\"name\":\"abcd\",\"protocol\":\"openid-connect\",\"protocolMapper\":\"oidc-hardcoded-claim-mapper\"}]"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,37 @@
1
+ RSpec.describe KeycloakAdmin::RoleRepresentation do
2
+ describe "#to_json" do
3
+ before(:each) do
4
+ @mapper = KeycloakAdmin::RoleRepresentation.from_hash(
5
+ {
6
+ "id" => "bb79fb10-a7b4-4728-a662-82a4de7844a3",
7
+ "name" => "abcd",
8
+ "composite" => true,
9
+ "clientRole" => false
10
+ }
11
+ )
12
+ end
13
+
14
+ it "can convert to json" do
15
+ expect(@mapper.to_json).to eq "{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false}"
16
+ end
17
+ end
18
+
19
+ describe "array#to_json" do
20
+ before(:each) do
21
+ @mappers = [
22
+ KeycloakAdmin::RoleRepresentation.from_hash(
23
+ {
24
+ "id" => "bb79fb10-a7b4-4728-a662-82a4de7844a3",
25
+ "name" => "abcd",
26
+ "composite" => true,
27
+ "clientRole" => false
28
+ }
29
+ )
30
+ ]
31
+ end
32
+
33
+ it "can convert to json" do
34
+ expect(@mappers.to_json).to eq "[{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false}]"
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycloak-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorent Lempereur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-cookie
@@ -136,6 +136,8 @@ files:
136
136
  - spec/representation/identity_provider_mapper_representation_spec.rb
137
137
  - spec/representation/identity_provider_representation_spec.rb
138
138
  - spec/representation/impersonation_representation_spec.rb
139
+ - spec/representation/protocol_mapper_representation_spec.rb
140
+ - spec/representation/role_representation_spec.rb
139
141
  - spec/representation/user_representation_spec.rb
140
142
  - spec/resource/group_resource_spec.rb
141
143
  - spec/resource/user_resource_spec.rb