keycloak-admin 1.0.3 → 1.0.6

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: a677bd275fc1500031ac0a13adcc312a6eff5da4fc662292d616c9a3bb4d753c
4
- data.tar.gz: 8600a6ceb17f1d9635a331d442c4696e7cdd672aa411136f63f42c9387b34158
3
+ metadata.gz: a78897f6f30b684a57e9233d436c4cd338061729abc161e0afd8c904ca8890d7
4
+ data.tar.gz: 75c438cf89337f0823d0cd4b7f0379dc5d40dcf090309b319e02ee5145b92f6c
5
5
  SHA512:
6
- metadata.gz: 3716f93590b60ce198c746b606b63b0e6fb010544005792ec4f3d6b5e3cbcec47bc63ea689d330f68ba3befed19387896f11e01667f501180d9ada4d147f9fcf
7
- data.tar.gz: 89c40af6666c161b44801bba87cad4ceca1bf73bc3d211be8755a00e334a56748a4495cc436d726c8d84e4ce155458437600cd35ef24f9b280a550ae3cc137ec
6
+ metadata.gz: e1f43d6a122d6e5ce869a38773293fc8bb913865c4febef40904cb660b7440dede79fdb477476bf4f73b001999fc4adb4eb662677b74b8c908baa0370538a09e
7
+ data.tar.gz: bc883a362f07cbec20df4ae07fd0fbabe5b5d9056fc0df443df65d768c0887dd33a0b0c3127b45efa80f5d60231a09cab3e45358cf969ea097b2bfa5173df431
data/CHANGELOG.md CHANGED
@@ -5,11 +5,16 @@ 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
+ ## [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
+
12
+ ## [1.0.5] - 2022-03-11
9
13
 
10
14
  * Create `Client`
11
15
  * Create `Identity Provider` (Breaking change: `IdentityProviderRepresentation.configuration` has been renamed to `IdentityProviderRepresentation.config`)
12
16
  * Add `Identity Provider Mapping`
17
+ * Find service account for a `Client`
13
18
 
14
19
  ## [1.0.1] - 2021-10-14
15
20
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keycloak-admin (1.0.3)
4
+ keycloak-admin (1.0.5)
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.3"
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
@@ -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
- :protocol_mapper
7
+ :protocolMapper
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.protocol_mapper = 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.protocolMapper = hash["protocolMapper"]
16
16
  rep
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -1,4 +1,4 @@
1
- RSpec.describe KeycloakAdmin::UserRepresentation do
1
+ RSpec.describe KeycloakAdmin::ClientRepresentation do
2
2
  describe "#to_json" do
3
3
  before(:each) do
4
4
  @client = KeycloakAdmin::ClientRepresentation.from_hash(
@@ -1,4 +1,4 @@
1
- RSpec.describe KeycloakAdmin::UserRepresentation do
1
+ RSpec.describe KeycloakAdmin::IdentityProviderMapperRepresentation do
2
2
  describe "#to_json" do
3
3
  before(:each) do
4
4
  @mapper = KeycloakAdmin::IdentityProviderMapperRepresentation.from_hash(
@@ -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.3
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