jwt-rack 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bef98cd84654986f72aac0d1b8fc9a64f762bd0e784e39929e15893a3868c586
4
+ data.tar.gz: 8b70bf2c4dcd2ea7b92fed3c6121c834195eb9365a320acacbd7ff639ad20f2e
5
+ SHA512:
6
+ metadata.gz: fe5702dd93cecb195a467a1f037c67a7d052ebabb67714d131ed118e34755b6c2155bec6b13853c4df8d0ad9c49a7c578efa2d2bc4de106b1919ee5e9a286eda
7
+ data.tar.gz: 28ec9ecb2e24e958cee55899054589ff55a35dc7bb86f9e80cb322e958747157de2f37e60b249878c792e454100d4b7c6608c066b1c319a5c51cc03f200d7328
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6.0
3
+
4
+ # Use / or %r around regular expressions.
5
+ Style/RegexpLiteral:
6
+ EnforcedStyle: mixed
7
+ # slashes: Always use slashes.
8
+ # percent_r: Always use %r.
9
+ # mixed: Use slashes on single-line regexes, and %r on multi-line regexes.
10
+
11
+ Metrics/MethodLength:
12
+ Max: 30
13
+
14
+ Metrics/LineLength:
15
+ Max: 99
16
+
17
+ Metrics/AbcSize:
18
+ Max: 25
@@ -0,0 +1,9 @@
1
+ before_install:
2
+ - sudo apt-get install -y libsodium18
3
+ dist: xenial
4
+ language: ruby
5
+ rvm:
6
+ - 2.3.8
7
+ - 2.4.5
8
+ - 2.5.3
9
+ - 2.6.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jwt-rack.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yaroslav Savchuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,123 @@
1
+ # JWT::Rack
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jwt-rack.svg)](http://badge.fury.io/rb/jwt-rack)
4
+ [![Build Status](https://travis-ci.org/ysv/jwt-rack.svg)](https://travis-ci.org/ysv/jwt-rack)
5
+ [![Code Climate](https://codeclimate.com/github/ysv/jwt-rack/badges/gpa.svg)](https://codeclimate.com/github/ysv/jwt-rack)
6
+
7
+ ## About
8
+
9
+ This gem provides JSON Web Token (JWT) based authentication.
10
+
11
+ ## Requirements
12
+
13
+ - Ruby 2.3.8 or greater
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's `Gemfile`:
18
+
19
+ ```ruby
20
+ gem 'jwt-rack'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```
26
+ $ bundle install
27
+ ```
28
+
29
+ Or install it directly with:
30
+
31
+ ```
32
+ $ gem install jwt-rack
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ `JWT::Rack::Auth` accepts several configuration options. All options are passed in a single Ruby Hash:
38
+
39
+ * `secret` : required : `String` || `OpenSSL::PKey::RSA` || `OpenSSL::PKey::EC` : A cryptographically secure String (for HMAC algorithms) or a public key object of an appropriate type for public key algorithms. Set to `nil` if you are using the `'none'` algorithm.
40
+
41
+ * `verify` : optional : Boolean : Determines whether JWT will verify tokens keys for mismatch key types when decoded. Default is `true`. Set to `false` if you are using the `'none'` algorithm.
42
+
43
+ * `options` : optional : Hash : A hash of options that are passed through to JWT to configure supported claims and algorithms. See the ruby-jwt docs for [more information of the algorithms and their requirements](https://github.com/jwt/ruby-jwt#algorithms-and-usage) as well as [more information on the supported claims](https://github.com/progrium/ruby-jwt#support-for-reserved-claim-names). These options are passed through without change to the underlying `ruby-jwt` gem. By default only expiration (exp) and Not Before (nbf) claims are verified. Pass in an algorithm choice like `{ algorithm: 'HS256' }`.
44
+
45
+ * `exclude` : optional : Array : An Array of path strings representing paths that should not be checked for the presence of a valid JWT token. Excludes sub-paths as of specified paths as well (e.g. `%w(/docs)` excludes `/docs/some/thing.html` also). Each path should start with a `/`. If a path matches the current request path this entire middleware is skipped and no authentication or verification of tokens takes place.
46
+
47
+ * `on_error` : optional : Callable : An object which responds to `call` method with single `error` parameter. `error` parameter is one of `JWT::Rack::Auth::ERRORS_TO_RESCUE`. `on_error` callable object will be called if one of `JWT::Rack::Auth::ERRORS_TO_RESCUE` raised. For default handler check `JWT::Rack::Auth#default_on_error`.
48
+
49
+ ## Example Server-Side Config
50
+
51
+ Where `my_args` is a `Hash` containing valid keys. See `spec/example_spec.rb`
52
+ for a more complete example of the valid arguments for creating and verifying
53
+ tokens.
54
+
55
+ ### Sinatra
56
+
57
+ ```ruby
58
+ use JWT::Rack::Auth, my_args
59
+ ```
60
+
61
+ ### Cuba
62
+
63
+ ```ruby
64
+ Cuba.use JWT::Rack::Auth, my_args
65
+ ```
66
+
67
+ ### Rails
68
+
69
+ ```ruby
70
+ Rails.application.config.middleware.use JWT::Rack::Auth, my_args
71
+ ```
72
+
73
+ ## Generating tokens
74
+ You can generate JSON Web Tokens for your users using the
75
+ `JWT::Rack::Token#encode` method which takes `payload`,
76
+ `secret`, and `algorithm` params.
77
+
78
+ The secret will be either a cryptographically strong random string, or the
79
+ secret key component of a public/private keypair of an accepted type depending on
80
+ the algorithm you choose. You can see examples of using the various key types at
81
+ the [ruby-jwt gem repo](https://github.com/jwt/ruby-jwt/blob/master/README.md)
82
+
83
+ The `algorithm` is an optional String and can be one of the following (default HMAC 'HS256'):
84
+
85
+ ```ruby
86
+ %w(none HS256 HS384 HS512 RS256 RS384 RS512 ED25519 ES256 ES384 ES512)
87
+
88
+ HS256 is the default
89
+ ```
90
+
91
+ Note that `ED25519` support depends on the `rbnacl` which is _not_ already included by the
92
+ `rack-jwt` gem. If you wish to use the `ED25519` algorith, you must also manually require
93
+ `rbnacl` gem in addition to `rack-jwt`.
94
+
95
+ Here is a sample payload with illustrative data. You don't have to use all,
96
+ or even most, of these.
97
+
98
+ ```ruby
99
+ secret = 'your_secret_token_or_key'
100
+
101
+ my_payload = {
102
+ data: 'data',
103
+ exp: Time.now.to_i + 4 * 3600,
104
+ nbf: Time.now.to_i - 3600,
105
+ iss: 'https://my.awesome.website/',
106
+ aud: 'audience',
107
+ jti: Digest::MD5.hexdigest([hmac_secret, iat].join(':').to_s),
108
+ iat: Time.now.to_i,
109
+ sub: 'subject'
110
+ }
111
+
112
+ alg = 'HS256'
113
+
114
+ JWT::Rack::Token.encode(my_payload, secret, alg)
115
+ ```
116
+
117
+ ## Contributing
118
+
119
+ 1. Fork it ( https://github.com/ysv/jwt-rack/fork )
120
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
121
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
122
+ 4. Push to the branch (`git push origin my-new-feature`)
123
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jwt/rack"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "jwt/rack/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jwt-rack"
7
+ spec.version = Jwt::Rack::VERSION
8
+ spec.authors = ["Yaroslav Savchuk"]
9
+ spec.email = ["savchukyarpolk@gmail.com"]
10
+
11
+ spec.summary = %q{Rack middleware that provides authentication based on JSON Web Tokens.}
12
+ spec.description = %q{Rack middleware that provides authentication based on JSON Web Tokens.}
13
+ spec.homepage = "https://github.com/ysv/jwt-rack"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/ysv/jwt-rack"
18
+ spec.metadata["changelog_uri"] = "https://github.com/ysv/jwt-rack/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.platform = Gem::Platform::RUBY
30
+ spec.required_ruby_version = '>= 2.3.8'
31
+
32
+ spec.add_development_dependency 'bundler', '>= 1.16.2'
33
+ spec.add_development_dependency 'rake', '>= 12.0.0'
34
+ spec.add_development_dependency 'rack-test', '>= 1.0.0'
35
+ spec.add_development_dependency 'rspec', '>= 3.8.0'
36
+ spec.add_development_dependency 'simplecov', '>= 0.16.0'
37
+ spec.add_development_dependency 'rbnacl', '>= 6.0.1'
38
+
39
+ spec.add_runtime_dependency 'rack'
40
+ spec.add_runtime_dependency 'jwt', '~> 2.1.0'
41
+ end
@@ -0,0 +1,8 @@
1
+ require "jwt/rack/version"
2
+
3
+ module Jwt
4
+ module Rack
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Jwt
2
+ module Rack
3
+ VERSION = "0.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jwt-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Savchuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.16.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.8.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.16.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.16.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rbnacl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 6.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 6.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: jwt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.1.0
125
+ description: Rack middleware that provides authentication based on JSON Web Tokens.
126
+ email:
127
+ - savchukyarpolk@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - jwt-rack.gemspec
143
+ - lib/jwt/rack.rb
144
+ - lib/jwt/rack/version.rb
145
+ homepage: https://github.com/ysv/jwt-rack
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ homepage_uri: https://github.com/ysv/jwt-rack
150
+ source_code_uri: https://github.com/ysv/jwt-rack
151
+ changelog_uri: https://github.com/ysv/jwt-rack/blob/master/CHANGELOG.md
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.3.8
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.0.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Rack middleware that provides authentication based on JSON Web Tokens.
171
+ test_files: []