keycloak 2.0.0 → 2.1.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/lib/keycloak.rb +48 -42
- data/lib/keycloak/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd7cbf6d2db06b82251cd19d94c9753b33756a1f
|
4
|
+
data.tar.gz: febd42f89d7269eac914fb92b1c003ecf62e5a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d049e46d6b42a45f88a71e08617b0aabe15ee9af3690967f618795f84e635244e907b5c7b0e53e36d8e937351f8788836801ff56d955d2facd0b41f7efb5fac1
|
7
|
+
data.tar.gz: 9dbf3762c6773581c334498d4ecaa6eaf67b5c58fc410a7f1d3b553c6065be2c27762bdabbcbfde2bd4540e5f1b05ac3598167c944ba06e3fde174af3a727256
|
data/lib/keycloak.rb
CHANGED
@@ -56,10 +56,10 @@ module Keycloak
|
|
56
56
|
mount_request_token(payload)
|
57
57
|
end
|
58
58
|
|
59
|
-
def self.get_token_by_refresh_token(refreshToken =
|
59
|
+
def self.get_token_by_refresh_token(refreshToken = '')
|
60
60
|
verify_setup
|
61
61
|
|
62
|
-
refreshToken = self.token['refresh_token']
|
62
|
+
refreshToken = self.token['refresh_token'] if refreshToken.empty?
|
63
63
|
|
64
64
|
payload = {'client_id' => @client_id,
|
65
65
|
'client_secret' => @secret,
|
@@ -81,14 +81,12 @@ module Keycloak
|
|
81
81
|
mount_request_token(payload)
|
82
82
|
end
|
83
83
|
|
84
|
-
def self.get_token_introspection(
|
84
|
+
def self.get_token_introspection(token = '')
|
85
85
|
verify_setup
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
payload = {'token' => self.token["refresh_token"]}
|
91
|
-
end
|
87
|
+
token = self.token["access_token"] if token.empty?
|
88
|
+
|
89
|
+
payload = {'token' => token}
|
92
90
|
|
93
91
|
authorization = Base64.strict_encode64("#{@client_id}:#{@secret}")
|
94
92
|
authorization = "Basic #{authorization}"
|
@@ -118,13 +116,16 @@ module Keycloak
|
|
118
116
|
"#{@configuration['authorization_endpoint']}?#{p}"
|
119
117
|
end
|
120
118
|
|
121
|
-
def self.logout(redirect_uri = '')
|
119
|
+
def self.logout(redirect_uri = '', refresh_token = '')
|
122
120
|
verify_setup
|
123
121
|
|
124
|
-
if self.token
|
122
|
+
if self.token || !refresh_token.empty?
|
123
|
+
|
124
|
+
refresh_token = self.token['refresh_token'] if refresh_token.empty?
|
125
|
+
|
125
126
|
payload = {'client_id' => @client_id,
|
126
127
|
'client_secret' => @secret,
|
127
|
-
'refresh_token' =>
|
128
|
+
'refresh_token' => refresh_token
|
128
129
|
}
|
129
130
|
|
130
131
|
header = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
@@ -152,10 +153,12 @@ module Keycloak
|
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
155
|
-
def self.get_userinfo
|
156
|
+
def self.get_userinfo(accessToken = '')
|
156
157
|
verify_setup
|
157
158
|
|
158
|
-
|
159
|
+
accessToken = self.token["access_token"] if accessToken.empty?
|
160
|
+
|
161
|
+
payload = {'access_token' => accessToken}
|
159
162
|
|
160
163
|
header = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
161
164
|
|
@@ -179,26 +182,11 @@ module Keycloak
|
|
179
182
|
"#{@url}/realms/#{@realm}/account"
|
180
183
|
end
|
181
184
|
|
182
|
-
def self.
|
183
|
-
if File.exists?(KEYCLOAK_JSON_FILE)
|
184
|
-
installation = JSON File.read(KEYCLOAK_JSON_FILE)
|
185
|
-
@realm = installation["realm"]
|
186
|
-
@url = installation["auth-server-url"]
|
187
|
-
@client_id = installation["resource"]
|
188
|
-
@secret = installation["credentials"]["secret"]
|
189
|
-
@public_key = installation["realm-public-key"]
|
190
|
-
@auth_server_url = installation["auth-server-url"]
|
191
|
-
openid_configuration
|
192
|
-
else
|
193
|
-
raise "#{KEYCLOAK_JSON_FILE} not found."
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def self.has_role?(userRole)
|
185
|
+
def self.has_role?(userRole, accessToken = '')
|
198
186
|
verify_setup
|
199
187
|
|
200
|
-
if user_signed_in?
|
201
|
-
dt = decoded_access_token[0]
|
188
|
+
if user_signed_in?(accessToken)
|
189
|
+
dt = decoded_access_token(accessToken)[0]
|
202
190
|
dt = dt["resource_access"][@client_id]
|
203
191
|
if dt != nil
|
204
192
|
dt["roles"].each do |role|
|
@@ -213,11 +201,11 @@ module Keycloak
|
|
213
201
|
end
|
214
202
|
end
|
215
203
|
|
216
|
-
def self.user_signed_in?
|
204
|
+
def self.user_signed_in?(accessToken = '')
|
217
205
|
verify_setup
|
218
206
|
|
219
207
|
begin
|
220
|
-
JSON(get_token_introspection)['active'] === true
|
208
|
+
JSON(get_token_introspection(accessToken))['active'] === true
|
221
209
|
rescue => e
|
222
210
|
if e.class < Keycloak::KeycloakException
|
223
211
|
raise
|
@@ -227,10 +215,10 @@ module Keycloak
|
|
227
215
|
end
|
228
216
|
end
|
229
217
|
|
230
|
-
def self.get_attribute(attributeName)
|
218
|
+
def self.get_attribute(attributeName, accessToken = '')
|
231
219
|
verify_setup
|
232
220
|
|
233
|
-
attr = decoded_access_token[0]
|
221
|
+
attr = decoded_access_token(accessToken)[0]
|
234
222
|
attr[attributeName]
|
235
223
|
end
|
236
224
|
|
@@ -254,6 +242,21 @@ module Keycloak
|
|
254
242
|
|
255
243
|
KEYCLOACK_CONTROLLER_DEFAULT = 'session'
|
256
244
|
|
245
|
+
def self.get_installation
|
246
|
+
if File.exists?(KEYCLOAK_JSON_FILE)
|
247
|
+
installation = JSON File.read(KEYCLOAK_JSON_FILE)
|
248
|
+
@realm = installation["realm"]
|
249
|
+
@url = installation["auth-server-url"]
|
250
|
+
@client_id = installation["resource"]
|
251
|
+
@secret = installation["credentials"]["secret"]
|
252
|
+
@public_key = installation["realm-public-key"]
|
253
|
+
@auth_server_url = installation["auth-server-url"]
|
254
|
+
openid_configuration
|
255
|
+
else
|
256
|
+
raise "#{KEYCLOAK_JSON_FILE} not found."
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
257
260
|
def self.verify_setup
|
258
261
|
get_installation if @configuration.nil?
|
259
262
|
end
|
@@ -307,18 +310,21 @@ module Keycloak
|
|
307
310
|
exec_request _request
|
308
311
|
end
|
309
312
|
|
310
|
-
def self.decoded_access_token
|
311
|
-
|
313
|
+
def self.decoded_access_token(accessToken = '')
|
314
|
+
accessToken = self.token["access_token"] if accessToken.empty?
|
315
|
+
JWT.decode accessToken, @public_key, false, { :algorithm => 'RS256' }
|
312
316
|
end
|
313
317
|
|
314
|
-
def self.decoded_refresh_token
|
315
|
-
|
318
|
+
def self.decoded_refresh_token(refreshToken = '')
|
319
|
+
refreshToken = self.token["access_token"] if refreshToken.empty?
|
320
|
+
JWT.decode refreshToken, @public_key, false, { :algorithm => 'RS256' }
|
316
321
|
end
|
317
322
|
|
318
|
-
def self.decoded_id_token
|
323
|
+
def self.decoded_id_token(idToken = '')
|
319
324
|
tk = self.token
|
320
|
-
|
321
|
-
|
325
|
+
idToken = tk["id_token"] if idToken.empty?
|
326
|
+
if idToken
|
327
|
+
@decoded_id_token = JWT.decode idToken, @public_key, false, { :algorithm => 'RS256' }
|
322
328
|
end
|
323
329
|
end
|
324
330
|
|
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: 2.
|
4
|
+
version: 2.1.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: 2017-08-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|