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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23e0995306d0b2428617e6f3b6989a18075a1ee149b08bea4bc02be3163e4267
4
- data.tar.gz: fa80fff93fbd3083ef40b4889114332363f1cf09e657e68a62e2b6b6eec4d4f3
3
+ metadata.gz: 301b2054a8ce75ff89406788b6aa02b58f7e8e4759646be044b307f1a905c4c8
4
+ data.tar.gz: d1e44bbb2a4b0a877f921bb1332f70fb4a17fade6c552bdb03f541b770530656
5
5
  SHA512:
6
- metadata.gz: a771461b7047e1c69ea687e29faaf8dd9c7c3ae8b2039978991c1068dc48c10f64146ab219ebb5b779d726acdda091828e0cf5ec25a83e683e093911ebfc4d1e
7
- data.tar.gz: ac5b2c2e407033c6c6b79dacce4284d2f8bc0e5d91be598e2efa33d0a773c2c140ba9cc4c240b1897641638cad526cd5131c288a4d1910bef4736b3b089bdeec
6
+ metadata.gz: 4667804039a5bd764b590e0cb2f9d9c33af226e47f3d64b0817bd1d380fb92100e62c18f6148a26e42a9cbb64d8a89f237375cb391409d1ec657c980bbf18e89
7
+ data.tar.gz: 421064e82c11236f259bfb5fbf1c0dcbbd1719b1636d0e0df61bf28eedc8bfeece4fd010ad449cf7165e04535dd025dd6265108dcf1a6bc67981036267ae7a69
data/CHANGELOG.md CHANGED
@@ -0,0 +1,7 @@
1
+ # 0.2.0
2
+
3
+ Allow a route to be marked by `:auth => false` or `:auth => [{ auth: false }]` to not require authentification. Can be usefull to programatically disable auth in certain environments.
4
+
5
+ # 0.1.0
6
+
7
+ First release
data/Gemfile CHANGED
@@ -14,3 +14,5 @@ gem "rake", "~> 13.0"
14
14
  gem "rspec", "~> 3.0"
15
15
 
16
16
  gem "rubocop", "~> 1.21"
17
+
18
+ gem "simplecov", "~> 0.21"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-jwt (0.1.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
- # Sinatra::Jwt
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sinatra/jwt`. To experiment with that code, run `bin/console` for an interactive prompt.
1
+ [![GitHub version](https://badge.fury.io/gh/suddani%2Fsinatra-jwt.svg)](https://badge.fury.io/gh/suddani%2Fsinatra-jwt)
2
+ [![Gem Version](https://badge.fury.io/rb/sinatra-jwt.svg)](https://badge.fury.io/rb/sinatra-jwt)
3
+ [![Ruby](https://github.com/suddani/sinatra-jwt/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/suddani/sinatra-jwt/actions/workflows/main.yml)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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-jwt"
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-jwt"
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-jwt"
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-jwt"
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-jwt"
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-jwt"
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-jwt"
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-jwt"
215
+ require "sinatra/jwt"
216
216
 
217
217
  class Application < Sinatra::Base
218
218
  register Sinatra::Jwt
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sinatra
4
4
  module Jwt
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
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
- if decoded_key
89
- if options.key?(:contains)
90
- added_keys = settings.jwt_auth_auth_diff.added_attr_or_appended?(
91
- decoded_key.first,
92
- JSON.parse(options[:contains].to_json)
93
- )
94
- if should_stop && added_keys
95
- halt 401, { status: "Unauthorized", message: "Missing rights" }.to_json
96
- elsif added_keys
97
- false
98
- end
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
@@ -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.1.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