keycloak 2.5.1 → 3.0.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/keycloak.rb +108 -117
- data/lib/keycloak/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd3cb974c7f655f965f864b7fcffee8a1c69166a91f43957522cfabe3f6aba3b
|
4
|
+
data.tar.gz: a78167c5ababe6e103ec55dd5adb044000dcf6c21dca8318f332a9eecdc6b611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a616d4cad7f422573b31c3e3c1f9129c4dbf51142d9e4f403c65f6e62a7ae64c62511e78e5f8589245db2e8aa4dc43c632734ec30eb26df4734c27899afb3228
|
7
|
+
data.tar.gz: 4269bbc0fc85ea7347428339c1a20b66db32e9b5e4a5b3dec9c0ce50aad4a8472cd74d19379edd80c62e70624ea9b33404545baca29f1bf8cae398dd182fda60
|
data/Gemfile.lock
CHANGED
data/lib/keycloak.rb
CHANGED
@@ -5,9 +5,13 @@ require 'jwt'
|
|
5
5
|
require 'base64'
|
6
6
|
require 'uri'
|
7
7
|
|
8
|
+
def isempty?(value)
|
9
|
+
value.respond_to?(:empty?) ? !!value.empty? : !value
|
10
|
+
end
|
11
|
+
|
8
12
|
module Keycloak
|
9
|
-
OLD_KEYCLOAK_JSON_FILE = 'keycloak.json'
|
10
|
-
KEYCLOAK_JSON_FILE = 'config/keycloak.json'
|
13
|
+
OLD_KEYCLOAK_JSON_FILE = 'keycloak.json'.freeze
|
14
|
+
KEYCLOAK_JSON_FILE = 'config/keycloak.json'.freeze
|
11
15
|
|
12
16
|
class << self
|
13
17
|
attr_accessor :proxy, :generate_request_exception, :keycloak_controller,
|
@@ -21,15 +25,15 @@ module Keycloak
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def self.installation_file
|
24
|
-
if File.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
@installation_file ||= if File.exist?(KEYCLOAK_JSON_FILE)
|
29
|
+
KEYCLOAK_JSON_FILE
|
30
|
+
else
|
31
|
+
OLD_KEYCLOAK_JSON_FILE
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def self.installation_file=(file = nil)
|
32
|
-
raise InstallationFileNotFound unless file.instance_of?(String) && File.
|
36
|
+
raise InstallationFileNotFound unless file.instance_of?(String) && File.exist?(file)
|
33
37
|
@installation_file = file || KEYCLOAK_JSON_FILE
|
34
38
|
end
|
35
39
|
|
@@ -42,8 +46,8 @@ module Keycloak
|
|
42
46
|
def self.get_token(user, password, client_id = '', secret = '')
|
43
47
|
setup_module
|
44
48
|
|
45
|
-
client_id = @client_id if client_id
|
46
|
-
secret = @secret if secret
|
49
|
+
client_id = @client_id if isempty?(client_id)
|
50
|
+
secret = @secret if isempty?(secret)
|
47
51
|
|
48
52
|
payload = { 'client_id' => client_id,
|
49
53
|
'client_secret' => secret,
|
@@ -57,8 +61,8 @@ module Keycloak
|
|
57
61
|
def self.get_token_by_code(code, redirect_uri, client_id = '', secret = '')
|
58
62
|
verify_setup
|
59
63
|
|
60
|
-
client_id = @client_id if client_id
|
61
|
-
secret = @secret if secret
|
64
|
+
client_id = @client_id if isempty?(client_id)
|
65
|
+
secret = @secret if isempty?(secret)
|
62
66
|
|
63
67
|
payload = { 'client_id' => client_id,
|
64
68
|
'client_secret' => secret,
|
@@ -72,9 +76,9 @@ module Keycloak
|
|
72
76
|
def self.get_token_by_exchange(issuer, issuer_token, client_id = '', secret = '', token_endpoint = '')
|
73
77
|
setup_module
|
74
78
|
|
75
|
-
client_id = @client_id if client_id
|
76
|
-
secret = @secret if secret
|
77
|
-
token_endpoint = @configuration['token_endpoint'] if token_endpoint
|
79
|
+
client_id = @client_id if isempty?(client_id)
|
80
|
+
secret = @secret if isempty?(secret)
|
81
|
+
token_endpoint = @configuration['token_endpoint'] if isempty?(token_endpoint)
|
78
82
|
|
79
83
|
payload = { 'client_id' => client_id, 'client_secret' => secret, 'audience' => client_id, 'grant_type' => 'urn:ietf:params:oauth:grant-type:token-exchange', 'subject_token_type' => 'urn:ietf:params:oauth:token-type:access_token', 'subject_issuer' => issuer, 'subject_token' => issuer_token }
|
80
84
|
header = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
@@ -95,7 +99,7 @@ module Keycloak
|
|
95
99
|
def self.get_userinfo_issuer(access_token = '', userinfo_endpoint = '')
|
96
100
|
verify_setup
|
97
101
|
|
98
|
-
userinfo_endpoint = @configuration['userinfo_endpoint'] if userinfo_endpoint
|
102
|
+
userinfo_endpoint = @configuration['userinfo_endpoint'] if isempty?(userinfo_endpoint)
|
99
103
|
|
100
104
|
access_token = self.token["access_token"] if access_token.empty?
|
101
105
|
payload = { 'access_token' => access_token }
|
@@ -112,9 +116,9 @@ module Keycloak
|
|
112
116
|
def self.get_token_by_refresh_token(refresh_token = '', client_id = '', secret = '')
|
113
117
|
verify_setup
|
114
118
|
|
115
|
-
client_id = @client_id if client_id
|
116
|
-
secret = @secret if secret
|
117
|
-
refresh_token =
|
119
|
+
client_id = @client_id if isempty?(client_id)
|
120
|
+
secret = @secret if isempty?(secret)
|
121
|
+
refresh_token = token['refresh_token'] if refresh_token.empty?
|
118
122
|
|
119
123
|
payload = { 'client_id' => client_id,
|
120
124
|
'client_secret' => secret,
|
@@ -127,8 +131,8 @@ module Keycloak
|
|
127
131
|
def self.get_token_by_client_credentials(client_id = '', secret = '')
|
128
132
|
setup_module
|
129
133
|
|
130
|
-
client_id = @client_id if client_id
|
131
|
-
secret = @secret if secret
|
134
|
+
client_id = @client_id if isempty?(client_id)
|
135
|
+
secret = @secret if isempty?(secret)
|
132
136
|
|
133
137
|
payload = { 'client_id' => client_id,
|
134
138
|
'client_secret' => secret,
|
@@ -140,10 +144,10 @@ module Keycloak
|
|
140
144
|
def self.get_token_introspection(token = '', client_id = '', secret = '', token_introspection_endpoint = '')
|
141
145
|
verify_setup
|
142
146
|
|
143
|
-
client_id = @client_id if client_id
|
144
|
-
secret = @secret if secret
|
145
|
-
token = self.token[
|
146
|
-
token_introspection_endpoint = @configuration['token_introspection_endpoint'] if token_introspection_endpoint
|
147
|
+
client_id = @client_id if isempty?(client_id)
|
148
|
+
secret = @secret if isempty?(secret)
|
149
|
+
token = self.token['access_token'] if isempty?(token)
|
150
|
+
token_introspection_endpoint = @configuration['token_introspection_endpoint'] if isempty?(token_introspection_endpoint)
|
147
151
|
|
148
152
|
payload = { 'token' => token }
|
149
153
|
|
@@ -170,10 +174,10 @@ module Keycloak
|
|
170
174
|
def self.url_login_redirect(redirect_uri, response_type = 'code', client_id = '', authorization_endpoint = '')
|
171
175
|
verify_setup
|
172
176
|
|
173
|
-
client_id = @client_id if client_id
|
174
|
-
authorization_endpoint = @configuration['authorization_endpoint'] if authorization_endpoint
|
177
|
+
client_id = @client_id if isempty?(client_id)
|
178
|
+
authorization_endpoint = @configuration['authorization_endpoint'] if isempty?(authorization_endpoint)
|
175
179
|
|
176
|
-
p = URI.encode_www_form(
|
180
|
+
p = URI.encode_www_form(response_type: response_type, client_id: client_id, redirect_uri: redirect_uri)
|
177
181
|
"#{authorization_endpoint}?#{p}"
|
178
182
|
end
|
179
183
|
|
@@ -183,9 +187,9 @@ module Keycloak
|
|
183
187
|
if self.token || !refresh_token.empty?
|
184
188
|
|
185
189
|
refresh_token = self.token['refresh_token'] if refresh_token.empty?
|
186
|
-
client_id = @client_id if client_id
|
187
|
-
secret = @secret if secret
|
188
|
-
end_session_endpoint = @configuration['end_session_endpoint'] if end_session_endpoint
|
190
|
+
client_id = @client_id if isempty?(client_id)
|
191
|
+
secret = @secret if isempty?(secret)
|
192
|
+
end_session_endpoint = @configuration['end_session_endpoint'] if isempty?(end_session_endpoint)
|
189
193
|
|
190
194
|
payload = { 'client_id' => client_id,
|
191
195
|
'client_secret' => secret,
|
@@ -193,11 +197,11 @@ module Keycloak
|
|
193
197
|
|
194
198
|
header = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
195
199
|
|
196
|
-
if redirect_uri.empty?
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
200
|
+
final_url = if redirect_uri.empty?
|
201
|
+
end_session_endpoint
|
202
|
+
else
|
203
|
+
"#{end_session_endpoint}?#{URI.encode_www_form(redirect_uri: redirect_uri)}"
|
204
|
+
end
|
201
205
|
|
202
206
|
_request = -> do
|
203
207
|
RestClient.post(final_url, payload, header){ |response, request, result|
|
@@ -219,8 +223,8 @@ module Keycloak
|
|
219
223
|
def self.get_userinfo(access_token = '', userinfo_endpoint = '')
|
220
224
|
verify_setup
|
221
225
|
|
222
|
-
access_token = self.token[
|
223
|
-
userinfo_endpoint = @configuration['userinfo_endpoint'] if userinfo_endpoint
|
226
|
+
access_token = self.token['access_token'] if access_token.empty?
|
227
|
+
userinfo_endpoint = @configuration['userinfo_endpoint'] if isempty?(userinfo_endpoint)
|
224
228
|
|
225
229
|
payload = { 'access_token' => access_token }
|
226
230
|
|
@@ -249,32 +253,28 @@ module Keycloak
|
|
249
253
|
def self.has_role?(user_role, access_token = '', client_id = '', secret = '', token_introspection_endpoint = '')
|
250
254
|
verify_setup
|
251
255
|
|
252
|
-
client_id = @client_id if client_id
|
253
|
-
secret = @secret if secret
|
254
|
-
token_introspection_endpoint = @configuration['token_introspection_endpoint'] if token_introspection_endpoint
|
256
|
+
client_id = @client_id if isempty?(client_id)
|
257
|
+
secret = @secret if isempty?(secret)
|
258
|
+
token_introspection_endpoint = @configuration['token_introspection_endpoint'] if isempty?(token_introspection_endpoint)
|
255
259
|
|
256
260
|
if !Keycloak.validate_token_when_call_has_role || user_signed_in?(access_token, client_id, secret, token_introspection_endpoint)
|
257
261
|
dt = decoded_access_token(access_token)[0]
|
258
|
-
dt = dt[
|
259
|
-
|
260
|
-
dt[
|
262
|
+
dt = dt['resource_access'][client_id]
|
263
|
+
unless dt.nil?
|
264
|
+
dt['roles'].each do |role|
|
261
265
|
return true if role.to_s == user_role.to_s
|
262
266
|
end
|
263
|
-
false
|
264
|
-
else
|
265
|
-
false
|
266
267
|
end
|
267
|
-
else
|
268
|
-
false
|
269
268
|
end
|
269
|
+
false
|
270
270
|
end
|
271
271
|
|
272
272
|
def self.user_signed_in?(access_token = '', client_id = '', secret = '', token_introspection_endpoint = '')
|
273
273
|
verify_setup
|
274
274
|
|
275
|
-
client_id = @client_id if client_id
|
276
|
-
secret = @secret if secret
|
277
|
-
token_introspection_endpoint = @configuration['token_introspection_endpoint'] if token_introspection_endpoint
|
275
|
+
client_id = @client_id if isempty?(client_id)
|
276
|
+
secret = @secret if isempty?(secret)
|
277
|
+
token_introspection_endpoint = @configuration['token_introspection_endpoint'] if isempty?(token_introspection_endpoint)
|
278
278
|
|
279
279
|
begin
|
280
280
|
JSON(get_token_introspection(access_token, client_id, secret, token_introspection_endpoint))['active'] === true
|
@@ -322,7 +322,7 @@ module Keycloak
|
|
322
322
|
|
323
323
|
private
|
324
324
|
|
325
|
-
KEYCLOACK_CONTROLLER_DEFAULT = 'session'
|
325
|
+
KEYCLOACK_CONTROLLER_DEFAULT = 'session'.freeze
|
326
326
|
|
327
327
|
def self.get_installation
|
328
328
|
if File.exists?(Keycloak.installation_file)
|
@@ -332,16 +332,13 @@ module Keycloak
|
|
332
332
|
@secret = installation["credentials"]["secret"]
|
333
333
|
@public_key = installation["realm-public-key"]
|
334
334
|
@auth_server_url = installation["auth-server-url"]
|
335
|
-
openid_configuration
|
336
335
|
else
|
337
|
-
if Keycloak.realm
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
@auth_server_url = Keycloak.auth_server_url
|
342
|
-
openid_configuration
|
343
|
-
end
|
336
|
+
raise "#{Keycloak.installation_file} and relm settings not found." if isempty?(Keycloak.realm) || isempty?(Keycloak.auth_server_url)
|
337
|
+
|
338
|
+
@realm = Keycloak.realm
|
339
|
+
@auth_server_url = Keycloak.auth_server_url
|
344
340
|
end
|
341
|
+
openid_configuration
|
345
342
|
end
|
346
343
|
|
347
344
|
def self.verify_setup
|
@@ -368,7 +365,7 @@ module Keycloak
|
|
368
365
|
end
|
369
366
|
|
370
367
|
def self.openid_configuration
|
371
|
-
RestClient.proxy = Keycloak.proxy
|
368
|
+
RestClient.proxy = Keycloak.proxy unless isempty?(Keycloak.proxy)
|
372
369
|
config_url = "#{@auth_server_url}/realms/#{@realm}/.well-known/openid-configuration"
|
373
370
|
_request = -> do
|
374
371
|
RestClient.get config_url
|
@@ -438,13 +435,13 @@ module Keycloak
|
|
438
435
|
end
|
439
436
|
|
440
437
|
def self.revoke_consent_user(id, client_id = nil, access_token = nil)
|
441
|
-
client_id = Keycloak::Client.client_id if client_id
|
438
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
442
439
|
generic_delete("users/#{id}/consents/#{client_id}", nil, nil, access_token)
|
443
440
|
end
|
444
441
|
|
445
442
|
def self.update_account_email(id, actions, redirect_uri = '', client_id = nil, access_token = nil)
|
446
|
-
client_id = Keycloak::Client.client_id if client_id
|
447
|
-
generic_put("users/#{id}/execute-actions-email", {:
|
443
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
444
|
+
generic_put("users/#{id}/execute-actions-email", { redirect_uri: redirect_uri, client_id: client_id }, actions, access_token)
|
448
445
|
end
|
449
446
|
|
450
447
|
def self.get_role_mappings(id, access_token = nil)
|
@@ -555,7 +552,7 @@ module Keycloak
|
|
555
552
|
private
|
556
553
|
|
557
554
|
def self.effective_access_token(access_token)
|
558
|
-
if access_token
|
555
|
+
if isempty?(access_token)
|
559
556
|
Keycloak::Client.token['access_token']
|
560
557
|
else
|
561
558
|
access_token
|
@@ -578,35 +575,35 @@ module Keycloak
|
|
578
575
|
end
|
579
576
|
|
580
577
|
def self.get_users(query_parameters = nil, client_id = '', secret = '')
|
581
|
-
client_id = Keycloak::Client.client_id if client_id
|
582
|
-
secret = Keycloak::Client.secret if secret
|
578
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
579
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
583
580
|
|
584
581
|
proc = lambda {|token|
|
585
|
-
Keycloak::Admin.get_users(query_parameters, token[
|
582
|
+
Keycloak::Admin.get_users(query_parameters, token['access_token'])
|
586
583
|
}
|
587
584
|
|
588
585
|
default_call(proc, client_id, secret)
|
589
586
|
end
|
590
587
|
|
591
588
|
def self.get_groups(query_parameters = nil, client_id = '', secret = '')
|
592
|
-
client_id = Keycloak::Client.client_id if client_id
|
593
|
-
secret = Keycloak::Client.secret if secret
|
589
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
590
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
594
591
|
|
595
|
-
proc = lambda {|token|
|
596
|
-
Keycloak::Admin.get_groups(query_parameters, token[
|
592
|
+
proc = lambda { |token|
|
593
|
+
Keycloak::Admin.get_groups(query_parameters, token['access_token'])
|
597
594
|
}
|
598
595
|
|
599
596
|
default_call(proc, client_id, secret)
|
600
597
|
end
|
601
598
|
|
602
599
|
def self.change_password(user_id, redirect_uri = '', client_id = '', secret = '')
|
603
|
-
client_id = Keycloak::Client.client_id if client_id
|
604
|
-
secret = Keycloak::Client.secret if secret
|
600
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
601
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
605
602
|
|
606
603
|
proc = lambda {|token|
|
607
|
-
Keycloak.generic_request(token[
|
604
|
+
Keycloak.generic_request(token['access_token'],
|
608
605
|
Keycloak::Admin.full_url("users/#{user_id}/execute-actions-email"),
|
609
|
-
{:
|
606
|
+
{ redirect_uri: redirect_uri, client_id: client_id },
|
610
607
|
['UPDATE_PASSWORD'],
|
611
608
|
'PUT')
|
612
609
|
}
|
@@ -615,20 +612,20 @@ module Keycloak
|
|
615
612
|
end
|
616
613
|
|
617
614
|
def self.forgot_password(user_login, redirect_uri = '', client_id = '', secret = '')
|
618
|
-
client_id = Keycloak::Client.client_id if client_id
|
619
|
-
secret = Keycloak::Client.secret if secret
|
615
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
616
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
620
617
|
|
621
618
|
user = get_user_info(user_login, true, client_id, secret)
|
622
619
|
change_password(user['id'], redirect_uri, client_id, secret)
|
623
620
|
end
|
624
621
|
|
625
622
|
def self.get_logged_user_info(client_id = '', secret = '')
|
626
|
-
client_id = Keycloak::Client.client_id if client_id
|
627
|
-
secret = Keycloak::Client.secret if secret
|
623
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
624
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
628
625
|
|
629
626
|
proc = lambda {|token|
|
630
627
|
userinfo = JSON Keycloak::Client.get_userinfo
|
631
|
-
Keycloak.generic_request(token[
|
628
|
+
Keycloak.generic_request(token['access_token'],
|
632
629
|
Keycloak::Admin.full_url("users/#{userinfo['sub']}"),
|
633
630
|
nil, nil, 'GET')
|
634
631
|
}
|
@@ -637,8 +634,8 @@ module Keycloak
|
|
637
634
|
end
|
638
635
|
|
639
636
|
def self.get_user_info(user_login, whole_word = false, client_id = '', secret = '')
|
640
|
-
client_id = Keycloak::Client.client_id if client_id
|
641
|
-
secret = Keycloak::Client.secret if secret
|
637
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
638
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
642
639
|
|
643
640
|
proc = lambda { |token|
|
644
641
|
if user_login.index('@').nil?
|
@@ -679,13 +676,13 @@ module Keycloak
|
|
679
676
|
end
|
680
677
|
|
681
678
|
def self.exists_name_or_email(value, user_id = '', client_id = '', secret = '')
|
682
|
-
client_id = Keycloak::Client.client_id if client_id
|
683
|
-
secret = Keycloak::Client.secret if secret
|
679
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
680
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
684
681
|
|
685
682
|
begin
|
686
683
|
usuario = Keycloak::Internal.get_user_info(value, true, client_id, secret)
|
687
684
|
if user_id.empty? || user_id != usuario['id']
|
688
|
-
usuario
|
685
|
+
!isempty?(usuario)
|
689
686
|
else
|
690
687
|
false
|
691
688
|
end
|
@@ -695,22 +692,22 @@ module Keycloak
|
|
695
692
|
end
|
696
693
|
|
697
694
|
def self.logged_federation_user?(client_id = '', secret = '')
|
698
|
-
client_id = Keycloak::Client.client_id if client_id
|
699
|
-
secret = Keycloak::Client.secret if secret
|
695
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
696
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
700
697
|
info = get_logged_user_info(client_id, secret)
|
701
698
|
info['federationLink'] != nil
|
702
699
|
end
|
703
700
|
|
704
701
|
def self.create_simple_user(username, password, email, first_name, last_name, realm_roles_names, client_roles_names, proc = nil, client_id = '', secret = '')
|
705
|
-
client_id = Keycloak::Client.client_id if client_id
|
706
|
-
secret = Keycloak::Client.secret if secret
|
702
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
703
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
707
704
|
|
708
705
|
begin
|
709
706
|
username.downcase!
|
710
707
|
user = get_user_info(username, true, client_id, secret)
|
711
|
-
|
708
|
+
new_user = false
|
712
709
|
rescue Keycloak::UserLoginNotFound
|
713
|
-
|
710
|
+
new_user = true
|
714
711
|
rescue
|
715
712
|
raise
|
716
713
|
end
|
@@ -722,11 +719,11 @@ module Keycloak
|
|
722
719
|
lastName: last_name,
|
723
720
|
enabled: true }
|
724
721
|
|
725
|
-
if !
|
722
|
+
if !new_user || Keycloak.generic_request(token["access_token"],
|
726
723
|
Keycloak::Admin.full_url("users/"),
|
727
724
|
nil, user_representation, 'POST')
|
728
725
|
|
729
|
-
user = get_user_info(username, true, client_id, secret) if
|
726
|
+
user = get_user_info(username, true, client_id, secret) if new_user
|
730
727
|
|
731
728
|
credential_representation = { type: "password",
|
732
729
|
temporary: false,
|
@@ -743,7 +740,7 @@ module Keycloak
|
|
743
740
|
if client_roles_names.count > 0
|
744
741
|
roles = []
|
745
742
|
client_roles_names.each do |r|
|
746
|
-
|
743
|
+
unless isempty?(r)
|
747
744
|
role = JSON Keycloak.generic_request(token["access_token"],
|
748
745
|
Keycloak::Admin.full_url("clients/#{client[0]['id']}/roles/#{r}"),
|
749
746
|
nil, nil, 'GET')
|
@@ -761,7 +758,7 @@ module Keycloak
|
|
761
758
|
if realm_roles_names.count > 0
|
762
759
|
roles = []
|
763
760
|
realm_roles_names.each do |r|
|
764
|
-
|
761
|
+
unless isempty?(r)
|
765
762
|
role = JSON Keycloak.generic_request(token["access_token"],
|
766
763
|
Keycloak::Admin.full_url("roles/#{r}"),
|
767
764
|
nil, nil, 'GET')
|
@@ -787,19 +784,19 @@ module Keycloak
|
|
787
784
|
end
|
788
785
|
|
789
786
|
def self.create_starter_user(username, password, email, client_roles_names, proc = nil, client_id = '', secret = '')
|
790
|
-
client_id = Keycloak::Client.client_id if client_id
|
791
|
-
secret = Keycloak::Client.secret if secret
|
787
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
788
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
792
789
|
Keycloak::Internal.create_simple_user(username, password, email, '', '', [], client_roles_names, proc, client_id, secret)
|
793
790
|
end
|
794
791
|
|
795
792
|
def self.get_client_roles(client_id = '', secret = '')
|
796
|
-
client_id = Keycloak::Client.client_id if client_id
|
797
|
-
secret = Keycloak::Client.secret if secret
|
793
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
794
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
798
795
|
|
799
796
|
proc = lambda {|token|
|
800
|
-
client = JSON Keycloak::Admin.get_clients({ clientId: client_id }, token[
|
797
|
+
client = JSON Keycloak::Admin.get_clients({ clientId: client_id }, token['access_token'])
|
801
798
|
|
802
|
-
Keycloak.generic_request(token[
|
799
|
+
Keycloak.generic_request(token['access_token'],
|
803
800
|
Keycloak::Admin.full_url("clients/#{client[0]['id']}/roles"),
|
804
801
|
nil, nil, 'GET')
|
805
802
|
}
|
@@ -808,8 +805,8 @@ module Keycloak
|
|
808
805
|
end
|
809
806
|
|
810
807
|
def self.get_client_user_roles(user_id, client_id = '', secret = '')
|
811
|
-
client_id = Keycloak::Client.client_id if client_id
|
812
|
-
secret = Keycloak::Client.secret if secret
|
808
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
809
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
813
810
|
|
814
811
|
proc = lambda {|token|
|
815
812
|
client = JSON Keycloak::Admin.get_clients({ clientId: client_id }, token["access_token"])
|
@@ -820,8 +817,8 @@ module Keycloak
|
|
820
817
|
end
|
821
818
|
|
822
819
|
def self.has_role?(user_id, user_role, client_id = '', secret = '')
|
823
|
-
client_id = Keycloak::Client.client_id if client_id
|
824
|
-
secret = Keycloak::Client.secret if secret
|
820
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
821
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
825
822
|
|
826
823
|
roles = JSON get_client_user_roles(user_id, client_id, secret)
|
827
824
|
if !roles.nil?
|
@@ -843,8 +840,8 @@ module Keycloak
|
|
843
840
|
|
844
841
|
Keycloak::Client.get_installation
|
845
842
|
|
846
|
-
client_id = Keycloak::Client.client_id if client_id
|
847
|
-
secret = Keycloak::Client.secret if secret
|
843
|
+
client_id = Keycloak::Client.client_id if isempty?(client_id)
|
844
|
+
secret = Keycloak::Client.secret if isempty?(secret)
|
848
845
|
|
849
846
|
payload = { 'client_id' => client_id,
|
850
847
|
'client_secret' => secret,
|
@@ -886,7 +883,6 @@ module Keycloak
|
|
886
883
|
end
|
887
884
|
end
|
888
885
|
end
|
889
|
-
|
890
886
|
end
|
891
887
|
|
892
888
|
private
|
@@ -945,7 +941,6 @@ module Keycloak
|
|
945
941
|
end
|
946
942
|
|
947
943
|
_request.call
|
948
|
-
|
949
944
|
end
|
950
945
|
|
951
946
|
def self.rescue_response(response)
|
@@ -957,11 +952,7 @@ module Keycloak
|
|
957
952
|
response.body
|
958
953
|
end
|
959
954
|
when 400..499
|
960
|
-
|
961
|
-
response.return!
|
962
|
-
rescue RestClient::ExceptionWithResponse => err
|
963
|
-
raise ActionController::RoutingError.new(err.response)
|
964
|
-
end
|
955
|
+
response.return!
|
965
956
|
else
|
966
957
|
if Keycloak.explode_exception
|
967
958
|
response.return!
|
@@ -978,4 +969,4 @@ module Keycloak
|
|
978
969
|
end
|
979
970
|
end
|
980
971
|
|
981
|
-
require 'keycloak/exceptions'
|
972
|
+
require 'keycloak/exceptions'
|
data/lib/keycloak/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Portugues
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|