otp-jwt 0.2.3 → 0.2.4
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/main.workflow +17 -3
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/lib/otp/jwt/active_record.rb +14 -3
- data/lib/otp/jwt/test_helpers.rb +9 -2
- data/lib/otp/jwt/version.rb +1 -1
- data/otp-jwt.gemspec +1 -1
- metadata +6 -7
- data/Gemfile.lock +0 -197
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a6047b41e5b59f65c9a0ab0b138798ba611a113
|
4
|
+
data.tar.gz: 5b157ecb5af5abebcd324f3b18698279af02d050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c9ee97ec926b861d0599462def570ae799ac65a3f59040725b376359de451817680b1a538759126fe698895157813b15a911738c4976dd801cce5d17aa0a562
|
7
|
+
data.tar.gz: d3fede4d63a6121e34fdcad1b8d3c48cd85088e99bfa94b001cf94895ea6574e66e061db7e442a9b4904eb079c7457cd0398d897eaf0085b0d29b50cb3428655
|
data/.github/main.workflow
CHANGED
@@ -2,7 +2,8 @@ workflow "Tests" {
|
|
2
2
|
on = "push"
|
3
3
|
resolves = [
|
4
4
|
"rspec-ruby2.6_rails4",
|
5
|
-
"rspec-ruby2.6_rails5"
|
5
|
+
"rspec-ruby2.6_rails5",
|
6
|
+
"rspec-ruby2.6_rails6"
|
6
7
|
]
|
7
8
|
}
|
8
9
|
|
@@ -10,10 +11,11 @@ action "rspec-ruby2.6_rails4" {
|
|
10
11
|
uses = "docker://ruby:2.6-alpine"
|
11
12
|
env = {
|
12
13
|
RAILS_VERSION = "~> 4"
|
14
|
+
SQLITE3_VERSION = "~> 1.3.6"
|
13
15
|
}
|
14
16
|
args = [
|
15
17
|
"sh", "-c",
|
16
|
-
"apk add -U git build-base sqlite-dev &&
|
18
|
+
"apk add -U git build-base sqlite-dev && bundle install && rake"
|
17
19
|
]
|
18
20
|
}
|
19
21
|
|
@@ -25,6 +27,18 @@ action "rspec-ruby2.6_rails5" {
|
|
25
27
|
}
|
26
28
|
args = [
|
27
29
|
"sh", "-c",
|
28
|
-
"apk add -U git build-base sqlite-dev &&
|
30
|
+
"apk add -U git build-base sqlite-dev && bundle install && rake"
|
31
|
+
]
|
32
|
+
}
|
33
|
+
|
34
|
+
action "rspec-ruby2.6_rails6" {
|
35
|
+
uses = "docker://ruby:2.6-alpine"
|
36
|
+
needs = ["rspec-ruby2.6_rails5"]
|
37
|
+
env = {
|
38
|
+
RAILS_VERSION = "~> 6.0.0.rc1"
|
39
|
+
}
|
40
|
+
args = [
|
41
|
+
"sh", "-c",
|
42
|
+
"apk add -U git build-base sqlite-dev && bundle install && rake"
|
29
43
|
]
|
30
44
|
}
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -14,7 +14,16 @@ module OTP
|
|
14
14
|
# @return [ActiveRecord::Base] model
|
15
15
|
def from_jwt(token, claim_name = 'sub')
|
16
16
|
OTP::JWT::Token.decode(token) do |payload|
|
17
|
-
|
17
|
+
val = payload[claim_name]
|
18
|
+
pk_col = self.column_for_attribute(self.primary_key)
|
19
|
+
|
20
|
+
# Arel casts the values to the primary key type, which means
|
21
|
+
# that an UUID will become an integer...
|
22
|
+
casted_val = self.connection.type_cast(val, pk_col)
|
23
|
+
|
24
|
+
return if casted_val.to_s != val.to_s.strip
|
25
|
+
|
26
|
+
self.find_by(self.primary_key => val)
|
18
27
|
end
|
19
28
|
end
|
20
29
|
end
|
@@ -24,8 +33,10 @@ module OTP
|
|
24
33
|
# @param claims [Hash] extra claims to be included
|
25
34
|
# @return [ActiveRecord::Base] model
|
26
35
|
def to_jwt(claims = nil)
|
27
|
-
|
28
|
-
|
36
|
+
OTP::JWT::Token.sign(
|
37
|
+
sub: self.send(self.class.primary_key),
|
38
|
+
**(claims || {})
|
39
|
+
)
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
data/lib/otp/jwt/test_helpers.rb
CHANGED
@@ -4,16 +4,23 @@ module OTP
|
|
4
4
|
module JWT
|
5
5
|
# Helpers to help you test the [JWT] requests.
|
6
6
|
module TestHelpers
|
7
|
+
# Helper provides JSON content type headers
|
8
|
+
#
|
9
|
+
# @return [Hash] the relevant content type &co
|
10
|
+
def json_headers
|
11
|
+
{ 'Content-Type': Mime[:json].to_s }
|
12
|
+
end
|
13
|
+
|
7
14
|
# Helper to handle authentication requests easier
|
8
15
|
#
|
9
16
|
# @return [Hash] the authorization headers
|
10
17
|
def jwt_auth_header(entity_or_subject)
|
11
|
-
return
|
18
|
+
return json_headers unless entity_or_subject.present?
|
12
19
|
|
13
20
|
token = entity_or_subject.try(:to_jwt)
|
14
21
|
token ||= OTP::JWT::Token.sign(sub: entity_or_subject)
|
15
22
|
|
16
|
-
{ 'Authorization': "Bearer #{token}" }
|
23
|
+
{ 'Authorization': "Bearer #{token}" }.merge(json_headers)
|
17
24
|
end
|
18
25
|
|
19
26
|
# Parses and returns a deserialized JSON
|
data/lib/otp/jwt/version.rb
CHANGED
data/otp-jwt.gemspec
CHANGED
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'rubocop-rails_config'
|
32
32
|
spec.add_development_dependency 'rubocop-rspec'
|
33
33
|
spec.add_development_dependency 'simplecov'
|
34
|
-
spec.add_development_dependency 'sqlite3', '
|
34
|
+
spec.add_development_dependency 'sqlite3', ENV['SQLITE3_VERSION']
|
35
35
|
spec.add_development_dependency 'yardstick'
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otp-jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas Suscov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -168,16 +168,16 @@ dependencies:
|
|
168
168
|
name: sqlite3
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: '0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: yardstick
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,7 +205,6 @@ files:
|
|
205
205
|
- ".rubocop.yml"
|
206
206
|
- ".yardstick.yml"
|
207
207
|
- Gemfile
|
208
|
-
- Gemfile.lock
|
209
208
|
- README.md
|
210
209
|
- Rakefile
|
211
210
|
- lib/otp.rb
|
data/Gemfile.lock
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
otp-jwt (0.2.3)
|
5
|
-
activesupport
|
6
|
-
jwt (~> 2.2.0.pre.beta.0)
|
7
|
-
rotp (~> 4.1)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
actioncable (5.2.3)
|
13
|
-
actionpack (= 5.2.3)
|
14
|
-
nio4r (~> 2.0)
|
15
|
-
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailer (5.2.3)
|
17
|
-
actionpack (= 5.2.3)
|
18
|
-
actionview (= 5.2.3)
|
19
|
-
activejob (= 5.2.3)
|
20
|
-
mail (~> 2.5, >= 2.5.4)
|
21
|
-
rails-dom-testing (~> 2.0)
|
22
|
-
actionpack (5.2.3)
|
23
|
-
actionview (= 5.2.3)
|
24
|
-
activesupport (= 5.2.3)
|
25
|
-
rack (~> 2.0)
|
26
|
-
rack-test (>= 0.6.3)
|
27
|
-
rails-dom-testing (~> 2.0)
|
28
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
29
|
-
actionview (5.2.3)
|
30
|
-
activesupport (= 5.2.3)
|
31
|
-
builder (~> 3.1)
|
32
|
-
erubi (~> 1.4)
|
33
|
-
rails-dom-testing (~> 2.0)
|
34
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
35
|
-
activejob (5.2.3)
|
36
|
-
activesupport (= 5.2.3)
|
37
|
-
globalid (>= 0.3.6)
|
38
|
-
activemodel (5.2.3)
|
39
|
-
activesupport (= 5.2.3)
|
40
|
-
activerecord (5.2.3)
|
41
|
-
activemodel (= 5.2.3)
|
42
|
-
activesupport (= 5.2.3)
|
43
|
-
arel (>= 9.0)
|
44
|
-
activestorage (5.2.3)
|
45
|
-
actionpack (= 5.2.3)
|
46
|
-
activerecord (= 5.2.3)
|
47
|
-
marcel (~> 0.3.1)
|
48
|
-
activesupport (5.2.3)
|
49
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
50
|
-
i18n (>= 0.7, < 2)
|
51
|
-
minitest (~> 5.1)
|
52
|
-
tzinfo (~> 1.1)
|
53
|
-
addressable (2.6.0)
|
54
|
-
public_suffix (>= 2.0.2, < 4.0)
|
55
|
-
arel (9.0.0)
|
56
|
-
ast (2.4.0)
|
57
|
-
builder (3.2.3)
|
58
|
-
concurrent-ruby (1.1.5)
|
59
|
-
crass (1.0.4)
|
60
|
-
diff-lcs (1.3)
|
61
|
-
docile (1.3.1)
|
62
|
-
erubi (1.8.0)
|
63
|
-
ffaker (2.10.0)
|
64
|
-
globalid (0.4.2)
|
65
|
-
activesupport (>= 4.2.0)
|
66
|
-
i18n (1.6.0)
|
67
|
-
concurrent-ruby (~> 1.0)
|
68
|
-
jaro_winkler (1.5.2)
|
69
|
-
json (2.2.0)
|
70
|
-
jwt (2.2.0.pre.beta.0)
|
71
|
-
loofah (2.2.3)
|
72
|
-
crass (~> 1.0.2)
|
73
|
-
nokogiri (>= 1.5.9)
|
74
|
-
mail (2.7.1)
|
75
|
-
mini_mime (>= 0.1.1)
|
76
|
-
marcel (0.3.3)
|
77
|
-
mimemagic (~> 0.3.2)
|
78
|
-
method_source (0.9.2)
|
79
|
-
mimemagic (0.3.3)
|
80
|
-
mini_mime (1.0.1)
|
81
|
-
mini_portile2 (2.4.0)
|
82
|
-
minitest (5.11.3)
|
83
|
-
nio4r (2.3.1)
|
84
|
-
nokogiri (1.10.2)
|
85
|
-
mini_portile2 (~> 2.4.0)
|
86
|
-
parallel (1.16.2)
|
87
|
-
parser (2.6.2.0)
|
88
|
-
ast (~> 2.4.0)
|
89
|
-
psych (3.1.0)
|
90
|
-
public_suffix (3.0.3)
|
91
|
-
rack (2.0.6)
|
92
|
-
rack-test (1.1.0)
|
93
|
-
rack (>= 1.0, < 3)
|
94
|
-
rails (5.2.3)
|
95
|
-
actioncable (= 5.2.3)
|
96
|
-
actionmailer (= 5.2.3)
|
97
|
-
actionpack (= 5.2.3)
|
98
|
-
actionview (= 5.2.3)
|
99
|
-
activejob (= 5.2.3)
|
100
|
-
activemodel (= 5.2.3)
|
101
|
-
activerecord (= 5.2.3)
|
102
|
-
activestorage (= 5.2.3)
|
103
|
-
activesupport (= 5.2.3)
|
104
|
-
bundler (>= 1.3.0)
|
105
|
-
railties (= 5.2.3)
|
106
|
-
sprockets-rails (>= 2.0.0)
|
107
|
-
rails-dom-testing (2.0.3)
|
108
|
-
activesupport (>= 4.2.0)
|
109
|
-
nokogiri (>= 1.6)
|
110
|
-
rails-html-sanitizer (1.0.4)
|
111
|
-
loofah (~> 2.2, >= 2.2.2)
|
112
|
-
railties (5.2.3)
|
113
|
-
actionpack (= 5.2.3)
|
114
|
-
activesupport (= 5.2.3)
|
115
|
-
method_source
|
116
|
-
rake (>= 0.8.7)
|
117
|
-
thor (>= 0.19.0, < 2.0)
|
118
|
-
rainbow (3.0.0)
|
119
|
-
rake (12.3.2)
|
120
|
-
rotp (4.1.0)
|
121
|
-
addressable (~> 2.5)
|
122
|
-
rspec-core (3.8.0)
|
123
|
-
rspec-support (~> 3.8.0)
|
124
|
-
rspec-expectations (3.8.2)
|
125
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
126
|
-
rspec-support (~> 3.8.0)
|
127
|
-
rspec-mocks (3.8.0)
|
128
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
129
|
-
rspec-support (~> 3.8.0)
|
130
|
-
rspec-rails (3.8.2)
|
131
|
-
actionpack (>= 3.0)
|
132
|
-
activesupport (>= 3.0)
|
133
|
-
railties (>= 3.0)
|
134
|
-
rspec-core (~> 3.8.0)
|
135
|
-
rspec-expectations (~> 3.8.0)
|
136
|
-
rspec-mocks (~> 3.8.0)
|
137
|
-
rspec-support (~> 3.8.0)
|
138
|
-
rspec-support (3.8.0)
|
139
|
-
rubocop (0.66.0)
|
140
|
-
jaro_winkler (~> 1.5.1)
|
141
|
-
parallel (~> 1.10)
|
142
|
-
parser (>= 2.5, != 2.5.1.1)
|
143
|
-
psych (>= 3.1.0)
|
144
|
-
rainbow (>= 2.2.2, < 4.0)
|
145
|
-
ruby-progressbar (~> 1.7)
|
146
|
-
unicode-display_width (>= 1.4.0, < 1.6)
|
147
|
-
rubocop-performance (1.0.0)
|
148
|
-
rubocop (>= 0.58.0)
|
149
|
-
rubocop-rails_config (0.4.4)
|
150
|
-
railties (>= 3.0)
|
151
|
-
rubocop (~> 0.58)
|
152
|
-
rubocop-rspec (1.32.0)
|
153
|
-
rubocop (>= 0.60.0)
|
154
|
-
ruby-progressbar (1.10.0)
|
155
|
-
simplecov (0.16.1)
|
156
|
-
docile (~> 1.1)
|
157
|
-
json (>= 1.8, < 3)
|
158
|
-
simplecov-html (~> 0.10.0)
|
159
|
-
simplecov-html (0.10.2)
|
160
|
-
sprockets (3.7.2)
|
161
|
-
concurrent-ruby (~> 1.0)
|
162
|
-
rack (> 1, < 3)
|
163
|
-
sprockets-rails (3.2.1)
|
164
|
-
actionpack (>= 4.0)
|
165
|
-
activesupport (>= 4.0)
|
166
|
-
sprockets (>= 3.0.0)
|
167
|
-
sqlite3 (1.3.13)
|
168
|
-
thor (0.20.3)
|
169
|
-
thread_safe (0.3.6)
|
170
|
-
tzinfo (1.2.5)
|
171
|
-
thread_safe (~> 0.1)
|
172
|
-
unicode-display_width (1.5.0)
|
173
|
-
websocket-driver (0.7.0)
|
174
|
-
websocket-extensions (>= 0.1.0)
|
175
|
-
websocket-extensions (0.1.3)
|
176
|
-
yard (0.9.18)
|
177
|
-
yardstick (0.9.9)
|
178
|
-
yard (~> 0.8, >= 0.8.7.2)
|
179
|
-
|
180
|
-
PLATFORMS
|
181
|
-
ruby
|
182
|
-
|
183
|
-
DEPENDENCIES
|
184
|
-
bundler
|
185
|
-
ffaker
|
186
|
-
otp-jwt!
|
187
|
-
rails
|
188
|
-
rspec-rails
|
189
|
-
rubocop-performance
|
190
|
-
rubocop-rails_config
|
191
|
-
rubocop-rspec
|
192
|
-
simplecov
|
193
|
-
sqlite3 (~> 1.3.6)
|
194
|
-
yardstick
|
195
|
-
|
196
|
-
BUNDLED WITH
|
197
|
-
1.17.3
|