rack-ninja_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: 60ef8b50594dfc815315d1e66a3c4288fdeb8269
4
+ data.tar.gz: b998e8dc946e9f209ba99e4c2968cf0a4481d8c6
5
+ SHA512:
6
+ metadata.gz: 851e4f16a420ad75483086d01f1999b71af475cf61398bedf4e00c1cb7ef4f0bda5f6758c1949644d30d3f8156d129c92a1a8fb22002b7098fa8e58d9a0804ec
7
+ data.tar.gz: a3d61f16de1ba31046df33ad11a949b59f7ca559c80cdbc2cbe7cc0b512140d7110079d08ca29b9b7113308c9f8dcb3db2649047b9ac083b33ed240adec1b057
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-ninja_auth.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 JP Hastings-Spital
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,23 @@
1
+ # Rack::NinjaAuth
2
+
3
+ Require authentication via google for your application without passing any auth information to your application. This may sound crazy, but it's perfect for securing a test environment.
4
+
5
+ ## Example
6
+
7
+ Add this as middleware to your rack application, then execute with `NINJA_GOOGLE_CLIENT_ID` and `NINJA_GOOGLE_CLIENT_SECRET` environment variables set.
8
+
9
+ ```ruby
10
+ require 'sinatra'
11
+ require 'rack/ninja_auth'
12
+
13
+ use Rack::NinjaAuth::Middleware, /@gmail.com$/
14
+
15
+ get '/' do
16
+ "This is secure without authorisation with a google account with an email ending in @gmail.com"
17
+ end
18
+ ```
19
+
20
+ ## License
21
+
22
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
23
+
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/examples/gmail.rb ADDED
@@ -0,0 +1,21 @@
1
+ $: << '../lib'
2
+ # Make sure you run this with the appropriate environment variables set:
3
+ #
4
+ # ```
5
+ # NINJA_GOOGLE_CLIENT_ID=<Your google client id>
6
+ # NINJA_GOOGLE_CLIENT_SECRET=<Your google client secret>
7
+ # ruby gmail.rb
8
+ # ```
9
+ #
10
+ # Now you can visit `http://127.0.0.1:4567/secured` and will only access it if you validate with a google
11
+ # account that has an `@gmail.com` email address.
12
+
13
+ require 'sinatra'
14
+ require 'rack/ninja_auth'
15
+
16
+ use Rack::NinjaAuth::Middleware, /@gmail.com$/
17
+ # use Rack::NinjaAuth::Middleware, /@gmail\./, './file/to/deliver/if/email/does/not/match.html'
18
+
19
+ get '/secured' do
20
+ "You hit the secured app"
21
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module NinjaAuth
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ require 'rack/ninja_auth/version'
2
+ require 'sinatra/base'
3
+ require 'omniauth/google_oauth2'
4
+
5
+ module Rack
6
+ module NinjaAuth
7
+ class Middleware < Sinatra::Base
8
+ use Rack::Session::Pool,
9
+ key: 'rack.ninja_auth',
10
+ expire_after: 2592000
11
+
12
+ use OmniAuth::Builder do
13
+ provider :google_oauth2, ENV["NINJA_GOOGLE_CLIENT_ID"], ENV["NINJA_GOOGLE_CLIENT_SECRET"]
14
+ end
15
+
16
+ def initialize(app, email_matcher = //, not_allowed_file = nil)
17
+ @main_app = app
18
+ @email_matcher = email_matcher
19
+ @not_allowed_file = not_allowed_file || ::File.expand_path('../../../views/401.html', __FILE__)
20
+ super()
21
+ end
22
+
23
+ before do
24
+ if is_authenticated?
25
+ res = @main_app.call(request.env)
26
+ headers res[1]
27
+ halt res[0], res[2]
28
+ end
29
+ end
30
+
31
+ get '/auth/google_oauth2/callback' do
32
+ if (request.env["omniauth.auth"].info.email.match(@email_matcher) rescue false)
33
+ session[:user] = request.env["omniauth.auth"].info.email
34
+ redirect session[:redirect_to]
35
+ else
36
+ send_file(@not_allowed_file, status: 401)
37
+ end
38
+ end
39
+
40
+ after do
41
+ if status == 404
42
+ session[:redirect_to] = env['REQUEST_URI'] == '/auth/google_oauth2' ? '/' : env['REQUEST_URI']
43
+ redirect '/auth/google_oauth2'
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def is_authenticated?
50
+ !!session[:user]
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/ninja_auth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-ninja_auth"
8
+ spec.version = Rack::NinjaAuth::VERSION
9
+ spec.authors = ["JP Hastings-Spital"]
10
+ spec.email = ["jp@deliveroo.co.uk"]
11
+
12
+ spec.summary = %q{Secure your test rigs with google.}
13
+ spec.description = %q{Transparently secure your rack application with google. For test rigs etc.}
14
+ spec.homepage = "https://github.com/jphastings/rack-ninja_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 "sinatra", "~> 1.4"
23
+ spec.add_dependency "omniauth-google-oauth2", "~> 0.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ end
data/views/401.html ADDED
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4
+ <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5
+ <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
6
+ <head>
7
+ <meta charset="utf-8">
8
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
9
+ <title>Not authorized</title>
10
+ <meta name="description" content="Not authorized - Ninja Auth">
11
+ <meta name="viewport" content="width=device-width, initial-scale=1">
12
+ </head>
13
+ <body>
14
+ <div class="alert">
15
+ <h1>Not authorized</h1>
16
+ <p>Sorry, the google identity you provided hasn't been given access to this site.</p>
17
+ </div>
18
+ </body>
19
+ </html>
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ninja_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JP Hastings-Spital
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-google-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
83
+ description: Transparently secure your rack application with google. For test rigs
84
+ etc.
85
+ email:
86
+ - jp@deliveroo.co.uk
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - examples/gmail.rb
100
+ - lib/rack/ninja_auth.rb
101
+ - lib/rack/ninja_auth/version.rb
102
+ - rack-ninja_auth.gemspec
103
+ - views/401.html
104
+ homepage: https://github.com/jphastings/rack-ninja_auth
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Secure your test rigs with google.
128
+ test_files: []