roda-basic-auth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a25fb1b57a71764743f9d4169d1efc47d8c81398
4
+ data.tar.gz: e4e737198c5e7061ceafbe629883d5369005b6df
5
+ SHA512:
6
+ metadata.gz: 0f91e96f8dcf050dcfbf1d65205f75c03298f428cb75ddfe2290ff1c3bbe02eea23d04302c47f64ad72135f97076d0aa2e1c7fbbaa707b2425bb79cc3aca9131
7
+ data.tar.gz: 0d15fefcbd2f733b4e2356ce3604e40dd294158ebc40c70ae8896ac60021741b7d250537c508fdb57a4724362585b421feb71359f4183e44b8aec887995d1de5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in roda-basic-auth.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Amadeus Folego
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,47 @@
1
+ # Roda Basic Authentication
2
+
3
+ Adds functionality for simple http authentication with Roda.
4
+
5
+ ## Configuration
6
+
7
+ Configure your Roda application to use this plugin:
8
+
9
+ ```ruby
10
+ plugin :basic_auth
11
+ ```
12
+
13
+ You can pass global options, in this context they'll be shared between all
14
+ basic\_auth calls.
15
+
16
+ ```ruby
17
+ plugin :basic_auth, authenticator: proc {|user, pass| [user, pass] == %w[foo bar]},
18
+ realm: 'Restricted Area' # default
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Call `r.basic_auth` when you want to authenticate the user, it halts the
24
+ request with 401 response code if the authenticator is false.
25
+
26
+ You can specify the local authenticator with a block:
27
+
28
+ ```ruby
29
+ r.basic_auth { |user, pass| [user, pass] == %w[foo bar] }
30
+ ```
31
+
32
+ ## Warden
33
+
34
+ To avoid having your 401 responses intercepted by warden, you need to configure
35
+ the unauthenticated callback that is called just before the request is halted:
36
+
37
+ ```ruby
38
+ plugin :basic_auth, unauthorized: proc {|r| r.env['warden'].custom_failure! }
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/badosu/roda-basic-auth.
44
+
45
+ ## License
46
+
47
+ 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,2 @@
1
+ require "bundler/gem_tasks"
2
+ 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/basic_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
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,7 @@
1
+ require 'roda'
2
+
3
+ module Roda::RodaPlugins
4
+ module BasicAuth
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ require "roda"
2
+ require "roda/plugins/basic_auth/version"
3
+
4
+ module Roda::RodaPlugins
5
+ module BasicAuth
6
+ DEFAULTS = {
7
+ realm: "Restricted Area",
8
+ unauthorized_headers: proc do |opts|
9
+ {'Content-Type' => 'text/plain',
10
+ 'Content-Length' => '0',
11
+ 'WWW-Authenticate' => ('Basic realm="%s"' % opts[:realm])}
12
+ end,
13
+ bad_request_headers: proc do |opts|
14
+ {'Content-Type' => 'text/plain', 'Content-Length' => '0'}
15
+ end
16
+ }
17
+
18
+ def self.configure(app, opts={})
19
+ plugin_opts = (app.opts[:basic_auth] ||= DEFAULTS)
20
+ app.opts[:basic_auth] = plugin_opts.merge(opts)
21
+ app.opts[:basic_auth].freeze
22
+ end
23
+
24
+ module RequestMethods
25
+ def basic_auth(opts={}, &authenticator)
26
+ auth_opts = roda_class.opts[:basic_auth].merge(opts)
27
+ authenticator ||= auth_opts[:authenticator]
28
+
29
+ raise "Must provide an authenticator block" if authenticator.nil?
30
+
31
+ auth = Rack::Auth::Basic::Request.new(env)
32
+
33
+ unless auth.provided?
34
+ auth_opts[:unauthorized].call(self) if auth_opts[:unauthorized]
35
+ halt [401, auth_opts[:unauthorized_headers].call(auth_opts), []]
36
+ end
37
+
38
+ unless auth.basic?
39
+ halt [400, auth_opts[:bad_request_headers].call(auth_opts), []]
40
+ end
41
+
42
+ if authenticator.call(*auth.credentials)
43
+ env['REMOTE_USER'] = auth.username
44
+ else
45
+ auth_opts[:unauthorized].call(self) if auth_opts[:unauthorized]
46
+ halt [401, auth_opts[:unauthorized_headers].call(auth_opts), []]
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ register_plugin(:basic_auth, BasicAuth)
53
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'roda/plugins/basic_auth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "roda-basic-auth"
8
+ spec.version = Roda::RodaPlugins::BasicAuth::VERSION
9
+ spec.authors = ["Amadeus Folego"]
10
+ spec.email = ["amadeusfolego@gmail.com"]
11
+
12
+ spec.summary = %q{Adds basic authentication methods to Roda}
13
+ spec.description = %q{Adds basic authentication methods to Roda}
14
+ spec.homepage = "https://github.com/badosu/basic-roda-auth"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "roda", "~> 2.0"
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-basic-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amadeus Folego
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-23 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
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Adds basic authentication methods to Roda
56
+ email:
57
+ - amadeusfolego@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/roda/plugins/basic_auth.rb
70
+ - lib/roda/plugins/basic_auth/version.rb
71
+ - roda-basic-auth.gemspec
72
+ homepage: https://github.com/badosu/basic-roda-auth
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Adds basic authentication methods to Roda
96
+ test_files: []