json-jwt 1.0.3 → 1.1.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.
Potentially problematic release.
This version of json-jwt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/json/jws.rb +21 -0
- data/spec/json/jws_spec.rb +57 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a67d827d688275c320f167da344b09c410389ae9
|
4
|
+
data.tar.gz: 86de0fee6cdab321509cb679c977c5c3654517c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fd02d0b56b9fe92afc6300d8a7074a71fdf346264af52488b389b685100342fac4eea8485c5d4e0be68b8752049f6089a8b5ba05509d9f33d4116663705c8ed
|
7
|
+
data.tar.gz: ed5ee926666db5e52ca85ed60973321cf5042366c9484aa12e4c8cd37a6d3503a2c514b7699f99e6d1828e10202c2e1ff02f5d529dd9b3be880a6c24b3487bad
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/json/jws.rb
CHANGED
@@ -21,6 +21,27 @@ module JSON
|
|
21
21
|
raise VerificationFailed
|
22
22
|
end
|
23
23
|
|
24
|
+
def as_json(options = {})
|
25
|
+
case options[:syntax]
|
26
|
+
when :general
|
27
|
+
{
|
28
|
+
payload: UrlSafeBase64.encode64(self.to_json),
|
29
|
+
signatures: {
|
30
|
+
protected: UrlSafeBase64.encode64(header.to_json),
|
31
|
+
signature: UrlSafeBase64.encode64(signature.to_s)
|
32
|
+
}
|
33
|
+
}
|
34
|
+
when :flattened
|
35
|
+
{
|
36
|
+
protected: UrlSafeBase64.encode64(header.to_json),
|
37
|
+
payload: UrlSafeBase64.encode64(self.to_json),
|
38
|
+
signature: UrlSafeBase64.encode64(signature.to_s)
|
39
|
+
}
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
24
45
|
private
|
25
46
|
|
26
47
|
def digest
|
data/spec/json/jws_spec.rb
CHANGED
@@ -158,4 +158,61 @@ describe JSON::JWS do
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
161
|
+
|
162
|
+
describe 'to_json' do
|
163
|
+
let(:alg) { :RS256 }
|
164
|
+
let(:private_key_or_secret) { private_key }
|
165
|
+
|
166
|
+
context 'as default' do
|
167
|
+
it 'should JSONize payload' do
|
168
|
+
jws.to_json.should == claims.to_json
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when syntax option given' do
|
173
|
+
context 'when general' do
|
174
|
+
it 'should return General JWS JSON Serialization' do
|
175
|
+
signed.to_json(syntax: :general).should == {
|
176
|
+
payload: UrlSafeBase64.encode64(claims.to_json),
|
177
|
+
signatures: {
|
178
|
+
protected: UrlSafeBase64.encode64(signed.header.to_json),
|
179
|
+
signature: UrlSafeBase64.encode64(signed.signature)
|
180
|
+
}
|
181
|
+
}.to_json
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when not signed yet' do
|
185
|
+
it 'should not fail' do
|
186
|
+
jws.to_json(syntax: :general).should == {
|
187
|
+
payload: UrlSafeBase64.encode64(claims.to_json),
|
188
|
+
signatures: {
|
189
|
+
protected: UrlSafeBase64.encode64(jws.header.to_json),
|
190
|
+
signature: UrlSafeBase64.encode64('')
|
191
|
+
}
|
192
|
+
}.to_json
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when flattened' do
|
198
|
+
it 'should return Flattened JWS JSON Serialization' do
|
199
|
+
signed.to_json(syntax: :flattened).should == {
|
200
|
+
protected: UrlSafeBase64.encode64(signed.header.to_json),
|
201
|
+
payload: UrlSafeBase64.encode64(claims.to_json),
|
202
|
+
signature: UrlSafeBase64.encode64(signed.signature)
|
203
|
+
}.to_json
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when not signed yet' do
|
207
|
+
it 'should not fail' do
|
208
|
+
jws.to_json(syntax: :flattened).should == {
|
209
|
+
protected: UrlSafeBase64.encode64(jws.header.to_json),
|
210
|
+
payload: UrlSafeBase64.encode64(claims.to_json),
|
211
|
+
signature: UrlSafeBase64.encode64('')
|
212
|
+
}.to_json
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
161
218
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov matake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|