keycloak 2.2.9 → 2.3.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 +5 -5
- data/.vscode/launch.json +65 -0
- data/README.pt-BR.md +15 -1
- data/lib/generators/keycloak.rb +4 -0
- data/lib/keycloak.rb +59 -11
- data/lib/keycloak/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bed7a57a922cce701d2a97abfe58dc2a9424a6744bf9756f2abdc99e0f8fe9a4
|
4
|
+
data.tar.gz: c133a6162ad571e0e224145524430991e94d09333f24a8cc40302b48562087bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d123f765a14329ac0078f14b252563b34b8955abc63b1c65aa2a466fc2382fc3d7eb0ecf158e08362c96bea3c81d0244b28df2ece20faf92280193840f5c855e
|
7
|
+
data.tar.gz: 785c56cfce98cf957c2c83a16143599e226ddf521d0fbaa629413f1bd9bb95f1072f3e753c19cbac8aa5d931ed2942d4f269f9a2c542f60411d4794e65824d84
|
data/.vscode/launch.json
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
{
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
3
|
+
// Hover to view descriptions of existing attributes.
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
+
"version": "0.2.0",
|
6
|
+
"configurations": [
|
7
|
+
|
8
|
+
{
|
9
|
+
"name": "Debug Local File",
|
10
|
+
"type": "Ruby",
|
11
|
+
"request": "launch",
|
12
|
+
"cwd": "${workspaceRoot}",
|
13
|
+
"program": "${workspaceRoot}/main.rb"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"name": "Listen for rdebug-ide",
|
17
|
+
"type": "Ruby",
|
18
|
+
"request": "attach",
|
19
|
+
"cwd": "${workspaceRoot}",
|
20
|
+
"remoteHost": "127.0.0.1",
|
21
|
+
"remotePort": "1234",
|
22
|
+
"remoteWorkspaceRoot": "${workspaceRoot}"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"name": "Rails server",
|
26
|
+
"type": "Ruby",
|
27
|
+
"request": "launch",
|
28
|
+
"cwd": "${workspaceRoot}",
|
29
|
+
"program": "${workspaceRoot}/bin/rails",
|
30
|
+
"args": [
|
31
|
+
"server"
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"name": "RSpec - all",
|
36
|
+
"type": "Ruby",
|
37
|
+
"request": "launch",
|
38
|
+
"cwd": "${workspaceRoot}",
|
39
|
+
"program": "${workspaceRoot}/bin/rspec",
|
40
|
+
"args": [
|
41
|
+
"-I",
|
42
|
+
"${workspaceRoot}"
|
43
|
+
]
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"name": "RSpec - active spec file only",
|
47
|
+
"type": "Ruby",
|
48
|
+
"request": "launch",
|
49
|
+
"cwd": "${workspaceRoot}",
|
50
|
+
"program": "${workspaceRoot}/bin/rspec",
|
51
|
+
"args": [
|
52
|
+
"-I",
|
53
|
+
"${workspaceRoot}",
|
54
|
+
"${file}"
|
55
|
+
]
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"name": "Cucumber",
|
59
|
+
"type": "Ruby",
|
60
|
+
"request": "launch",
|
61
|
+
"cwd": "${workspaceRoot}",
|
62
|
+
"program": "${workspaceRoot}/bin/cucumber"
|
63
|
+
}
|
64
|
+
]
|
65
|
+
}
|
data/README.pt-BR.md
CHANGED
@@ -33,7 +33,7 @@ Para adicionar o arquivo de configuração:
|
|
33
33
|
|
34
34
|
Considerando que você já possua um ambiente do Keycloak configurado e a gem já instalada, o próximo passo é definir como será a autenticação da aplicação. O Keycloak trabalha com os principais protocolos de autenticação, tais como o OpenID Connect, Oauth 2.0 e SAML 2.0, integrando acesso a sistemas via Single-Sign On, podendo inclusive disponibilizar acessos a usuários LDAP ou Active Directory.
|
35
35
|
|
36
|
-
Ao cadastrar um Reino e também um Client no seu ambiente Keycloak,
|
36
|
+
Ao cadastrar um Reino e também um Client no seu ambiente Keycloak, você poderá fazer o download do arquivo de instalação do Client para dentro da pasta raiz da aplicação, para que a gem obtenha as informações necessárias para interagir com o Keycloak. Para fazer esse download, basta acessar o cadastro de seu Client, clicar na aba <b>Installation</b>, selecionar <b>Keycloak OIDC JSON</b> no campo <b>Format option</b> e clicar em <b>Download</b>. Caso a sua aplicação não trabalhe apenas com um client específico (aplicação servidora de APIs, por exemplo), então você poderá informar o reino que a gem irá interagir no arquivo de configuração `keycloak.rb`.
|
37
37
|
|
38
38
|
A gem possui um módulo principal chamado <b>Keycloak</b>. Dentro desse módulo há três outros módulos: <b>Client</b>, <b>Admin</b> e <b>Internal</b>.
|
39
39
|
|
@@ -41,6 +41,20 @@ A gem possui um módulo principal chamado <b>Keycloak</b>. Dentro desse módulo
|
|
41
41
|
|
42
42
|
O módulo Keycloak possui alguns atributos e suas definições são fundamentais para o perfeito funcionamento da gem na aplicação.
|
43
43
|
|
44
|
+
```ruby
|
45
|
+
Keycloak.realm
|
46
|
+
```
|
47
|
+
|
48
|
+
Se a sua aplicação não trabalha apenas com um client específico (aplicação servidora de APIs, por exemplo), então você poderá informar o nome reino que a gem irá interagir nesse atributo. Ao ser instalada, a gem cria o arquivo `keycloak.rb` em `config/initializers`. Este atributo pode ser encontrado e definido nesse arquivo.
|
49
|
+
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Keycloak.auth_server_url
|
53
|
+
```
|
54
|
+
|
55
|
+
Para o mesmo cenário do atributo acima, você poderá informar a url reino que a gem irá interagir nesse atributo. Ao ser instalada, a gem cria o arquivo `keycloak.rb` em `config/initializers`. Este atributo pode ser encontrado e definido nesse arquivo.
|
56
|
+
|
57
|
+
|
44
58
|
```ruby
|
45
59
|
Keycloak.proxy
|
46
60
|
```
|
data/lib/generators/keycloak.rb
CHANGED
@@ -4,3 +4,7 @@ Keycloak.proxy = ''
|
|
4
4
|
Keycloak.generate_request_exception = true
|
5
5
|
# controller that manage the user session
|
6
6
|
Keycloak.keycloak_controller = 'session'
|
7
|
+
# relm name (only if the installation file is not present)
|
8
|
+
Keycloak.realm = ''
|
9
|
+
# relm url (only if the installation file is not present)
|
10
|
+
Keycloak.auth_server_url = ''
|
data/lib/keycloak.rb
CHANGED
@@ -8,7 +8,8 @@ require 'uri'
|
|
8
8
|
module Keycloak
|
9
9
|
class << self
|
10
10
|
attr_accessor :proxy, :generate_request_exception, :keycloak_controller,
|
11
|
-
:proc_cookie_token, :proc_external_attributes
|
11
|
+
:proc_cookie_token, :proc_external_attributes,
|
12
|
+
:realm, :auth_server_url
|
12
13
|
end
|
13
14
|
|
14
15
|
|
@@ -21,8 +22,8 @@ module Keycloak
|
|
21
22
|
|
22
23
|
module Client
|
23
24
|
class << self
|
24
|
-
|
25
|
-
|
25
|
+
attr_accessor :realm, :auth_server_url
|
26
|
+
attr_reader :client_id, :secret, :configuration, :public_key
|
26
27
|
end
|
27
28
|
|
28
29
|
KEYCLOAK_JSON_FILE = 'keycloak.json'
|
@@ -51,6 +52,41 @@ module Keycloak
|
|
51
52
|
mount_request_token(payload)
|
52
53
|
end
|
53
54
|
|
55
|
+
def self.get_token_by_exchange(issuer, issuer_token)
|
56
|
+
setup_module
|
57
|
+
|
58
|
+
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 }
|
59
|
+
header = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
60
|
+
_request = -> do
|
61
|
+
RestClient.post(@configuration['token_endpoint'], payload, header){|response, request, result|
|
62
|
+
# case response.code
|
63
|
+
# when 200
|
64
|
+
# response.body
|
65
|
+
# else
|
66
|
+
# response.return!
|
67
|
+
# end
|
68
|
+
response.body
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
exec_request _request
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.get_userinfo_issuer(access_token = '')
|
76
|
+
verify_setup
|
77
|
+
|
78
|
+
access_token = self.token["access_token"] if access_token.empty?
|
79
|
+
payload = { 'access_token' => access_token }
|
80
|
+
header = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
81
|
+
_request = -> do
|
82
|
+
RestClient.post(@configuration['userinfo_endpoint'], payload, header){ |response, request, result|
|
83
|
+
response.body
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
exec_request _request
|
88
|
+
end
|
89
|
+
|
54
90
|
def self.get_token_by_refresh_token(refresh_token = '')
|
55
91
|
verify_setup
|
56
92
|
|
@@ -77,14 +113,16 @@ module Keycloak
|
|
77
113
|
mount_request_token(payload)
|
78
114
|
end
|
79
115
|
|
80
|
-
def self.get_token_introspection(token = '')
|
116
|
+
def self.get_token_introspection(token = '', client_id = '', secret = '')
|
81
117
|
verify_setup
|
82
118
|
|
83
119
|
token = self.token["access_token"] if token.empty?
|
84
|
-
|
85
120
|
payload = { 'token' => token }
|
86
121
|
|
87
|
-
|
122
|
+
client_id = @client_id if client_id.empty?
|
123
|
+
secret = @secret if secret.empty?
|
124
|
+
|
125
|
+
authorization = Base64.strict_encode64("#{client_id}:#{secret}")
|
88
126
|
authorization = "Basic #{authorization}"
|
89
127
|
|
90
128
|
header = {'Content-Type' => 'application/x-www-form-urlencoded',
|
@@ -95,7 +133,6 @@ module Keycloak
|
|
95
133
|
case response.code
|
96
134
|
when 200..399
|
97
135
|
response.body
|
98
|
-
|
99
136
|
else
|
100
137
|
response.return!
|
101
138
|
end
|
@@ -175,7 +212,7 @@ module Keycloak
|
|
175
212
|
def self.url_user_account
|
176
213
|
verify_setup
|
177
214
|
|
178
|
-
"#{@
|
215
|
+
"#{@auth_server_url}/realms/#{@realm}/account"
|
179
216
|
end
|
180
217
|
|
181
218
|
def self.has_role?(user_role, access_token = '')
|
@@ -242,14 +279,19 @@ module Keycloak
|
|
242
279
|
if File.exists?(KEYCLOAK_JSON_FILE)
|
243
280
|
installation = JSON File.read(KEYCLOAK_JSON_FILE)
|
244
281
|
@realm = installation["realm"]
|
245
|
-
@url = installation["auth-server-url"]
|
246
282
|
@client_id = installation["resource"]
|
247
283
|
@secret = installation["credentials"]["secret"]
|
248
284
|
@public_key = installation["realm-public-key"]
|
249
285
|
@auth_server_url = installation["auth-server-url"]
|
250
286
|
openid_configuration
|
251
287
|
else
|
252
|
-
|
288
|
+
if Keycloak.realm.blank? || Keycloak.auth_server_url.blank?
|
289
|
+
raise "#{KEYCLOAK_JSON_FILE} and relm settings not found."
|
290
|
+
else
|
291
|
+
@realm = Keycloak.realm
|
292
|
+
@auth_server_url = Keycloak.auth_server_url
|
293
|
+
openid_configuration
|
294
|
+
end
|
253
295
|
end
|
254
296
|
end
|
255
297
|
|
@@ -277,7 +319,7 @@ module Keycloak
|
|
277
319
|
|
278
320
|
def self.openid_configuration
|
279
321
|
RestClient.proxy = Keycloak.proxy unless Keycloak.proxy.empty?
|
280
|
-
config_url = "#{@
|
322
|
+
config_url = "#{@auth_server_url}/realms/#{@realm}/.well-known/openid-configuration"
|
281
323
|
_request = -> do
|
282
324
|
RestClient.get config_url
|
283
325
|
end
|
@@ -827,6 +869,12 @@ module Keycloak
|
|
827
869
|
else
|
828
870
|
response.body
|
829
871
|
end
|
872
|
+
when 400..499
|
873
|
+
begin
|
874
|
+
response.return!
|
875
|
+
rescue RestClient::ExceptionWithResponse => err
|
876
|
+
raise ActionController::RoutingError.new(err.response)
|
877
|
+
end
|
830
878
|
else
|
831
879
|
if Keycloak.explode_exception
|
832
880
|
response.return!
|
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.3.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:
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
106
|
- ".travis.yml"
|
107
|
+
- ".vscode/launch.json"
|
107
108
|
- CODE_OF_CONDUCT.md
|
108
109
|
- Gemfile
|
109
110
|
- LICENSE.txt
|
@@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
version: '0'
|
139
140
|
requirements: []
|
140
141
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.7.3
|
142
143
|
signing_key:
|
143
144
|
specification_version: 4
|
144
145
|
summary: Add authentication to applications and secure services with Keycloak
|