keycloak-admin 0.7.4 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e59d2429daf60f186a44419025f9ecf6468e948306b10dd07acc6f71ff36bdb
4
- data.tar.gz: a82dd0cdce80a82e19372ed04cf4b84f84a0138faac9d7fcc4d3eca1f128507f
3
+ metadata.gz: 4c3087f9b9079163b0648bd1a3ae30d3526fef7f8f5d7afc59f251b9f23e7507
4
+ data.tar.gz: 99eeb84049b48e7410e271f4633d0a79b765d9dd5bb4d185469eebe247c98b19
5
5
  SHA512:
6
- metadata.gz: 4b940501a2a046248b9773d6075e72e6c0717a291646a5dbd583b67b59ab54b9a02b6f7407e2fa75330ad829bd50100155f42245358380163868b48968488caa
7
- data.tar.gz: 9ae5a43cfcde48897618294f845c2494ba45e1ecb80d980aa15b99397e9cfc4014a2ef03f36fbdbee1cf8b96f6d5099bae087217901b09f0505cac702967dfa2
6
+ metadata.gz: 28d689fe25884746e02f3f1dba166a2c78472f7e897680b39efe2c10e782fe52a1f661265e59ee676f65a4ee8cd3cc3b99e77dcb9fc3e8a44b2a92ca976db038
7
+ data.tar.gz: d065e64a554f1991e1ec4be2c77cfb81d5e811a6db64d452bdafb7e1cf1e0ce4449444446374e9f09472fa07fee6f8a7468311ff44a86bfd7c5e1ff2cd573656
@@ -5,6 +5,11 @@ 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
+ ## [0.7.5] - 2020-03-28
9
+
10
+ Thanks to @RomanHargrave
11
+ * Support for working with federated identity provider (broker) links
12
+
8
13
  ## [0.7.4] - 2019-10-17
9
14
 
10
15
  * Support for Rails 6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keycloak-admin (0.7.4)
4
+ keycloak-admin (0.7.5)
5
5
  http-cookie (~> 1.0, >= 1.0.3)
6
6
  rest-client (~> 2.0)
7
7
 
@@ -12,13 +12,15 @@ GEM
12
12
  diff-lcs (1.3)
13
13
  domain_name (0.5.20190701)
14
14
  unf (>= 0.0.5, < 1.0.0)
15
+ http-accept (1.7.0)
15
16
  http-cookie (1.0.3)
16
17
  domain_name (~> 0.5)
17
- mime-types (3.2.2)
18
+ mime-types (3.3.1)
18
19
  mime-types-data (~> 3.2015)
19
- mime-types-data (3.2019.0331)
20
+ mime-types-data (3.2019.1009)
20
21
  netrc (0.11.0)
21
- rest-client (2.0.2)
22
+ rest-client (2.1.0)
23
+ http-accept (>= 1.7.0, < 2.0)
22
24
  http-cookie (>= 1.0.2, < 2.0)
23
25
  mime-types (>= 1.16, < 4.0)
24
26
  netrc (~> 0.8)
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", "0.7.4"
15
+ gem "keycloak-admin", "0.7.5"
16
16
  ```
17
17
 
18
18
  ## Login
@@ -97,6 +97,7 @@ All options have a default value. However, all of them can be changed in your in
97
97
  * Get list of client role mappings for a user/group
98
98
  * Save client role mappings for a user/group
99
99
  * Save realm-level role mappings for a user/group
100
+ * Link/Unlink users to federated identity provider brokers
100
101
 
101
102
  ### Get an access token
102
103
 
@@ -21,6 +21,7 @@ require_relative "keycloak-admin/representation/impersonation_representation"
21
21
  require_relative "keycloak-admin/representation/credential_representation"
22
22
  require_relative "keycloak-admin/representation/realm_representation"
23
23
  require_relative "keycloak-admin/representation/role_representation"
24
+ require_relative "keycloak-admin/representation/federated_identity_representation"
24
25
  require_relative "keycloak-admin/representation/user_representation"
25
26
  require_relative "keycloak-admin/resource/base_role_containing_resource"
26
27
  require_relative "keycloak-admin/resource/group_resource"
@@ -80,6 +80,23 @@ module KeycloakAdmin
80
80
  ImpersonationRedirectionRepresentation.from_url(impersonation_url(user_id), headers)
81
81
  end
82
82
 
83
+ def link_idp(user_id, idp_id, idp_user_id, idp_username)
84
+ fed_id_rep = FederatedIdentityRepresentation.new
85
+ fed_id_rep.user_id = idp_user_id
86
+ fed_id_rep.user_name = idp_username
87
+ fed_id_rep.identity_provider = idp_id
88
+
89
+ execute_http do
90
+ RestClient.post(federated_identity_url(user_id, idp_id), fed_id_rep.to_json, headers)
91
+ end
92
+ end
93
+
94
+ def unlink_idp(user_id, idp_id)
95
+ execute_http do
96
+ RestClient::Resource.new(federated_identity_url(user_id, idp_id), @configuration.rest_client_options).delete(headers)
97
+ end
98
+ end
99
+
83
100
  def users_url(id=nil)
84
101
  if id
85
102
  "#{@realm_client.realm_admin_url}/users/#{id}"
@@ -103,6 +120,12 @@ module KeycloakAdmin
103
120
  "#{users_url(user_id)}/impersonation"
104
121
  end
105
122
 
123
+ def federated_identity_url(user_id, identity_provider)
124
+ raise ArgumentError.new("user_id must be defined") if user_id.nil?
125
+ raise ArgumentError.new("identity_provider must be defined") if identity_provider.nil?
126
+ "#{users_url(user_id)}/federated-identity/#{identity_provider}"
127
+ end
128
+
106
129
  private
107
130
 
108
131
  def build(username, email, password, email_verified, locale)
@@ -0,0 +1,15 @@
1
+ module KeycloakAdmin
2
+ class FederatedIdentityRepresentation < Representation
3
+ attr_accessor :identity_provider,
4
+ :user_id,
5
+ :user_name
6
+
7
+ def self.from_hash(hash)
8
+ rep = new
9
+ rep.identity_provider = hash['identityProvider']
10
+ rep.user_id = hash['userId']
11
+ rep.user_name = hash['userName']
12
+ rep
13
+ end
14
+ end
15
+ end
@@ -10,21 +10,23 @@ module KeycloakAdmin
10
10
  :email_verified,
11
11
  :first_name,
12
12
  :last_name,
13
- :credentials
13
+ :credentials,
14
+ :federated_identities
14
15
 
15
16
  def self.from_hash(hash)
16
- user = new
17
- user.id = hash["id"]
18
- user.created_timestamp = hash["createdTimestamp"]
19
- user.origin = hash["origin"]
20
- user.username = hash["username"]
21
- user.email = hash["email"]
22
- user.enabled = hash["enabled"]
23
- user.email_verified = hash["emailVerified"]
24
- user.first_name = hash["firstName"]
25
- user.last_name = hash["lastName"]
26
- user.attributes = hash["attributes"]
27
- user.credentials = hash["credentials"]&.map{ |hash| CredentialRepresentation.from_hash(hash) } || []
17
+ user = new
18
+ user.id = hash["id"]
19
+ user.created_timestamp = hash["createdTimestamp"]
20
+ user.origin = hash["origin"]
21
+ user.username = hash["username"]
22
+ user.email = hash["email"]
23
+ user.enabled = hash["enabled"]
24
+ user.email_verified = hash["emailVerified"]
25
+ user.first_name = hash["firstName"]
26
+ user.last_name = hash["lastName"]
27
+ user.attributes = hash["attributes"]
28
+ user.credentials = hash["credentials"]&.map{ |hash| CredentialRepresentation.from_hash(hash) } || []
29
+ user.federated_identities = hash["federatedIdentities"]&.map { |hash| FederatedIdentityRepresentation.from_hash(hash) } || []
28
30
  user
29
31
  end
30
32
 
@@ -32,5 +34,10 @@ module KeycloakAdmin
32
34
  @credentials ||= []
33
35
  @credentials.push(credential_representation)
34
36
  end
37
+
38
+ def add_federated_identity(federated_identity_representation)
39
+ @federated_identities ||= []
40
+ @federated_identities.push(federated_identity_representation)
41
+ end
35
42
  end
36
43
  end
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
@@ -9,7 +9,7 @@ RSpec.describe KeycloakAdmin::UserRepresentation do
9
9
  end
10
10
 
11
11
  it "can convert to json" do
12
- expect(@user.to_json).to eq '{"id":null,"createdTimestamp":1559836000,"origin":null,"username":"test_username","email":null,"enabled":true,"emailVerified":null,"firstName":null,"lastName":null,"attributes":null,"credentials":[]}'
12
+ expect(@user.to_json).to eq '{"id":null,"createdTimestamp":1559836000,"origin":null,"username":"test_username","email":null,"enabled":true,"emailVerified":null,"firstName":null,"lastName":null,"attributes":null,"credentials":[],"federatedIdentities":[]}'
13
13
  end
14
14
  end
15
15
  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: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorent Lempereur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-17 00:00:00.000000000 Z
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-cookie
@@ -103,6 +103,7 @@ files:
103
103
  - lib/keycloak-admin/representation/camel_json.rb
104
104
  - lib/keycloak-admin/representation/client_representation.rb
105
105
  - lib/keycloak-admin/representation/credential_representation.rb
106
+ - lib/keycloak-admin/representation/federated_identity_representation.rb
106
107
  - lib/keycloak-admin/representation/group_representation.rb
107
108
  - lib/keycloak-admin/representation/impersonation_redirection_representation.rb
108
109
  - lib/keycloak-admin/representation/impersonation_representation.rb
@@ -150,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
152
153
  requirements: []
153
- rubygems_version: 3.0.6
154
+ rubygems_version: 3.0.3
154
155
  signing_key:
155
156
  specification_version: 4
156
157
  summary: Keycloak Admin REST API client written in Ruby