roda-token-auth 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a2f0a5fd3e8b811a98a716e4303d61ff0a6e8e4
4
+ data.tar.gz: ea373a28681c13f0cc720676192e5dbd9f9b3e6d
5
+ SHA512:
6
+ metadata.gz: 142f7945d68ce8d3a843a4412f65849d95bd6c4e8e51ca6260864ce16bd75f48b84d36388e5158805d729019ade179e1ab56006fc9a843c2c483abcad52bae1f
7
+ data.tar.gz: 98f361759ffa36708713da3a127a7d87bb738f137db45a90909b6c06839cba4c61059f6bf40f7125fc0d131b1be5b002f8f79d7a098a14356d74ea97a9cd5a03
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in roda-token-auth.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ronaldo Raivil
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.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Roda Token Authentication
2
+
3
+ Adds token authentication to Roda.
4
+ Based on [Roda Basic Auth](https://github.com/badosu/roda-basic-auth)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'roda-token-auth'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install roda-token-auth
21
+
22
+ ## Configuration
23
+
24
+ Configure your Roda application to use this plugin:
25
+
26
+ ```ruby
27
+ plugin :token_auth
28
+ ```
29
+
30
+ You can pass global options, in this context they'll be shared between all
31
+ `r.token_auth` calls.
32
+
33
+ ```ruby
34
+ plugin :token_auth, authenticator: proc {|token, secret| [token, secret] == %w(foo bar)}
35
+ ```
36
+
37
+ ```ruby
38
+ plugin :token_auth, authenticator: proc {|token, secret| [token, secret] == %w(foo bar)}, token_variable: "X-My-Custom-Token", secret_variable: "X-My-Custom-Secret"
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ Call `r.token_auth` inside the routes you want to authenticate the user, it will halt
44
+ the request with 401 response code if the authenticator is false.
45
+
46
+ You can specify the local authenticator with a block:
47
+
48
+ ```ruby
49
+ r.token_auth { |token, secret| [token, secret] == %w(foo bar) }
50
+ ```
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/raivil/roda-token-auth.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "roda/plugins/token_auth"
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__)
data/bin/setup ADDED
@@ -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
+ # frozen_string_literal: true
2
+ require "roda"
3
+ require "roda/plugins/token_auth/version"
4
+
5
+ module Roda::RodaPlugins
6
+ module TokenAuth
7
+ DEFAULTS = {
8
+ token_variable: "X-Token",
9
+ secret_variable: "X-Secret",
10
+ unauthorized_headers: proc do |_opts|
11
+ { "Content-Type" => "application/json", "Content-Length" => "0" }
12
+ end
13
+ }.freeze
14
+
15
+ def self.configure(app, opts = {})
16
+ plugin_opts = (app.opts[:token_auth] ||= DEFAULTS)
17
+ app.opts[:token_auth] = plugin_opts.merge(opts)
18
+ app.opts[:token_auth].freeze
19
+ end
20
+
21
+ module RequestMethods
22
+ def token_auth(opts = {}, &authenticator)
23
+ auth_opts = roda_class.opts[:token_auth].merge(opts)
24
+ authenticator ||= auth_opts[:authenticator]
25
+
26
+ raise "Must provide an authenticator block" if authenticator.nil?
27
+ auth_token = header_variable(auth_opts, :token_variable)
28
+ auth_secret = header_variable(auth_opts, :secret_variable)
29
+ return if authenticator.call(auth_token, auth_secret)
30
+ auth_opts[:unauthorized]&.call(self)
31
+ halt [401, auth_opts[:unauthorized_headers].call(auth_opts), []]
32
+ end
33
+
34
+ def header_variable(auth_opts, variable_name)
35
+ env["HTTP_#{auth_opts[variable_name]}".tr("-", "_").upcase]
36
+ end
37
+ end
38
+ end
39
+
40
+ register_plugin(:token_auth, TokenAuth)
41
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Roda
4
+ module RodaPlugins
5
+ module TokenAuth
6
+ VERSION = "0.1.1".freeze
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "roda/plugins/token_auth/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "roda-token-auth"
8
+ spec.version = Roda::RodaPlugins::TokenAuth::VERSION
9
+ spec.authors = ["Ronaldo Raivil"]
10
+ spec.email = ["raivil@gmail.com"]
11
+
12
+ spec.summary = %(Plugin that adds token authentication methods to Roda)
13
+ spec.description = %(Plugin that adds token authentication methods to Roda)
14
+ spec.homepage = "https://github.com/raivil/roda-token-auth"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "roda", ">= 2.0", "< 4.0"
34
+ spec.add_development_dependency "bundler", "~> 1.15"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "rack-test", "0.7.0"
38
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-token-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ronaldo Raivil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.15'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.15'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rack-test
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '='
80
+ - !ruby/object:Gem::Version
81
+ version: 0.7.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '='
87
+ - !ruby/object:Gem::Version
88
+ version: 0.7.0
89
+ description: Plugin that adds token authentication methods to Roda
90
+ email:
91
+ - raivil@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/roda/plugins/token_auth.rb
106
+ - lib/roda/plugins/token_auth/version.rb
107
+ - roda-token-auth.gemspec
108
+ homepage: https://github.com/raivil/roda-token-auth
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.13
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Plugin that adds token authentication methods to Roda
133
+ test_files: []