researchable_jwt-authenticable 1.1.0 → 1.2.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/CHANGELOG.md +14 -0
- data/Gemfile.lock +5 -10
- data/README.md +18 -0
- data/lib/jwt_authenticable/auth.rb +11 -6
- data/lib/jwt_authenticable/version.rb +1 -1
- data/lib/jwt_authenticable.rb +1 -1
- data/node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb +1 -1
- data/sig/jwt_authenticable.rbs +1 -0
- metadata +12 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6779a8f7597e46e6d8fd58f2c4ee4fb50412377722fec09112f54f29e0356567
|
|
4
|
+
data.tar.gz: 87edc735717c5fe7fffd7bd7dd1a6eccdef1461035b98b6402d616773d8f6969
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b53d00ed3d314492f326274efd6f7b0a67f5dcc1d27d9c52a2c33bdec096d868bc507728cbb48b2507cf12884798db5e3d1ea2dd359af67329766225586b437
|
|
7
|
+
data.tar.gz: e1cacbadcfcae8ceff9cfc733ee1e4f023b70735329d671dd9c2beefafaff7f6431ed2a58d6a01335129181a16e11e1af0c2d001f781657993d6f2ad2ffabf8c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.2.1](https://gitlab.com/researchable/general/gems/jwt-authenticable/compare/v1.2.0...v1.2.1) (2026-08-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* allow jwt 3.x by loosening the gemspec constraint ([bceed30](https://gitlab.com/researchable/general/gems/jwt-authenticable/commit/bceed30caaaeb734cc4a9c23da50457dd338660a))
|
|
7
|
+
|
|
8
|
+
# [1.2.0](https://gitlab.com/researchable/general/gems/jwt-authenticable/compare/v1.1.0...v1.2.0) (2023-10-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* allow skipping 2fa ([541de8a](https://gitlab.com/researchable/general/gems/jwt-authenticable/commit/541de8a7ac4cc2029c00b44f30dde2486b4dfb06))
|
|
14
|
+
|
|
1
15
|
# [1.1.0](https://gitlab.com/researchable/general/gems/jwt-authenticable/compare/v1.0.1...v1.1.0) (2023-06-30)
|
|
2
16
|
|
|
3
17
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
researchable_jwt-authenticable (1.
|
|
4
|
+
researchable_jwt-authenticable (1.2.0)
|
|
5
5
|
dry-configurable (~> 0.16)
|
|
6
|
-
jwt (
|
|
6
|
+
jwt (>= 2.6, < 4)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
@@ -14,11 +14,9 @@ GEM
|
|
|
14
14
|
minitest (>= 5.1)
|
|
15
15
|
tzinfo (~> 2.0)
|
|
16
16
|
ast (2.4.2)
|
|
17
|
+
base64 (0.3.0)
|
|
17
18
|
byebug (11.1.3)
|
|
18
19
|
concurrent-ruby (1.2.2)
|
|
19
|
-
debase (0.2.5.beta2)
|
|
20
|
-
debase-ruby_core_source (>= 0.10.12)
|
|
21
|
-
debase-ruby_core_source (3.2.1)
|
|
22
20
|
diff-lcs (1.5.0)
|
|
23
21
|
dry-configurable (0.16.1)
|
|
24
22
|
dry-core (~> 0.6)
|
|
@@ -28,7 +26,8 @@ GEM
|
|
|
28
26
|
zeitwerk (~> 2.6)
|
|
29
27
|
i18n (1.12.0)
|
|
30
28
|
concurrent-ruby (~> 1.0)
|
|
31
|
-
jwt (2.
|
|
29
|
+
jwt (3.2.0)
|
|
30
|
+
base64
|
|
32
31
|
minitest (5.18.0)
|
|
33
32
|
parallel (1.22.1)
|
|
34
33
|
parser (3.2.1.1)
|
|
@@ -79,8 +78,6 @@ GEM
|
|
|
79
78
|
rubocop-rails (= 2.12.4)
|
|
80
79
|
rubocop-rake (= 0.6.0)
|
|
81
80
|
rubocop-rspec (= 2.6.0)
|
|
82
|
-
ruby-debug-ide (0.7.3)
|
|
83
|
-
rake (>= 0.8.1)
|
|
84
81
|
ruby-progressbar (1.13.0)
|
|
85
82
|
tzinfo (2.0.6)
|
|
86
83
|
concurrent-ruby (~> 1.0)
|
|
@@ -92,12 +89,10 @@ PLATFORMS
|
|
|
92
89
|
|
|
93
90
|
DEPENDENCIES
|
|
94
91
|
byebug
|
|
95
|
-
debase
|
|
96
92
|
rake (~> 13.0)
|
|
97
93
|
researchable_jwt-authenticable!
|
|
98
94
|
rspec (~> 3.0)
|
|
99
95
|
ruboguide (~> 1.0)
|
|
100
|
-
ruby-debug-ide
|
|
101
96
|
|
|
102
97
|
BUNDLED WITH
|
|
103
98
|
2.4.6
|
data/README.md
CHANGED
|
@@ -46,6 +46,24 @@ class ApplicationController < ActionController::API
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
```
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
This gem works with `jwt` 2.6 or newer, including `jwt` 3.x.
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
JwtAuthenticable.configure do |config|
|
|
56
|
+
# One of HS256, HS384, HS512, RS256, RS384 or RS512. Anything else falls back to HS256.
|
|
57
|
+
config.algorithm = 'HS256'
|
|
58
|
+
|
|
59
|
+
# The shared secret, or for the RS* algorithms the public key used to verify the signature.
|
|
60
|
+
config.jwt_secret_key = ENV.fetch('JWT_SECRET_KEY', nil)
|
|
61
|
+
|
|
62
|
+
# When true, a token is only considered valid if it carries a truthy `2fa` claim.
|
|
63
|
+
config.enforce_2fa = false
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
49
67
|
## Development
|
|
50
68
|
|
|
51
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -11,28 +11,33 @@ module JwtAuthenticable
|
|
|
11
11
|
|
|
12
12
|
# Authenticates a user.
|
|
13
13
|
# @raise MissingAuthScope if the jwt does not have the right scope
|
|
14
|
-
def authenticate_user!
|
|
15
|
-
validate_jwt_token! token: authorization_token
|
|
14
|
+
def authenticate_user!(skip_2fa: false)
|
|
15
|
+
validate_jwt_token! token: authorization_token!, skip_2fa: skip_2fa
|
|
16
16
|
rescue MissingAuth, MissingAuthScope, InvalidAuthScheme, TwoFANotEnabledError, JWT::VerificationError,
|
|
17
17
|
JWT::ExpiredSignature => e
|
|
18
18
|
unauthorized(e.message)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def authenticate_user_without_2fa!
|
|
22
|
+
authenticate_user!(skip_2fa: true)
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
# Consider any method below as private and not meant to be used by including classes
|
|
22
26
|
|
|
23
27
|
# Validate that the JWT token signature and the following claims are valid:
|
|
24
28
|
# - exp
|
|
25
29
|
# - scope
|
|
26
30
|
# @param token [String] JWT token string (just the token, with the header, payload and signature separated by '.')
|
|
27
|
-
# @param
|
|
31
|
+
# @param skip_2fa [Boolean] When set to true it will not raise a TwoFANotEnabledError if the jwt payload does not
|
|
32
|
+
# contain the 2fa claim.
|
|
28
33
|
# @raise AuthorizationError if the user is trying to login with the incorrect rights.
|
|
29
34
|
# @return [Hash] the JWT payload
|
|
30
|
-
def validate_jwt_token!(token:)
|
|
35
|
+
def validate_jwt_token!(token:, skip_2fa: false)
|
|
31
36
|
# NOTE: it is still safe if JWT_SECRET_KEY is not set. The method will trigger a JWT exception
|
|
32
37
|
payload = JWT.decode(token, JwtAuthenticable.config.jwt_secret_key, true,
|
|
33
38
|
{ algorithm: algorithm }).first
|
|
34
39
|
|
|
35
|
-
raise TwoFANotEnabledError if JwtAuthenticable.config.enforce_2fa && !payload['2fa']
|
|
40
|
+
raise TwoFANotEnabledError if JwtAuthenticable.config.enforce_2fa && !payload['2fa'] && !skip_2fa
|
|
36
41
|
|
|
37
42
|
payload
|
|
38
43
|
end
|
|
@@ -59,7 +64,7 @@ module JwtAuthenticable
|
|
|
59
64
|
end
|
|
60
65
|
|
|
61
66
|
def supported_algos
|
|
62
|
-
SUPPORTED_ALGOS
|
|
67
|
+
SUPPORTED_ALGOS
|
|
63
68
|
end
|
|
64
69
|
end
|
|
65
70
|
end
|
data/lib/jwt_authenticable.rb
CHANGED
|
@@ -14,7 +14,7 @@ module JwtAuthenticable
|
|
|
14
14
|
# If set to true, a jwt will only be considered valid if 2fa has been enabled
|
|
15
15
|
setting :enforce_2fa, default: false
|
|
16
16
|
|
|
17
|
-
SUPPORTED_ALGOS = [
|
|
17
|
+
SUPPORTED_ALGOS = %w[HS256 HS384 HS512 RS256 RS384 RS512].freeze
|
|
18
18
|
|
|
19
19
|
class Error < StandardError; end
|
|
20
20
|
end
|
data/sig/jwt_authenticable.rbs
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: researchable_jwt-authenticable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Researchable
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: dry-configurable
|
|
@@ -28,16 +27,22 @@ dependencies:
|
|
|
28
27
|
name: jwt
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - ">="
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
32
|
version: '2.6'
|
|
33
|
+
- - "<"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '4'
|
|
34
36
|
type: :runtime
|
|
35
37
|
prerelease: false
|
|
36
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
39
|
requirements:
|
|
38
|
-
- - "
|
|
40
|
+
- - ">="
|
|
39
41
|
- !ruby/object:Gem::Version
|
|
40
42
|
version: '2.6'
|
|
43
|
+
- - "<"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '4'
|
|
41
46
|
description: " Researchable's JwtAuthenticable relies on Json Web Tokens to deal
|
|
42
47
|
with authentication.\n"
|
|
43
48
|
email:
|
|
@@ -67,12 +72,11 @@ files:
|
|
|
67
72
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/prerelease/lib/test-gem/version.rb
|
|
68
73
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb
|
|
69
74
|
- sig/jwt_authenticable.rbs
|
|
70
|
-
homepage: https://gitlab.com/researchable/general/gems/jwt-authenticable/-/blob/v1.1
|
|
75
|
+
homepage: https://gitlab.com/researchable/general/gems/jwt-authenticable/-/blob/v1.2.1/README.md
|
|
71
76
|
licenses:
|
|
72
77
|
- MIT
|
|
73
78
|
metadata:
|
|
74
79
|
rubygems_mfa_required: 'true'
|
|
75
|
-
post_install_message:
|
|
76
80
|
rdoc_options: []
|
|
77
81
|
require_paths:
|
|
78
82
|
- lib
|
|
@@ -87,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
91
|
- !ruby/object:Gem::Version
|
|
88
92
|
version: '0'
|
|
89
93
|
requirements: []
|
|
90
|
-
rubygems_version: 3.
|
|
91
|
-
signing_key:
|
|
94
|
+
rubygems_version: 3.6.9
|
|
92
95
|
specification_version: 4
|
|
93
96
|
summary: Researchable's gem to deal with JWT authentication
|
|
94
97
|
test_files: []
|