keycloak-api-rails 0.12.4 → 1.0.1
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/.github/workflows/ci.yml +28 -0
- data/CHANGELOG.md +13 -0
- data/Dockerfile +1 -1
- data/Gemfile.lock +159 -138
- data/README.md +19 -19
- data/keycloak-api-rails.gemspec +4 -4
- data/lib/keycloak-api-rails/authentication.rb +9 -11
- data/lib/keycloak-api-rails/configuration.rb +10 -11
- data/lib/keycloak-api-rails/helper.rb +3 -3
- data/lib/keycloak-api-rails/http_client.rb +2 -2
- data/lib/keycloak-api-rails/middleware.rb +4 -4
- data/lib/keycloak-api-rails/public_key_cached_resolver.rb +2 -2
- data/lib/keycloak-api-rails/public_key_resolver.rb +1 -1
- data/lib/keycloak-api-rails/railtie.rb +2 -2
- data/lib/keycloak-api-rails/service.rb +7 -7
- data/lib/keycloak-api-rails/version.rb +2 -2
- data/lib/keycloak-api-rails.rb +4 -4
- data/spec/keycloak-api-rails/activesupport_free_spec.rb +18 -0
- data/spec/keycloak-api-rails/authentication_spec.rb +42 -4
- data/spec/keycloak-api-rails/configuration_spec.rb +101 -0
- data/spec/keycloak-api-rails/helper_spec.rb +63 -2
- data/spec/keycloak-api-rails/public_key_cached_resolver_spec.rb +3 -3
- data/spec/keycloak-api-rails/service_spec.rb +30 -8
- data/spec/support/activesupport_free_probe.rb +131 -0
- data/spec/support/public_key_cached_resolver_stub.rb +1 -1
- data/spec/support/public_key_resolver_stub.rb +1 -1
- metadata +16 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72a9cf5907ae0256e7acfbf9bd9e453dcbcaeae5fd4c5ce146780e3ef5ec2644
|
|
4
|
+
data.tar.gz: ac22d1edfbf8d1701ac82a213f3052ca32976dd766841111066600910497d58d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e73d57fcaf904c534048ff6d6e611913298b173be1e47b01b31c7c6cb351f2e8d74b00a57027ce03063b63391f2200c9c8d866a18a7cb632856acb77bdb5d494
|
|
7
|
+
data.tar.gz: be4136364d974a0ebcba62a31f526341cdef89f0f87f991dde409cb40a36303f0ae4a781599929caf830cf89a58ce01b20e2c7209ef7613c9e0d465b831bbb17
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ "main" ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ "main" ]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
ruby-version: ['3.2']
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- name: Set up Ruby
|
|
23
|
+
uses: ruby/setup-ruby@v1
|
|
24
|
+
with:
|
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
26
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ 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
|
+
## [1.0.1] - 2026-07-30
|
|
9
|
+
|
|
10
|
+
* Dependencies: Upgrade test dependency `timecop` to `0.9.11`
|
|
11
|
+
* Upgrade Docker image to Ruby 3.4
|
|
12
|
+
* Remove all usages of `ActiveSupport` from the library, replaced by plain Ruby
|
|
13
|
+
|
|
14
|
+
## [1.0.0] - 2025-12-10
|
|
15
|
+
|
|
16
|
+
* *[BREAKING CHANGE!]* Rename top-level module from `Keycloak` to `KeycloakApiRails` to avoid conflicts with other gems. (thanks to @eilers)
|
|
17
|
+
* *Migration: Please do a global find and replace of `Keycloak.` to `KeycloakApiRails.` in your application.*
|
|
18
|
+
* Automate tests on Github Actions
|
|
19
|
+
* Dependencies: Upgrade test dependencies: timecop, rspec and byebug.
|
|
20
|
+
|
|
8
21
|
## [0.12.4] - 2024-06-20
|
|
9
22
|
|
|
10
23
|
* Log error when fetching the public keys from Keycloak
|
data/Dockerfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,228 +1,249 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
keycloak-api-rails (0.
|
|
4
|
+
keycloak-api-rails (1.0.0)
|
|
5
5
|
json-jwt (>= 1.11.0)
|
|
6
6
|
rails (>= 4.2)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
action_text-trix (2.1.19)
|
|
12
|
+
railties
|
|
13
|
+
actioncable (8.1.3.1)
|
|
14
|
+
actionpack (= 8.1.3.1)
|
|
15
|
+
activesupport (= 8.1.3.1)
|
|
14
16
|
nio4r (~> 2.0)
|
|
15
17
|
websocket-driver (>= 0.6.1)
|
|
16
18
|
zeitwerk (~> 2.6)
|
|
17
|
-
actionmailbox (
|
|
18
|
-
actionpack (=
|
|
19
|
-
activejob (=
|
|
20
|
-
activerecord (=
|
|
21
|
-
activestorage (=
|
|
22
|
-
activesupport (=
|
|
23
|
-
mail (>= 2.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
activejob (= 7.1.3.4)
|
|
31
|
-
activesupport (= 7.1.3.4)
|
|
32
|
-
mail (~> 2.5, >= 2.5.4)
|
|
33
|
-
net-imap
|
|
34
|
-
net-pop
|
|
35
|
-
net-smtp
|
|
19
|
+
actionmailbox (8.1.3.1)
|
|
20
|
+
actionpack (= 8.1.3.1)
|
|
21
|
+
activejob (= 8.1.3.1)
|
|
22
|
+
activerecord (= 8.1.3.1)
|
|
23
|
+
activestorage (= 8.1.3.1)
|
|
24
|
+
activesupport (= 8.1.3.1)
|
|
25
|
+
mail (>= 2.8.0)
|
|
26
|
+
actionmailer (8.1.3.1)
|
|
27
|
+
actionpack (= 8.1.3.1)
|
|
28
|
+
actionview (= 8.1.3.1)
|
|
29
|
+
activejob (= 8.1.3.1)
|
|
30
|
+
activesupport (= 8.1.3.1)
|
|
31
|
+
mail (>= 2.8.0)
|
|
36
32
|
rails-dom-testing (~> 2.2)
|
|
37
|
-
actionpack (
|
|
38
|
-
actionview (=
|
|
39
|
-
activesupport (=
|
|
33
|
+
actionpack (8.1.3.1)
|
|
34
|
+
actionview (= 8.1.3.1)
|
|
35
|
+
activesupport (= 8.1.3.1)
|
|
40
36
|
nokogiri (>= 1.8.5)
|
|
41
|
-
racc
|
|
42
37
|
rack (>= 2.2.4)
|
|
43
38
|
rack-session (>= 1.0.1)
|
|
44
39
|
rack-test (>= 0.6.3)
|
|
45
40
|
rails-dom-testing (~> 2.2)
|
|
46
41
|
rails-html-sanitizer (~> 1.6)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
useragent (~> 0.16)
|
|
43
|
+
actiontext (8.1.3.1)
|
|
44
|
+
action_text-trix (~> 2.1.15)
|
|
45
|
+
actionpack (= 8.1.3.1)
|
|
46
|
+
activerecord (= 8.1.3.1)
|
|
47
|
+
activestorage (= 8.1.3.1)
|
|
48
|
+
activesupport (= 8.1.3.1)
|
|
52
49
|
globalid (>= 0.6.0)
|
|
53
50
|
nokogiri (>= 1.8.5)
|
|
54
|
-
actionview (
|
|
55
|
-
activesupport (=
|
|
51
|
+
actionview (8.1.3.1)
|
|
52
|
+
activesupport (= 8.1.3.1)
|
|
56
53
|
builder (~> 3.1)
|
|
57
54
|
erubi (~> 1.11)
|
|
58
55
|
rails-dom-testing (~> 2.2)
|
|
59
56
|
rails-html-sanitizer (~> 1.6)
|
|
60
|
-
activejob (
|
|
61
|
-
activesupport (=
|
|
57
|
+
activejob (8.1.3.1)
|
|
58
|
+
activesupport (= 8.1.3.1)
|
|
62
59
|
globalid (>= 0.3.6)
|
|
63
|
-
activemodel (
|
|
64
|
-
activesupport (=
|
|
65
|
-
activerecord (
|
|
66
|
-
activemodel (=
|
|
67
|
-
activesupport (=
|
|
60
|
+
activemodel (8.1.3.1)
|
|
61
|
+
activesupport (= 8.1.3.1)
|
|
62
|
+
activerecord (8.1.3.1)
|
|
63
|
+
activemodel (= 8.1.3.1)
|
|
64
|
+
activesupport (= 8.1.3.1)
|
|
68
65
|
timeout (>= 0.4.0)
|
|
69
|
-
activestorage (
|
|
70
|
-
actionpack (=
|
|
71
|
-
activejob (=
|
|
72
|
-
activerecord (=
|
|
73
|
-
activesupport (=
|
|
66
|
+
activestorage (8.1.3.1)
|
|
67
|
+
actionpack (= 8.1.3.1)
|
|
68
|
+
activejob (= 8.1.3.1)
|
|
69
|
+
activerecord (= 8.1.3.1)
|
|
70
|
+
activesupport (= 8.1.3.1)
|
|
74
71
|
marcel (~> 1.0)
|
|
75
|
-
activesupport (
|
|
72
|
+
activesupport (8.1.3.1)
|
|
76
73
|
base64
|
|
77
74
|
bigdecimal
|
|
78
|
-
concurrent-ruby (~> 1.0, >= 1.
|
|
75
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
79
76
|
connection_pool (>= 2.2.5)
|
|
80
77
|
drb
|
|
81
78
|
i18n (>= 1.6, < 2)
|
|
79
|
+
json
|
|
80
|
+
logger (>= 1.4.2)
|
|
82
81
|
minitest (>= 5.1)
|
|
83
|
-
|
|
84
|
-
tzinfo (~> 2.0)
|
|
82
|
+
securerandom (>= 0.3)
|
|
83
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
84
|
+
uri (>= 0.13.1)
|
|
85
85
|
aes_key_wrap (1.1.0)
|
|
86
|
-
base64 (0.
|
|
87
|
-
bigdecimal (
|
|
88
|
-
bindata (
|
|
86
|
+
base64 (0.3.0)
|
|
87
|
+
bigdecimal (4.1.2)
|
|
88
|
+
bindata (3.0.0)
|
|
89
89
|
builder (3.3.0)
|
|
90
|
-
byebug (
|
|
91
|
-
concurrent-ruby (1.3.
|
|
92
|
-
connection_pool (
|
|
93
|
-
crass (1.0.
|
|
94
|
-
date (3.
|
|
95
|
-
diff-lcs (1.
|
|
96
|
-
drb (2.2.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
byebug (12.0.0)
|
|
91
|
+
concurrent-ruby (1.3.8)
|
|
92
|
+
connection_pool (3.0.2)
|
|
93
|
+
crass (1.0.7)
|
|
94
|
+
date (3.5.1)
|
|
95
|
+
diff-lcs (1.6.2)
|
|
96
|
+
drb (2.2.3)
|
|
97
|
+
erb (6.0.6)
|
|
98
|
+
erubi (1.13.1)
|
|
99
|
+
faraday (2.14.3)
|
|
100
|
+
faraday-net_http (>= 2.0, < 3.5)
|
|
101
|
+
json
|
|
102
|
+
logger
|
|
103
|
+
faraday-follow_redirects (0.5.0)
|
|
101
104
|
faraday (>= 1, < 3)
|
|
102
|
-
faraday-net_http (3.
|
|
103
|
-
net-http
|
|
104
|
-
globalid (1.
|
|
105
|
+
faraday-net_http (3.4.4)
|
|
106
|
+
net-http (~> 0.5)
|
|
107
|
+
globalid (1.4.0)
|
|
105
108
|
activesupport (>= 6.1)
|
|
106
|
-
i18n (1.
|
|
109
|
+
i18n (1.15.2)
|
|
107
110
|
concurrent-ruby (~> 1.0)
|
|
108
|
-
io-console (0.
|
|
109
|
-
irb (1.
|
|
111
|
+
io-console (0.8.2)
|
|
112
|
+
irb (1.18.0)
|
|
113
|
+
pp (>= 0.6.0)
|
|
114
|
+
prism (>= 1.3.0)
|
|
110
115
|
rdoc (>= 4.0.0)
|
|
111
116
|
reline (>= 0.4.2)
|
|
112
|
-
json
|
|
117
|
+
json (2.21.1)
|
|
118
|
+
json-jwt (1.17.1)
|
|
113
119
|
activesupport (>= 4.2)
|
|
114
120
|
aes_key_wrap
|
|
115
121
|
base64
|
|
116
122
|
bindata
|
|
117
123
|
faraday (~> 2.0)
|
|
118
124
|
faraday-follow_redirects
|
|
119
|
-
|
|
125
|
+
logger (1.7.0)
|
|
126
|
+
loofah (2.25.2)
|
|
120
127
|
crass (~> 1.0.2)
|
|
121
128
|
nokogiri (>= 1.12.0)
|
|
122
|
-
mail (2.
|
|
129
|
+
mail (2.9.1)
|
|
130
|
+
logger
|
|
123
131
|
mini_mime (>= 0.1.1)
|
|
124
132
|
net-imap
|
|
125
133
|
net-pop
|
|
126
134
|
net-smtp
|
|
127
|
-
marcel (1.
|
|
135
|
+
marcel (1.2.1)
|
|
128
136
|
mini_mime (1.1.5)
|
|
129
|
-
mini_portile2 (2.8.
|
|
130
|
-
minitest (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
mini_portile2 (2.8.9)
|
|
138
|
+
minitest (6.0.6)
|
|
139
|
+
drb (~> 2.0)
|
|
140
|
+
prism (~> 1.5)
|
|
141
|
+
net-http (0.9.1)
|
|
142
|
+
uri (>= 0.11.1)
|
|
143
|
+
net-imap (0.6.6)
|
|
135
144
|
date
|
|
136
145
|
net-protocol
|
|
137
146
|
net-pop (0.1.2)
|
|
138
147
|
net-protocol
|
|
139
148
|
net-protocol (0.2.2)
|
|
140
149
|
timeout
|
|
141
|
-
net-smtp (0.5.
|
|
150
|
+
net-smtp (0.5.1)
|
|
142
151
|
net-protocol
|
|
143
|
-
nio4r (2.7.
|
|
144
|
-
nokogiri (1.
|
|
152
|
+
nio4r (2.7.5)
|
|
153
|
+
nokogiri (1.19.4)
|
|
145
154
|
mini_portile2 (~> 2.8.2)
|
|
146
155
|
racc (~> 1.4)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
pp (0.6.4)
|
|
157
|
+
prettyprint
|
|
158
|
+
prettyprint (0.2.0)
|
|
159
|
+
prism (1.9.0)
|
|
160
|
+
racc (1.8.1)
|
|
161
|
+
rack (3.2.6)
|
|
162
|
+
rack-session (2.1.2)
|
|
163
|
+
base64 (>= 0.1.0)
|
|
152
164
|
rack (>= 3.0.0)
|
|
153
|
-
rack-test (2.
|
|
165
|
+
rack-test (2.2.0)
|
|
154
166
|
rack (>= 1.3)
|
|
155
|
-
rackup (2.1
|
|
167
|
+
rackup (2.3.1)
|
|
156
168
|
rack (>= 3)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
activesupport (= 7.1.3.4)
|
|
169
|
+
rails (8.1.3.1)
|
|
170
|
+
actioncable (= 8.1.3.1)
|
|
171
|
+
actionmailbox (= 8.1.3.1)
|
|
172
|
+
actionmailer (= 8.1.3.1)
|
|
173
|
+
actionpack (= 8.1.3.1)
|
|
174
|
+
actiontext (= 8.1.3.1)
|
|
175
|
+
actionview (= 8.1.3.1)
|
|
176
|
+
activejob (= 8.1.3.1)
|
|
177
|
+
activemodel (= 8.1.3.1)
|
|
178
|
+
activerecord (= 8.1.3.1)
|
|
179
|
+
activestorage (= 8.1.3.1)
|
|
180
|
+
activesupport (= 8.1.3.1)
|
|
170
181
|
bundler (>= 1.15.0)
|
|
171
|
-
railties (=
|
|
172
|
-
rails-dom-testing (2.
|
|
182
|
+
railties (= 8.1.3.1)
|
|
183
|
+
rails-dom-testing (2.3.0)
|
|
173
184
|
activesupport (>= 5.0.0)
|
|
174
185
|
minitest
|
|
175
186
|
nokogiri (>= 1.6)
|
|
176
|
-
rails-html-sanitizer (1.
|
|
177
|
-
loofah (~> 2.
|
|
178
|
-
nokogiri (
|
|
179
|
-
railties (
|
|
180
|
-
actionpack (=
|
|
181
|
-
activesupport (=
|
|
182
|
-
irb
|
|
187
|
+
rails-html-sanitizer (1.7.1)
|
|
188
|
+
loofah (~> 2.25, >= 2.25.2)
|
|
189
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
190
|
+
railties (8.1.3.1)
|
|
191
|
+
actionpack (= 8.1.3.1)
|
|
192
|
+
activesupport (= 8.1.3.1)
|
|
193
|
+
irb (~> 1.13)
|
|
183
194
|
rackup (>= 1.0.0)
|
|
184
195
|
rake (>= 12.2)
|
|
185
196
|
thor (~> 1.0, >= 1.2.2)
|
|
197
|
+
tsort (>= 0.2)
|
|
186
198
|
zeitwerk (~> 2.6)
|
|
187
|
-
rake (13.2
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
199
|
+
rake (13.4.2)
|
|
200
|
+
rbs (4.1.1)
|
|
201
|
+
logger
|
|
202
|
+
prism (>= 1.6.0)
|
|
203
|
+
tsort
|
|
204
|
+
rdoc (8.0.0)
|
|
205
|
+
erb
|
|
206
|
+
prism (>= 1.6.0)
|
|
207
|
+
rbs (>= 4.0.0)
|
|
208
|
+
tsort
|
|
209
|
+
reline (0.6.3)
|
|
191
210
|
io-console (~> 0.5)
|
|
192
|
-
rspec (3.
|
|
193
|
-
rspec-core (~> 3.
|
|
194
|
-
rspec-expectations (~> 3.
|
|
195
|
-
rspec-mocks (~> 3.
|
|
196
|
-
rspec-core (3.
|
|
197
|
-
rspec-support (~> 3.
|
|
198
|
-
rspec-expectations (3.
|
|
211
|
+
rspec (3.13.2)
|
|
212
|
+
rspec-core (~> 3.13.0)
|
|
213
|
+
rspec-expectations (~> 3.13.0)
|
|
214
|
+
rspec-mocks (~> 3.13.0)
|
|
215
|
+
rspec-core (3.13.6)
|
|
216
|
+
rspec-support (~> 3.13.0)
|
|
217
|
+
rspec-expectations (3.13.5)
|
|
199
218
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
200
|
-
rspec-support (~> 3.
|
|
201
|
-
rspec-mocks (3.
|
|
219
|
+
rspec-support (~> 3.13.0)
|
|
220
|
+
rspec-mocks (3.13.8)
|
|
202
221
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
203
|
-
rspec-support (~> 3.
|
|
204
|
-
rspec-support (3.
|
|
205
|
-
|
|
206
|
-
thor (1.
|
|
207
|
-
timecop (0.9.
|
|
208
|
-
timeout (0.
|
|
222
|
+
rspec-support (~> 3.13.0)
|
|
223
|
+
rspec-support (3.13.7)
|
|
224
|
+
securerandom (0.4.1)
|
|
225
|
+
thor (1.5.0)
|
|
226
|
+
timecop (0.9.11)
|
|
227
|
+
timeout (0.6.1)
|
|
228
|
+
tsort (0.2.0)
|
|
209
229
|
tzinfo (2.0.6)
|
|
210
230
|
concurrent-ruby (~> 1.0)
|
|
211
|
-
uri (
|
|
212
|
-
|
|
213
|
-
websocket-driver (0.
|
|
231
|
+
uri (1.1.1)
|
|
232
|
+
useragent (0.16.11)
|
|
233
|
+
websocket-driver (0.8.2)
|
|
234
|
+
base64
|
|
214
235
|
websocket-extensions (>= 0.1.0)
|
|
215
236
|
websocket-extensions (0.1.5)
|
|
216
|
-
zeitwerk (2.
|
|
237
|
+
zeitwerk (2.8.2)
|
|
217
238
|
|
|
218
239
|
PLATFORMS
|
|
219
240
|
ruby
|
|
220
241
|
|
|
221
242
|
DEPENDENCIES
|
|
222
|
-
byebug (=
|
|
243
|
+
byebug (= 12.0.0)
|
|
223
244
|
keycloak-api-rails!
|
|
224
|
-
rspec (= 3.
|
|
225
|
-
timecop (= 0.9.
|
|
245
|
+
rspec (= 3.13.2)
|
|
246
|
+
timecop (= 0.9.11)
|
|
226
247
|
|
|
227
248
|
BUNDLED WITH
|
|
228
249
|
2.4.13
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@ This gem validates Keycloak JWT token for Ruby On Rails APIs.
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```ruby
|
|
8
|
-
gem "keycloak-api-rails", "0.
|
|
8
|
+
gem "keycloak-api-rails", "1.0.1"
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Token validation
|
|
@@ -25,11 +25,11 @@ _If both method are used at the same time, The query string as a higher priority
|
|
|
25
25
|
|
|
26
26
|
By default, Keycloak-api-rails installs as a Rack Middleware. It processes all requests before any application logic. URIs/Paths can be excluded (opted-out) from this validation using the 'skip_paths' config option
|
|
27
27
|
|
|
28
|
-
Alternatively, it can be configured to `opt-in` to validation. In this case, no Rack middleware is used, and controllers can request (opt-in) by including the module `
|
|
28
|
+
Alternatively, it can be configured to `opt-in` to validation. In this case, no Rack middleware is used, and controllers can request (opt-in) by including the module `KeycloakApiRails::authentication` and calling `keycloak_authenticate`, for example in a `before_action`, like so:
|
|
29
29
|
|
|
30
30
|
```ruby
|
|
31
31
|
class MyApiController < ActionController::Base
|
|
32
|
-
include
|
|
32
|
+
include KeycloakApiRails::Authentication
|
|
33
33
|
|
|
34
34
|
before_action :keycloak_authenticate
|
|
35
35
|
end
|
|
@@ -41,7 +41,7 @@ In Rails controller, the request `env` variables has two more properties:
|
|
|
41
41
|
* `keycloak:keycloak_id`
|
|
42
42
|
* `keycloak:roles`
|
|
43
43
|
|
|
44
|
-
They can be accessed using `
|
|
44
|
+
They can be accessed using `KeycloakApiRails::Helper` methods.
|
|
45
45
|
|
|
46
46
|
## Overall configuration options
|
|
47
47
|
|
|
@@ -63,7 +63,7 @@ All options have a default value. However, all of them can be changed in your in
|
|
|
63
63
|
Create a `keycloak.rb` file in your Rails `config/initializers` folder. For instance:
|
|
64
64
|
|
|
65
65
|
```
|
|
66
|
-
|
|
66
|
+
KeycloakApiRails.configure do |config|
|
|
67
67
|
config.server_url = ENV["KEYCLOAK_SERVER_URL"]
|
|
68
68
|
config.realm_id = ENV["KEYCLOAK_REALM_ID"]
|
|
69
69
|
config.logger = Rails.logger
|
|
@@ -77,7 +77,7 @@ end
|
|
|
77
77
|
Or using opt-in configuration:
|
|
78
78
|
|
|
79
79
|
```ruby
|
|
80
|
-
|
|
80
|
+
KeycloakApiRails.configure do |config|
|
|
81
81
|
config.server_url = ENV["KEYCLOAK_SERVER_URL"]
|
|
82
82
|
config.realm_id = ENV["KEYCLOAK_REALM_ID"]
|
|
83
83
|
config.logger = Rails.logger
|
|
@@ -93,13 +93,13 @@ Once this gem is configured in your Rails project, you can read, validate and us
|
|
|
93
93
|
|
|
94
94
|
### Keycloak Id
|
|
95
95
|
|
|
96
|
-
If you identify users using their Keycloak Id, this value can be read from your controllers using `
|
|
96
|
+
If you identify users using their Keycloak Id, this value can be read from your controllers using `KeycloakApiRails::Helper.current_user_id(request.env)`.
|
|
97
97
|
|
|
98
98
|
```ruby
|
|
99
99
|
class AuthenticatedController < ApplicationController
|
|
100
100
|
|
|
101
101
|
def user
|
|
102
|
-
keycloak_id =
|
|
102
|
+
keycloak_id = KeycloakApiRails::Helper.current_user_id(request.env)
|
|
103
103
|
User.active.find_by(keycloak_id: keycloak_id)
|
|
104
104
|
end
|
|
105
105
|
end
|
|
@@ -108,12 +108,12 @@ end
|
|
|
108
108
|
Or if using opt-in mode, the controller can request validation conditionally:
|
|
109
109
|
```ruby
|
|
110
110
|
class MostlyAuthenticatedController < ApplicationController
|
|
111
|
-
include
|
|
111
|
+
include KeycloakApiRails::Authentication
|
|
112
112
|
|
|
113
113
|
before_action :keycloak_authenticate, only: show
|
|
114
114
|
|
|
115
115
|
def show
|
|
116
|
-
keycloak_id =
|
|
116
|
+
keycloak_id = KeycloakApiRails::Helper.current_user_id(request.env)
|
|
117
117
|
User.active.find_by(keycloak_id: keycloak_id)
|
|
118
118
|
end
|
|
119
119
|
|
|
@@ -125,7 +125,7 @@ end
|
|
|
125
125
|
|
|
126
126
|
### Roles
|
|
127
127
|
|
|
128
|
-
`
|
|
128
|
+
`KeycloakApiRails::Helper.current_user_roles` can be use against a Rails request to read user's roles.
|
|
129
129
|
|
|
130
130
|
For example, a controller can require users to be administrator (considering you defined an `application-admin` role):
|
|
131
131
|
|
|
@@ -143,18 +143,18 @@ class AdminController < ApplicationController
|
|
|
143
143
|
private
|
|
144
144
|
|
|
145
145
|
def current_user_roles
|
|
146
|
-
|
|
146
|
+
KeycloakApiRails::Helper.current_user_roles(request.env)
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
### Create an URL where the token must be passed via query string
|
|
152
152
|
|
|
153
|
-
`
|
|
153
|
+
`KeycloakApiRails::Helper.create_url_with_token` method can be used to build an url from another, by adding a token as query string.
|
|
154
154
|
|
|
155
155
|
```ruby
|
|
156
156
|
def example
|
|
157
|
-
|
|
157
|
+
KeycloakApiRails::Helper.create_url_with_token("https://api.pouet.io/api/more-pouets", "myToken")
|
|
158
158
|
end
|
|
159
159
|
```
|
|
160
160
|
|
|
@@ -163,14 +163,14 @@ This should output `https://api.pouet.io/api/more-pouets?authorizationToken=myTo
|
|
|
163
163
|
|
|
164
164
|
### Accessing Keycloak Service
|
|
165
165
|
|
|
166
|
-
A lazy-loaded service
|
|
166
|
+
A lazy-loaded service KeycloakApiRails::Service can be accessed using `KeycloakApiRails.service`.
|
|
167
167
|
For instance, to read a provided token:
|
|
168
168
|
```ruby
|
|
169
169
|
class RenderTokenController < ApplicationController
|
|
170
170
|
def show
|
|
171
171
|
uri = request.env["REQUEST_URI"]
|
|
172
172
|
headers = request.env
|
|
173
|
-
token =
|
|
173
|
+
token = KeycloakApiRails.service.read_token(uri, headers)
|
|
174
174
|
render json: { token: token }, status: :ok
|
|
175
175
|
end
|
|
176
176
|
end
|
|
@@ -200,10 +200,10 @@ let(:jwt) do
|
|
|
200
200
|
token.sign($private_key, :RS256).to_s
|
|
201
201
|
end
|
|
202
202
|
```
|
|
203
|
-
* Finally, in the same `shared_context`, stub `
|
|
203
|
+
* Finally, in the same `shared_context`, stub `KeycloakApiRails.public_key_resolver` to use a valid public key that is able to validate `jwt`:
|
|
204
204
|
```ruby
|
|
205
205
|
before(:each) do
|
|
206
|
-
public_key_resolver =
|
|
206
|
+
public_key_resolver = KeycloakApiRails.public_key_resolver
|
|
207
207
|
allow(public_key_resolver).to receive(:find_public_keys) { JSON::JWK::Set.new(JSON::JWK.new($private_key, kid: "default")) }
|
|
208
208
|
end
|
|
209
209
|
```
|
|
@@ -220,4 +220,4 @@ From the `keycloak-rails-api` directory:
|
|
|
220
220
|
## Next developments
|
|
221
221
|
|
|
222
222
|
* Manage multiple realms
|
|
223
|
-
* Avoid duplicate code in
|
|
223
|
+
* Avoid duplicate code in KeycloakApiRails::Middleware and `KeycloakApiRails::Authentication`
|
data/keycloak-api-rails.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ require "keycloak-api-rails/version"
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "keycloak-api-rails"
|
|
7
|
-
spec.version =
|
|
7
|
+
spec.version = KeycloakApiRails::VERSION
|
|
8
8
|
spec.authors = ["Lorent Lempereur"]
|
|
9
9
|
spec.email = ["lorent.lempereur.dev@gmail.com"]
|
|
10
10
|
spec.homepage = "https://github.com/looorent/keycloak-api-rails"
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.add_dependency "rails", ">= 4.2"
|
|
19
19
|
spec.add_dependency "json-jwt", ">= 1.11.0"
|
|
20
20
|
|
|
21
|
-
spec.add_development_dependency "rspec", "3.
|
|
22
|
-
spec.add_development_dependency "timecop", "0.9.
|
|
23
|
-
spec.add_development_dependency "byebug", "
|
|
21
|
+
spec.add_development_dependency "rspec", "3.13.2"
|
|
22
|
+
spec.add_development_dependency "timecop", "0.9.11"
|
|
23
|
+
spec.add_development_dependency "byebug", "12.0.0"
|
|
24
24
|
end
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
module
|
|
1
|
+
module KeycloakApiRails
|
|
2
2
|
module Authentication
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if respond_to?(:helper_method)
|
|
7
|
-
helper_method :keycloak_authenticate
|
|
3
|
+
def self.included(base)
|
|
4
|
+
if base.respond_to?(:helper_method)
|
|
5
|
+
base.helper_method :keycloak_authenticate
|
|
8
6
|
end
|
|
9
7
|
end
|
|
10
8
|
|
|
@@ -16,16 +14,16 @@ module Keycloak
|
|
|
16
14
|
path = env["PATH_INFO"]
|
|
17
15
|
uri = env["REQUEST_URI"]
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
token =
|
|
21
|
-
decoded_token =
|
|
17
|
+
KeycloakApiRails.logger.debug("Start authentication for #{method} : #{path}")
|
|
18
|
+
token = KeycloakApiRails.service.read_token(uri, env)
|
|
19
|
+
decoded_token = KeycloakApiRails.service.decode_and_verify(token)
|
|
22
20
|
authentication_succeeded(env, decoded_token)
|
|
23
21
|
rescue TokenError => e
|
|
24
22
|
authentication_failed(e.message)
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
def authentication_failed(message)
|
|
28
|
-
|
|
26
|
+
KeycloakApiRails.logger.info(message)
|
|
29
27
|
render status: :unauthorized, json: { error: message }
|
|
30
28
|
end
|
|
31
29
|
|
|
@@ -34,7 +32,7 @@ module Keycloak
|
|
|
34
32
|
Helper.assign_current_authorized_party(env, decoded_token)
|
|
35
33
|
Helper.assign_current_user_email(env, decoded_token)
|
|
36
34
|
Helper.assign_current_user_locale(env, decoded_token)
|
|
37
|
-
Helper.assign_current_user_custom_attributes(env, decoded_token,
|
|
35
|
+
Helper.assign_current_user_custom_attributes(env, decoded_token, KeycloakApiRails.config.custom_attributes)
|
|
38
36
|
Helper.assign_realm_roles(env, decoded_token)
|
|
39
37
|
Helper.assign_resource_roles(env, decoded_token)
|
|
40
38
|
Helper.assign_keycloak_token(env, decoded_token)
|