keycloak-admin 0.4 → 0.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
  SHA1:
3
- metadata.gz: b0b8ec4ab66da0bc2e63c8aa0cf41107da8b7430
4
- data.tar.gz: 21e5f3c5b983bf197607f280ff34a743811bc2fb
3
+ metadata.gz: 70b6714622b54d9fc925675f2a99a78fe0bdab18
4
+ data.tar.gz: c7afa5ac9282faee2fe4e0d61dd754bf4f842d7a
5
5
  SHA512:
6
- metadata.gz: 3f7ae98056acef279fac3365b9121dbca089a34a36076d1a31a62cb1a4b6af246c18899ea23418b8668fea59eb88a119b2e5fec9326bf7514a2150fdab560bc5
7
- data.tar.gz: 3e44a7ddf4fe78650136b73c73ddeb982e7baf55866674b0c32aadf655423be042eee46722274bf93b80f6cd126924d803a9b8743137576b3156bfd083459883
6
+ metadata.gz: 1e64662dee5bc2671394248a01f2f89a3feb1497a06089ce5a0ddbc483ba0eb2e9bd8e5630ac9cb5690dfd8472e4d75fd854a7dde53049cee89c14cc994deca2
7
+ data.tar.gz: e02240453e10ef9f56e5cc27ca60b55355941ef31d4b48e2b80fd10bcb475c7a6ee2107ec1e2f1b908c230fe10b7fc4c35b61cbbcd04193c1a2d15976027063c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keycloak-admin (0.4)
4
+ keycloak-admin (0.5)
5
5
  http-cookie (~> 1.0, >= 1.0.3)
6
6
 
7
7
  GEM
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.4"
15
+ gem "keycloak-admin", "0.5"
16
16
  ```
17
17
 
18
18
  ## Login
@@ -87,6 +87,7 @@ exit
87
87
  * Reset credentials
88
88
  * Delete a user
89
89
  * Impersonate a user
90
+ * Exchange a configurable token
90
91
 
91
92
  ### Get an access token
92
93
 
@@ -150,6 +151,17 @@ user_id = "95985b21-d884-4bbd-b852-cb8cd365afc2"
150
151
  KeycloakAdmin.realm("a_realm").users.get_redirect_impersonation(user_id)
151
152
  ```
152
153
 
154
+ ### Exchange a configurable token
155
+
156
+ *Requires your Keycloak server to have deployed the Custom REST API `configurable-token`* (https://github.com/looorent/keycloak-configurable-token-api)
157
+ Returns an instance of `KeycloakAdmin::TokenRepresentation`.
158
+
159
+ ```ruby
160
+ user_access_token = "abqsdofnqdsogn"
161
+ token_lifespan_in_seconds = 20
162
+ KeycloakAdmin.realm("a_realm").configurable_token.exchange_with(user_access_token, token_lifespan_in_seconds)
163
+ ```
164
+
153
165
  ## How to execute library tests
154
166
 
155
167
  From the `keycloak-admin-api` directory:
@@ -5,6 +5,7 @@ require_relative "keycloak-admin/client/client"
5
5
  require_relative "keycloak-admin/client/realm_client"
6
6
  require_relative "keycloak-admin/client/token_client"
7
7
  require_relative "keycloak-admin/client/user_client"
8
+ require_relative "keycloak-admin/client/configurable_token_client"
8
9
  require_relative "keycloak-admin/representation/camel_json"
9
10
  require_relative "keycloak-admin/representation/representation"
10
11
  require_relative "keycloak-admin/representation/token_representation"
@@ -0,0 +1,30 @@
1
+ module KeycloakAdmin
2
+ class ConfigurableTokenClient < 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 token_url
10
+ "#{realm_url}/configurable-token"
11
+ end
12
+
13
+ def realm_url
14
+ @realm_client.realm_url
15
+ end
16
+
17
+ def exchange_with(user_access_token, token_lifespan_in_seconds)
18
+ response = execute_http do
19
+ RestClient.post(token_url, {
20
+ tokenLifespanInSeconds: token_lifespan_in_seconds
21
+ }.to_json, {
22
+ Authorization: "Bearer #{user_access_token}",
23
+ content_type: :json,
24
+ accept: :json
25
+ })
26
+ end
27
+ TokenRepresentation.from_json(response.body)
28
+ end
29
+ end
30
+ end
@@ -25,6 +25,10 @@ module KeycloakAdmin
25
25
  TokenClient.new(@configuration, self)
26
26
  end
27
27
 
28
+ def configurable_token
29
+ ConfigurableTokenClient.new(@configuration, self)
30
+ end
31
+
28
32
  def users
29
33
  UserClient.new(@configuration, self)
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
@@ -0,0 +1,34 @@
1
+ RSpec.describe KeycloakAdmin::ConfigurableTokenClient do
2
+ describe "#initialize" do
3
+ context "when realm_name is defined" do
4
+ let(:realm_name) { "master" }
5
+ it "does not raise any error" do
6
+ expect {
7
+ KeycloakAdmin.realm(realm_name).configurable_token
8
+ }.to_not raise_error
9
+ end
10
+ end
11
+
12
+ context "when realm_name is not defined" do
13
+ let(:realm_name) { nil }
14
+ it "raises any error" do
15
+ expect {
16
+ KeycloakAdmin.realm(realm_name).configurable_token
17
+ }.to raise_error(ArgumentError)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#token_url" do
23
+ let(:realm_name) { "valid-realm" }
24
+ let(:user_id) { nil }
25
+
26
+ before(:each) do
27
+ @built_url = KeycloakAdmin.realm(realm_name).configurable_token.token_url
28
+ end
29
+
30
+ it "return a proper url with the realm name" do
31
+ expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/configurable-token"
32
+ end
33
+ end
34
+ 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.4'
4
+ version: '0.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: 2018-01-23 00:00:00.000000000 Z
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-cookie
@@ -75,6 +75,7 @@ files:
75
75
  - keycloak-admin.gemspec
76
76
  - lib/keycloak-admin.rb
77
77
  - lib/keycloak-admin/client/client.rb
78
+ - lib/keycloak-admin/client/configurable_token_client.rb
78
79
  - lib/keycloak-admin/client/realm_client.rb
79
80
  - lib/keycloak-admin/client/token_client.rb
80
81
  - lib/keycloak-admin/client/user_client.rb
@@ -87,6 +88,7 @@ files:
87
88
  - lib/keycloak-admin/representation/token_representation.rb
88
89
  - lib/keycloak-admin/representation/user_representation.rb
89
90
  - lib/keycloak-admin/version.rb
91
+ - spec/client/configurable_token_client_spec.rb
90
92
  - spec/client/realm_client_spec.rb
91
93
  - spec/client/token_client_spec.rb
92
94
  - spec/client/user_client_spec.rb