jwt 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +1 -1
- data/jwt.gemspec +7 -6
- data/lib/jwt.rb +12 -2
- data/spec/jwt_spec.rb +31 -5
- metadata +14 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fee3225d7739e1ab161dc39347ac2a20798f8fde
|
4
|
+
data.tar.gz: 979eb55ee5a17bba062741a6024d11000b45d7fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 423bb31cbe9140a3f8d627f87b8131d36d980e9d70dd844a5876a4d91665f145f9e8ac43d5f77f975e180d23387366473c3bc9ff70f31d466e7c3edfd97cdde4
|
7
|
+
data.tar.gz: ec9d3d47e5e877a8f8b03b2447611b2a1f23c863624827dfa7832bebae40ffcaaff8173da23f10df0a9660fda36ebf7980e306eb3b891091dc31423eea39e6a2
|
data/Rakefile
CHANGED
data/jwt.gemspec
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: jwt 1.2.0 ruby lib
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
5
|
s.name = "jwt"
|
5
|
-
s.version = "1.
|
6
|
+
s.version = "1.2.0"
|
6
7
|
|
7
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
8
10
|
s.authors = ["Jeff Lindsay"]
|
9
|
-
s.date = "2014-
|
11
|
+
s.date = "2014-11-24"
|
10
12
|
s.description = "JSON Web Token implementation in Ruby"
|
11
13
|
s.email = "progrium@gmail.com"
|
12
14
|
s.extra_rdoc_files = ["lib/jwt.rb", "lib/jwt/json.rb"]
|
13
|
-
s.files = ["Rakefile", "lib/jwt.rb", "lib/jwt/json.rb", "spec/helper.rb", "spec/jwt_spec.rb"
|
15
|
+
s.files = ["Manifest", "Rakefile", "jwt.gemspec", "lib/jwt.rb", "lib/jwt/json.rb", "spec/helper.rb", "spec/jwt_spec.rb"]
|
14
16
|
s.homepage = "http://github.com/progrium/ruby-jwt"
|
15
17
|
s.licenses = ["MIT"]
|
16
18
|
s.rdoc_options = ["--line-numbers", "--title", "Jwt", "--main", "README.md"]
|
17
|
-
s.require_paths = ["lib"]
|
18
19
|
s.rubyforge_project = "jwt"
|
19
|
-
s.rubygems_version = "
|
20
|
+
s.rubygems_version = "2.3.0"
|
20
21
|
s.summary = "JSON Web Token implementation in Ruby"
|
21
22
|
|
22
23
|
if s.respond_to? :specification_version then
|
23
|
-
s.specification_version =
|
24
|
+
s.specification_version = 4
|
24
25
|
|
25
26
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
27
|
s.add_development_dependency(%q<echoe>, [">= 4.6.3"])
|
data/lib/jwt.rb
CHANGED
@@ -10,6 +10,7 @@ require "jwt/json"
|
|
10
10
|
|
11
11
|
module JWT
|
12
12
|
class DecodeError < StandardError; end
|
13
|
+
class ExpiredSignature < StandardError; end
|
13
14
|
extend JWT::Json
|
14
15
|
|
15
16
|
module_function
|
@@ -93,16 +94,25 @@ module JWT
|
|
93
94
|
[header, payload, signature, signing_input]
|
94
95
|
end
|
95
96
|
|
96
|
-
def decode(jwt, key=nil, verify=true, &keyfinder)
|
97
|
+
def decode(jwt, key=nil, verify=true, options={}, &keyfinder)
|
97
98
|
raise JWT::DecodeError.new("Nil JSON web token") unless jwt
|
98
99
|
|
99
100
|
header, payload, signature, signing_input = decoded_segments(jwt, verify)
|
100
101
|
raise JWT::DecodeError.new("Not enough or too many segments") unless header && payload
|
101
|
-
|
102
|
+
|
103
|
+
default_options = {
|
104
|
+
:verify_expiration => true,
|
105
|
+
:leeway => 0
|
106
|
+
}
|
107
|
+
options = default_options.merge(options)
|
108
|
+
|
102
109
|
if verify
|
103
110
|
algo, key = signature_algorithm_and_key(header, key, &keyfinder)
|
104
111
|
verify_signature(algo, key, signing_input, signature)
|
105
112
|
end
|
113
|
+
if options[:verify_expiration] && payload.include?('exp')
|
114
|
+
raise JWT::ExpiredSignature.new("Signature has expired") unless payload['exp'] > (Time.now.to_i - options[:leeway])
|
115
|
+
end
|
106
116
|
return payload,header
|
107
117
|
end
|
108
118
|
|
data/spec/jwt_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe JWT do
|
4
4
|
before do
|
5
|
-
@payload = {"foo" => "bar"}
|
5
|
+
@payload = {"foo" => "bar", "exp" => Time.now.to_i + 1}
|
6
6
|
end
|
7
7
|
|
8
8
|
it "encodes and decodes JWTs" do
|
@@ -122,20 +122,46 @@ describe JWT do
|
|
122
122
|
JWT.decode(jwt, secret)
|
123
123
|
end
|
124
124
|
|
125
|
+
it "raises error when expired" do
|
126
|
+
expired_payload = @payload.clone
|
127
|
+
expired_payload['exp'] = Time.now.to_i - 1
|
128
|
+
secret = "secret"
|
129
|
+
jwt = JWT.encode(expired_payload, secret)
|
130
|
+
expect { JWT.decode(jwt, secret) }.to raise_error(JWT::ExpiredSignature)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "performs normal decode with skipped expiration check" do
|
134
|
+
expired_payload = @payload.clone
|
135
|
+
expired_payload['exp'] = Time.now.to_i - 1
|
136
|
+
secret = "secret"
|
137
|
+
jwt = JWT.encode(expired_payload, secret)
|
138
|
+
decoded_payload = JWT.decode(jwt, secret, true, {:verify_expiration => false})
|
139
|
+
expect(decoded_payload).to include(expired_payload)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "performs normal decode using leeway" do
|
143
|
+
expired_payload = @payload.clone
|
144
|
+
expired_payload['exp'] = Time.now.to_i - 2
|
145
|
+
secret = "secret"
|
146
|
+
jwt = JWT.encode(expired_payload, secret)
|
147
|
+
decoded_payload = JWT.decode(jwt, secret, true, {:leeway => 3})
|
148
|
+
expect(decoded_payload).to include(expired_payload)
|
149
|
+
end
|
150
|
+
|
125
151
|
describe "secure comparison" do
|
126
152
|
it "returns true if strings are equal" do
|
127
|
-
expect(JWT.secure_compare("Foo", "Foo")).to
|
153
|
+
expect(JWT.secure_compare("Foo", "Foo")).to be true
|
128
154
|
end
|
129
155
|
|
130
156
|
it "returns false if either input is nil or empty" do
|
131
157
|
[nil, ""].each do |bad|
|
132
|
-
expect(JWT.secure_compare(bad, "Foo")).to
|
133
|
-
expect(JWT.secure_compare("Foo", bad)).to
|
158
|
+
expect(JWT.secure_compare(bad, "Foo")).to be false
|
159
|
+
expect(JWT.secure_compare("Foo", bad)).to be false
|
134
160
|
end
|
135
161
|
end
|
136
162
|
|
137
163
|
it "retuns false if the strings are different" do
|
138
|
-
expect(JWT.secure_compare("Foo", "Bar")).to
|
164
|
+
expect(JWT.secure_compare("Foo", "Bar")).to be false
|
139
165
|
end
|
140
166
|
end
|
141
167
|
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jeff Lindsay
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-11-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: echoe
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 4.6.3
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 4.6.3
|
30
27
|
description: JSON Web Token implementation in Ruby
|
@@ -35,41 +32,40 @@ extra_rdoc_files:
|
|
35
32
|
- lib/jwt.rb
|
36
33
|
- lib/jwt/json.rb
|
37
34
|
files:
|
35
|
+
- Manifest
|
38
36
|
- Rakefile
|
37
|
+
- jwt.gemspec
|
39
38
|
- lib/jwt.rb
|
40
39
|
- lib/jwt/json.rb
|
41
40
|
- spec/helper.rb
|
42
41
|
- spec/jwt_spec.rb
|
43
|
-
- Manifest
|
44
|
-
- jwt.gemspec
|
45
42
|
homepage: http://github.com/progrium/ruby-jwt
|
46
43
|
licenses:
|
47
44
|
- MIT
|
45
|
+
metadata: {}
|
48
46
|
post_install_message:
|
49
47
|
rdoc_options:
|
50
|
-
- --line-numbers
|
51
|
-
- --title
|
48
|
+
- "--line-numbers"
|
49
|
+
- "--title"
|
52
50
|
- Jwt
|
53
|
-
- --main
|
51
|
+
- "--main"
|
54
52
|
- README.md
|
55
53
|
require_paths:
|
56
54
|
- lib
|
57
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
56
|
requirements:
|
60
|
-
- -
|
57
|
+
- - ">="
|
61
58
|
- !ruby/object:Gem::Version
|
62
59
|
version: '0'
|
63
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
61
|
requirements:
|
66
|
-
- -
|
62
|
+
- - ">="
|
67
63
|
- !ruby/object:Gem::Version
|
68
64
|
version: '1.2'
|
69
65
|
requirements: []
|
70
66
|
rubyforge_project: jwt
|
71
|
-
rubygems_version:
|
67
|
+
rubygems_version: 2.3.0
|
72
68
|
signing_key:
|
73
|
-
specification_version:
|
69
|
+
specification_version: 4
|
74
70
|
summary: JSON Web Token implementation in Ruby
|
75
71
|
test_files: []
|