rodauth-oauth 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -2
- data/LICENSE.txt +191 -0
- data/README.md +145 -13
- data/lib/generators/roda/oauth/install_generator.rb +1 -1
- data/lib/generators/roda/oauth/views_generator.rb +1 -6
- data/lib/rodauth/features/oauth.rb +148 -96
- data/lib/rodauth/features/oauth_http_mac.rb +111 -0
- data/lib/rodauth/features/oauth_jwt.rb +228 -0
- data/lib/rodauth/oauth/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec27cf0fcac2e93b6ba08d76a4fa3e165c55722864d87fb78e4f0fc70a15c759
|
4
|
+
data.tar.gz: 535f0b61b987f38179de2d7011b55d8b9b6e12bdf1293c9da7534c063277c2f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1179a1e5db37dbfdc9932a6ec74fb3fba37c7c863c0ec643f9b1c11fee8ef8b8bf71d0705bb9629135f517dbb3d49dd5e7609014ddc3aae28ad4bd0f45981a1
|
7
|
+
data.tar.gz: ebc711bc991746fbfa780f81a91c92508c55eca65e3e316a1fc4b23b6e9141f0d97a8871ce12527fdeaf71234d97ddfa0c712aca870c65f73ab89a11fe40839e
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,39 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
-
## 0.0.
|
5
|
+
## 0.0.3 (5/6/2020)
|
6
|
+
|
7
|
+
### Features
|
8
|
+
|
9
|
+
#### `:oauth_http_mac`
|
10
|
+
|
11
|
+
A new feature builds on top of `:oauth` to allow MAC authorization.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
plugin :rodauth do
|
15
|
+
enable :oauth_http_mac
|
16
|
+
# options here...
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
#### `:oauth_jwt`
|
21
|
+
|
22
|
+
Another new feature, this time supporting the generation of JWT access tokens.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
plugin :rodauth do
|
26
|
+
enable :oauth_jwt
|
27
|
+
# options here...
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### Improvements
|
32
|
+
|
33
|
+
* added options for disabling pkce and access type (respectively, `use_oauth_pkce?` and `use_oauth_access_type?`);
|
34
|
+
* renamed the existing `use_oauth_implicit_grant_type` to `use_oauth_implicit_grant_type?`;
|
35
|
+
* It's now usable as JSON API (small caveat: POST authorize will still redirect on success...);
|
36
|
+
|
37
|
+
## 0.0.2 (29/5/2020)
|
6
38
|
|
7
39
|
### Features
|
8
40
|
|
@@ -18,6 +50,6 @@
|
|
18
50
|
|
19
51
|
* usage of client secret for authorizing the generation of tokens, as the spec mandates (and refraining from them when doing PKCE).
|
20
52
|
|
21
|
-
## 0.0.1
|
53
|
+
## 0.0.1 (14/5/2020)
|
22
54
|
|
23
55
|
Initial implementation of the Oauth 2.0 framework, with an example app done using roda.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
https://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
Copyright 2013-2017 Docker, Inc.
|
180
|
+
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
182
|
+
you may not use this file except in compliance with the License.
|
183
|
+
You may obtain a copy of the License at
|
184
|
+
|
185
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
186
|
+
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
190
|
+
See the License for the specific language governing permissions and
|
191
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -13,13 +13,14 @@ This gem implements:
|
|
13
13
|
* [Authorization grant flow](https://tools.ietf.org/html/rfc6749#section-1.3);
|
14
14
|
* [Access Token generation](https://tools.ietf.org/html/rfc6749#section-1.4);
|
15
15
|
* [Access Token refresh](https://tools.ietf.org/html/rfc6749#section-1.5);
|
16
|
-
* [Token revocation](https://tools.ietf.org/html/rfc7009);
|
17
16
|
* [Implicit grant (off by default)[https://tools.ietf.org/html/rfc6749#section-4.2];
|
18
|
-
|
17
|
+
* [Token revocation](https://tools.ietf.org/html/rfc7009);
|
18
|
+
* [PKCE](https://tools.ietf.org/html/rfc7636);
|
19
19
|
* Access Type (Token refresh online and offline);
|
20
|
+
* [MAC Authentication Scheme](https://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token-02);
|
21
|
+
* [JWT Acess Tokens](https://tools.ietf.org/html/draft-ietf-oauth-access-token-jwt-07);
|
20
22
|
* OAuth application and token management dashboards;
|
21
23
|
|
22
|
-
|
23
24
|
This gem supports also rails (through [rodauth-rails]((https://github.com/janko/rodauth-rails))).
|
24
25
|
|
25
26
|
|
@@ -105,7 +106,7 @@ response = HTTPX.post("https://auth_server/oauth-token",json: {
|
|
105
106
|
})
|
106
107
|
response.raise_for_status
|
107
108
|
payload = JSON.parse(response.to_s)
|
108
|
-
puts payload #=> {"
|
109
|
+
puts payload #=> {"access_token" => "awr23f3h8f9d2h89...", "refresh_token" => "23fkop3kr290kc..." ....
|
109
110
|
```
|
110
111
|
|
111
112
|
##### cURL
|
@@ -130,7 +131,7 @@ response = HTTPX.post("https://auth_server/oauth-token",json: {
|
|
130
131
|
})
|
131
132
|
response.raise_for_status
|
132
133
|
payload = JSON.parse(response.to_s)
|
133
|
-
puts payload #=> {"
|
134
|
+
puts payload #=> {"access_token" => "awr23f3h8f9d2h89...", "token_type" => "Bearer" ....
|
134
135
|
```
|
135
136
|
|
136
137
|
##### cURL
|
@@ -154,7 +155,7 @@ response = httpx.with(headers: { "X-your-auth-scheme" => ENV["SERVER_KEY"] })
|
|
154
155
|
})
|
155
156
|
response.raise_for_status
|
156
157
|
payload = JSON.parse(response.to_s)
|
157
|
-
puts payload #=> {"
|
158
|
+
puts payload #=> {"access_token" => "awr23f3h8f9d2h89...", "token_type" => "Bearer" ....
|
158
159
|
```
|
159
160
|
|
160
161
|
##### cURL
|
@@ -337,13 +338,21 @@ This will only work **if there was a previous successful online grant** for the
|
|
337
338
|
|
338
339
|
#### DB schema
|
339
340
|
|
340
|
-
the "oauth_grants" table will have to include the "access_type row
|
341
|
+
the "oauth_grants" table will have to include the "access_type" row:
|
341
342
|
|
342
343
|
```ruby
|
343
344
|
# in migration
|
344
345
|
String :access_type, null: false, default: "offline"
|
345
346
|
```
|
346
347
|
|
348
|
+
If you want to disable this flow altogether, you can:
|
349
|
+
|
350
|
+
```ruby
|
351
|
+
enable :oauth
|
352
|
+
use_oauth_access_type? false
|
353
|
+
```
|
354
|
+
|
355
|
+
|
347
356
|
### Implicit Grant (default: disabled)
|
348
357
|
|
349
358
|
The implicit grant flow is part of the original OAuth 2.0 RFC, however, if you care about security, you are **strongly recommended** not to enable it.
|
@@ -366,9 +375,7 @@ The "Proof Key for Code Exchange by OAuth Public Clients" (aka PKCE) flow, which
|
|
366
375
|
```ruby
|
367
376
|
# with httpx
|
368
377
|
require "httpx"
|
369
|
-
|
370
|
-
response = httpx.with(headers: { "X-your-auth-scheme" => ENV["SERVER_KEY"] })
|
371
|
-
.post("https://auth_server/oauth-token",json: {
|
378
|
+
response = HTTPX.post("https://auth_server/oauth-token",json: {
|
372
379
|
client_id: ENV["OAUTH_CLIENT_ID"],
|
373
380
|
grant_type: "authorization_code",
|
374
381
|
code: "oiweicnewdh32fhoi3hf3ihfo2ih3f2o3as",
|
@@ -376,7 +383,7 @@ response = httpx.with(headers: { "X-your-auth-scheme" => ENV["SERVER_KEY"] })
|
|
376
383
|
})
|
377
384
|
response.raise_for_status
|
378
385
|
payload = JSON.parse(response.to_s)
|
379
|
-
puts payload #=> {"
|
386
|
+
puts payload #=> {"access_token" => ....
|
380
387
|
```
|
381
388
|
|
382
389
|
By default, the pkce integration sets "S256" as the default challenge method. If you value security, you **should not use plain**. However, if you really need to, you can set it in the `rodauth` plugin:
|
@@ -397,13 +404,138 @@ plugin :rodauth do
|
|
397
404
|
end
|
398
405
|
```
|
399
406
|
|
407
|
+
If you want, on the other hand. to disable this flow altogether, you can:
|
408
|
+
|
409
|
+
```ruby
|
410
|
+
enable :oauth
|
411
|
+
use_oauth_pkce? false
|
412
|
+
```
|
413
|
+
|
414
|
+
### HTTP Mac Authentication
|
415
|
+
|
416
|
+
You can enable HTTP MAC authentication like this:
|
417
|
+
|
418
|
+
```ruby
|
419
|
+
plugin :rodauth do
|
420
|
+
enable :oauth_http_mac
|
421
|
+
end
|
422
|
+
```
|
423
|
+
|
424
|
+
Generating an access token will deliver the following fields:
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
# with httpx
|
428
|
+
require "httpx"
|
429
|
+
response = httpx.post("https://auth_server/oauth-token",json: {
|
430
|
+
client_id: ENV["OAUTH_CLIENT_ID"],
|
431
|
+
client_secret: ENV["OAUTH_CLIENT_SECRET"],
|
432
|
+
grant_type: "authorization_code",
|
433
|
+
code: "oiweicnewdh32fhoi3hf3ihfo2ih3f2o3as"
|
434
|
+
})
|
435
|
+
response.raise_for_status
|
436
|
+
payload = JSON.parse(response.to_s)
|
437
|
+
puts payload #=> {
|
438
|
+
# "access_token" => ....
|
439
|
+
# "mac_key" => ....
|
440
|
+
# "mac_algorithm" =>
|
441
|
+
```
|
442
|
+
|
443
|
+
which you'll be able to use to generate the mac signature to send in the "Authorization" header.
|
444
|
+
|
445
|
+
#### DB schema
|
446
|
+
|
447
|
+
the "oauth_tokens" table will have to include a column for the mac key:
|
448
|
+
|
449
|
+
```ruby
|
450
|
+
# in migration
|
451
|
+
String :mac_key, token: true
|
452
|
+
```
|
453
|
+
|
454
|
+
|
455
|
+
### JWT Access Tokens
|
456
|
+
|
457
|
+
JWT Acess Tokens are great to avoid DB lookups when validation the authorization token. Quoting the RFC, *The approach is particularly common in topologies where the authorization server and resource server are not co-located, are not run by the same entity, or are otherwise separated by some boundary.*
|
458
|
+
|
459
|
+
You can enable JWT Access tokens by doing:
|
460
|
+
|
461
|
+
```ruby
|
462
|
+
plugin :rodauth do
|
463
|
+
enable :oauth_jwt
|
464
|
+
end
|
465
|
+
```
|
466
|
+
|
467
|
+
This will, by default, use the OAuth application as HMAC signature and "HS256" as the algorithm to sign the resulting JWT access tokens. You can tweak those features by editing the following options:
|
468
|
+
|
469
|
+
```ruby
|
470
|
+
enable :oauth_jwt
|
471
|
+
oauth_jwt_secret "SECRET"
|
472
|
+
# or oauth_jwt_secret_path "path/to/file"
|
473
|
+
oauth_jwt_algorithm "HS512"
|
474
|
+
```
|
475
|
+
|
476
|
+
You can look for other options in [the jwt gem documentation](https://github.com/jwt/ruby-jwt), as this is used under the hood.
|
477
|
+
|
478
|
+
#### Pub/Priv key
|
479
|
+
|
480
|
+
You can decide to keep a private key to encode the JWT token, while other clients hace the public key to decode it. You can then do it like:
|
481
|
+
|
482
|
+
```ruby
|
483
|
+
rsa_private = OpenSSL::PKey::RSA.generate 2048
|
484
|
+
rsa_public = rsa_private.public_key
|
485
|
+
|
486
|
+
plugin :rodauth do
|
487
|
+
enable :oauth_jwt
|
488
|
+
oauth_jwt_key rsa_private
|
489
|
+
oauth_jwt_decoding_secret rsa_public
|
490
|
+
oauth_jwt_algorithm "RS256"
|
491
|
+
end
|
492
|
+
```
|
493
|
+
|
494
|
+
#### JWK
|
495
|
+
|
496
|
+
One can further encode the JWT token using JSON Web Keys. Here's how you could enable the feature:
|
497
|
+
|
498
|
+
```ruby
|
499
|
+
plugin :rodauth do
|
500
|
+
enable :oauth_jwt
|
501
|
+
oauth_jwt_jwk_key 2048 # can be key size or the encoded RSA key, which is the only one supported now.
|
502
|
+
# oauth_jwt_jwk_key "path/to/rsa.pem" if you prefer
|
503
|
+
end
|
504
|
+
```
|
505
|
+
|
506
|
+
#### JWE
|
507
|
+
|
508
|
+
You can further instruct the jwt feature to encrypt the encoded token using JSON Web Encryption standard:
|
509
|
+
|
510
|
+
```ruby
|
511
|
+
jwe_key = OpenSSL::PKey::RSA.new(2048)
|
512
|
+
|
513
|
+
plugin :rodauth do
|
514
|
+
oauth_jwt_secret "SECRET"
|
515
|
+
oauth_jwt_algorithm "HS256"
|
516
|
+
oauth_jwt_jwe_key jwe_key
|
517
|
+
oauth_jwt_jwe_encryption_method "A192GCM"
|
518
|
+
end
|
519
|
+
```
|
520
|
+
|
521
|
+
which adds an extra layer of protection.
|
522
|
+
|
523
|
+
|
524
|
+
#### DB Schema
|
525
|
+
|
526
|
+
You'll still need the "oauth_tokens" table, however you can remove the "token" column.
|
527
|
+
|
528
|
+
#### Caveats
|
529
|
+
|
530
|
+
Although very handy for the mentioned use case, one can't revoke a JWT token on demand (it must expire first).
|
531
|
+
|
400
532
|
## Ruby support policy
|
401
533
|
|
402
|
-
The minimum Ruby version required to run `rodauth-oauth` is 2.3 . Besides that, it should support all rubies that rodauth and roda support.
|
534
|
+
The minimum Ruby version required to run `rodauth-oauth` is 2.3 . Besides that, it should support all rubies that rodauth and roda support, including JRuby and (potentially, I don't know yet) truffleruby.
|
403
535
|
|
404
536
|
### JRuby
|
405
537
|
|
406
|
-
If you're interested in using this library in rails, be
|
538
|
+
If you're interested in using this library in rails, be sure to check `rodauth-rails` policy, as it supports rails 5.2 upwards.
|
407
539
|
|
408
540
|
## Development
|
409
541
|
|