keycloak-admin 1.0.5 → 1.0.6

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: 5237b125d607832e7d0614d5a5955521aa5ee7bad1e45fc8860c3fdfa63befb0
4
- data.tar.gz: 60728516e9c1b12dee46daeae629c623a6a274d2aaae4ed9f4aa69ae8624bfd3
3
+ metadata.gz: a78897f6f30b684a57e9233d436c4cd338061729abc161e0afd8c904ca8890d7
4
+ data.tar.gz: 75c438cf89337f0823d0cd4b7f0379dc5d40dcf090309b319e02ee5145b92f6c
5
5
  SHA512:
6
- metadata.gz: 1d105d78cd7ce4aebf6032c01210b29ad8bba16dde885109246251da3c225978966b3b8fa4146acab8139556d4ccb905520451a079f32bc6885d190c01e01ebe
7
- data.tar.gz: adc82de6f294e006af09e00d8f19077a3007ec02bfd585d695d30e2b156753bf39cee391f3fd74f1df9cb7acfe6057e632d6d33f092f98b61c9830aaefd112dd
6
+ metadata.gz: e1f43d6a122d6e5ce869a38773293fc8bb913865c4febef40904cb660b7440dede79fdb477476bf4f73b001999fc4adb4eb662677b74b8c908baa0370538a09e
7
+ data.tar.gz: bc883a362f07cbec20df4ae07fd0fbabe5b5d9056fc0df443df65d768c0887dd33a0b0c3127b45efa80f5d60231a09cab3e45358cf969ea097b2bfa5173df431
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.6] - 2022-03-13
9
+
10
+ * 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.
11
+
8
12
  ## [1.0.5] - 2022-03-11
9
13
 
10
14
  * Create `Client`
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.5"
15
+ gem "keycloak-admin", "1.0.6"
16
16
  ```
17
17
 
18
18
  ## Login
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -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
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.5
4
+ version: 1.0.6
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,7 @@ 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
139
140
  - spec/representation/user_representation_spec.rb
140
141
  - spec/resource/group_resource_spec.rb
141
142
  - spec/resource/user_resource_spec.rb