sinatra-jwt 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +9 -1
- data/README.md +12 -12
- data/lib/sinatra/jwt/version.rb +1 -1
- data/lib/sinatra/jwt.rb +16 -23
- data/sinatra-jwt.gemspec +40 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301b2054a8ce75ff89406788b6aa02b58f7e8e4759646be044b307f1a905c4c8
|
4
|
+
data.tar.gz: d1e44bbb2a4b0a877f921bb1332f70fb4a17fade6c552bdb03f541b770530656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4667804039a5bd764b590e0cb2f9d9c33af226e47f3d64b0817bd1d380fb92100e62c18f6148a26e42a9cbb64d8a89f237375cb391409d1ec657c980bbf18e89
|
7
|
+
data.tar.gz: 421064e82c11236f259bfb5fbf1c0dcbbd1719b1636d0e0df61bf28eedc8bfeece4fd010ad449cf7165e04535dd025dd6265108dcf1a6bc67981036267ae7a69
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sinatra-jwt (0.
|
4
|
+
sinatra-jwt (0.2.0)
|
5
5
|
jwt (~> 2.5)
|
6
6
|
sinatra (~> 2.2)
|
7
7
|
|
@@ -10,6 +10,7 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
12
|
diff-lcs (1.5.0)
|
13
|
+
docile (1.4.0)
|
13
14
|
json (2.6.2)
|
14
15
|
jwt (2.5.0)
|
15
16
|
mustermann (2.0.2)
|
@@ -54,6 +55,12 @@ GEM
|
|
54
55
|
parser (>= 3.1.1.0)
|
55
56
|
ruby-progressbar (1.11.0)
|
56
57
|
ruby2_keywords (0.0.5)
|
58
|
+
simplecov (0.21.2)
|
59
|
+
docile (~> 1.1)
|
60
|
+
simplecov-html (~> 0.11)
|
61
|
+
simplecov_json_formatter (~> 0.1)
|
62
|
+
simplecov-html (0.12.3)
|
63
|
+
simplecov_json_formatter (0.1.4)
|
57
64
|
sinatra (2.2.2)
|
58
65
|
mustermann (~> 2.0)
|
59
66
|
rack (~> 2.2)
|
@@ -71,6 +78,7 @@ DEPENDENCIES
|
|
71
78
|
rbs
|
72
79
|
rspec (~> 3.0)
|
73
80
|
rubocop (~> 1.21)
|
81
|
+
simplecov (~> 0.21)
|
74
82
|
sinatra-jwt!
|
75
83
|
|
76
84
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
[](https://badge.fury.io/gh/suddani%2Fsinatra-jwt)
|
2
|
+
[](https://badge.fury.io/rb/sinatra-jwt)
|
3
|
+
[](https://github.com/suddani/sinatra-jwt/actions/workflows/main.yml)
|
4
4
|
|
5
|
-
|
5
|
+
# Sinatra::Jwt
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -17,7 +17,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
17
17
|
## Usage
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
require "sinatra
|
20
|
+
require "sinatra/jwt"
|
21
21
|
|
22
22
|
class Application < Sinatra::Base
|
23
23
|
register Sinatra::Jwt
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
## Use a single key
|
28
28
|
If you wish to use a single key you can provide it directly
|
29
29
|
```ruby
|
30
|
-
require "sinatra
|
30
|
+
require "sinatra/jwt"
|
31
31
|
|
32
32
|
class Application < Sinatra::Base
|
33
33
|
register Sinatra::Jwt
|
@@ -92,7 +92,7 @@ The file can contain as many keys as you want all with different algorithms.
|
|
92
92
|
#### Files
|
93
93
|
You can change the file that is loaded by either hardcoding the path
|
94
94
|
```ruby
|
95
|
-
require "sinatra
|
95
|
+
require "sinatra/jwt"
|
96
96
|
|
97
97
|
class Application < Sinatra::Base
|
98
98
|
register Sinatra::Jwt
|
@@ -102,7 +102,7 @@ end
|
|
102
102
|
```
|
103
103
|
or using the env helper method that takes the path from the environment variables
|
104
104
|
```ruby
|
105
|
-
require "sinatra
|
105
|
+
require "sinatra/jwt"
|
106
106
|
|
107
107
|
class Application < Sinatra::Base
|
108
108
|
register Sinatra::Jwt
|
@@ -116,7 +116,7 @@ end
|
|
116
116
|
#### Strings
|
117
117
|
You can change the file that is loaded by either hardcoding the path
|
118
118
|
```ruby
|
119
|
-
require "sinatra
|
119
|
+
require "sinatra/jwt"
|
120
120
|
|
121
121
|
class Application < Sinatra::Base
|
122
122
|
register Sinatra::Jwt
|
@@ -126,7 +126,7 @@ end
|
|
126
126
|
```
|
127
127
|
or using the env helper method that takes the path from the environment variables
|
128
128
|
```ruby
|
129
|
-
require "sinatra
|
129
|
+
require "sinatra/jwt"
|
130
130
|
|
131
131
|
class Application < Sinatra::Base
|
132
132
|
register Sinatra::Jwt
|
@@ -187,7 +187,7 @@ You can use a custom decoder by implementing an object that has a `decode` metho
|
|
187
187
|
```ruby
|
188
188
|
require "base64"
|
189
189
|
require "json"
|
190
|
-
require "sinatra
|
190
|
+
require "sinatra/jwt"
|
191
191
|
|
192
192
|
class DummyDecoder
|
193
193
|
def self.decode(token, key = nil, verify = false, options = {})
|
@@ -212,7 +212,7 @@ end
|
|
212
212
|
This decoder is bundled with the extension but will cause `unauthorized calls in any other environment than development`
|
213
213
|
|
214
214
|
```ruby
|
215
|
-
require "sinatra
|
215
|
+
require "sinatra/jwt"
|
216
216
|
|
217
217
|
class Application < Sinatra::Base
|
218
218
|
register Sinatra::Jwt
|
data/lib/sinatra/jwt/version.rb
CHANGED
data/lib/sinatra/jwt.rb
CHANGED
@@ -51,16 +51,6 @@ module Sinatra
|
|
51
51
|
set :jwt_auth_decoder, decoder
|
52
52
|
end
|
53
53
|
|
54
|
-
def self.added_attr_or_appended?(diff)
|
55
|
-
return true unless diff[:added_attr].nil?
|
56
|
-
return true unless diff[:appended].nil?
|
57
|
-
|
58
|
-
diff.each do |_k, v|
|
59
|
-
return true if v.is_a?(Hash) && added_attr_or_appended?(v)
|
60
|
-
end
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
54
|
# rubocop:disable Metrics/AbcSize
|
65
55
|
# rubocop:disable Metrics/CyclomaticComplexity
|
66
56
|
# rubocop:disable Metrics/MethodLength
|
@@ -78,27 +68,30 @@ module Sinatra
|
|
78
68
|
|
79
69
|
app.set(:auth) do |options_data|
|
80
70
|
condition do
|
71
|
+
return true if options_data == false
|
72
|
+
|
81
73
|
options = options_data.is_a?(Hash) ? options_data : {}
|
74
|
+
return true if options[:auth] == false
|
75
|
+
|
82
76
|
should_stop = !options.key?(:next) || !options[:next]
|
83
77
|
decoded_key = if should_stop
|
84
78
|
authorize!
|
85
79
|
else
|
86
80
|
authorize
|
87
81
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
82
|
+
|
83
|
+
return false unless decoded_key
|
84
|
+
|
85
|
+
if options.key?(:contains)
|
86
|
+
added_keys = settings.jwt_auth_auth_diff.added_attr_or_appended?(
|
87
|
+
decoded_key.first,
|
88
|
+
JSON.parse(options[:contains].to_json)
|
89
|
+
)
|
90
|
+
if should_stop && added_keys
|
91
|
+
halt 401, { status: "Unauthorized", message: "Missing rights" }.to_json if should_stop && added_keys
|
92
|
+
elsif added_keys
|
93
|
+
return false
|
99
94
|
end
|
100
|
-
else
|
101
|
-
false
|
102
95
|
end
|
103
96
|
end
|
104
97
|
end
|
data/sinatra-jwt.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/sinatra/jwt/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sinatra-jwt"
|
7
|
+
spec.version = Sinatra::Jwt::VERSION
|
8
|
+
spec.authors = ["Daniel Sudmann"]
|
9
|
+
spec.email = ["suddani@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Simple package to handle jwt auth in Sinatra"
|
12
|
+
spec.homepage = "https://github.com/suddani/sinatra-jwt"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/suddani/sinatra-jwt"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/suddani/sinatra-jwt/blob/master/CHANGELOG.md"
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "jwt", "~> 2.5"
|
36
|
+
spec.add_dependency "sinatra", "~> 2.2"
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, check out our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Sudmann
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/sinatra/jwt/top_level_key_array_diff.rb
|
63
63
|
- lib/sinatra/jwt/version.rb
|
64
64
|
- sig/sinatra/jwt.rbs
|
65
|
+
- sinatra-jwt.gemspec
|
65
66
|
homepage: https://github.com/suddani/sinatra-jwt
|
66
67
|
licenses:
|
67
68
|
- MIT
|