auth_proxy 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: ba659f59091d66a0ceac172732b28d56c1d97808
4
+ data.tar.gz: 862403034b1bcbeaa55aea3d26abfec5922c86ff
5
+ SHA512:
6
+ metadata.gz: 66354bb618bf0cdf498ed6bd9b67a171c1501619ec779ff2bac1d2a740efc890dfdeee5dbc62228403b38d09923a520ce25d942efc960994478a42668c71bcdd
7
+ data.tar.gz: 14074aa6997ed8d5fc858de20ff12ede1dbd9f23fbba8ca0d0784dbf18bdf7ab1172dfddd861d9c332c5fba3e078bad9443adcbea78292c832ad1491058032ff
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -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, 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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ auth_proxy (0.1.0)
5
+ omniauth-github (~> 1.1.2)
6
+ rack (~> 1.6.4)
7
+ rack-reverse-proxy (~> 0.9.0)
8
+ rack-router (~> 0.6.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ coderay (1.1.0)
14
+ diff-lcs (1.2.5)
15
+ faraday (0.9.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ hashie (3.4.2)
18
+ jwt (1.5.1)
19
+ method_source (0.8.2)
20
+ multi_json (1.11.2)
21
+ multi_xml (0.5.5)
22
+ multipart-post (2.0.0)
23
+ oauth2 (1.0.0)
24
+ faraday (>= 0.8, < 0.10)
25
+ jwt (~> 1.0)
26
+ multi_json (~> 1.3)
27
+ multi_xml (~> 0.5)
28
+ rack (~> 1.2)
29
+ omniauth (1.2.2)
30
+ hashie (>= 1.2, < 4)
31
+ rack (~> 1.0)
32
+ omniauth-github (1.1.2)
33
+ omniauth (~> 1.0)
34
+ omniauth-oauth2 (~> 1.1)
35
+ omniauth-oauth2 (1.3.1)
36
+ oauth2 (~> 1.0)
37
+ omniauth (~> 1.2)
38
+ pry (0.10.1)
39
+ coderay (~> 1.1.0)
40
+ method_source (~> 0.8.1)
41
+ slop (~> 3.4)
42
+ rack (1.6.4)
43
+ rack-proxy (0.5.17)
44
+ rack
45
+ rack-reverse-proxy (0.9.0)
46
+ rack (>= 1.0.0)
47
+ rack-proxy (~> 0.5)
48
+ rack-router (0.6.0)
49
+ rake (10.4.2)
50
+ rspec (3.3.0)
51
+ rspec-core (~> 3.3.0)
52
+ rspec-expectations (~> 3.3.0)
53
+ rspec-mocks (~> 3.3.0)
54
+ rspec-core (3.3.2)
55
+ rspec-support (~> 3.3.0)
56
+ rspec-expectations (3.3.1)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.3.0)
59
+ rspec-mocks (3.3.2)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.3.0)
62
+ rspec-support (3.3.0)
63
+ slop (3.6.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ auth_proxy!
70
+ bundler (~> 1.9)
71
+ pry (~> 0.10.1)
72
+ rake (~> 10.0)
73
+ rspec (~> 3.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Karl Entwistle
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,31 @@
1
+ ## Welcome to AuthProxy
2
+
3
+ This is a simple reverse proxy for Rack. It is not meant for production systems (although it may work), as the webserver fronting your app is generally much better at this sort of thing.
4
+
5
+ ## Example usage
6
+
7
+ ````ruby
8
+ require_relative 'lib/auth_proxy'
9
+
10
+ use Rack::Session::Cookie, secret: 'change_me'
11
+
12
+ use OmniAuth::Builder do
13
+ provider:github, 'key', 'secret'
14
+ end
15
+
16
+ run AuthProxy.new({
17
+ '/doodles' => 'https://www.google.com/'
18
+ })
19
+ ````
20
+
21
+ Would automatically proxy requests
22
+ - http://localhost/doodles => https://www.google.com/doodles
23
+ - http://localhost/doodles/static/styles.css => https://www.google.com/doodles/static/styles.css
24
+
25
+ ## Code Status
26
+
27
+ [![Build Status](https://semaphoreci.com/api/v1/projects/60b3b39b-fa3f-46e1-9a90-ede9107e1ccf/484376/badge.svg)](https://semaphoreci.com/karlentwistle/auth_proxy)
28
+
29
+ ## License
30
+
31
+ AuthProxy is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'auth_proxy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "auth_proxy"
8
+ spec.version = AuthProxy::VERSION
9
+ spec.authors = ["Karl Entwistle"]
10
+ spec.email = ["karl@simpleweb.co.uk"]
11
+
12
+ spec.summary = %q{simple reverse proxy for Rack.}
13
+ spec.description = %q{This is a simple reverse proxy for Rack. It is not meant for production systems (although it may work), as the webserver fronting your app is generally much better at this sort of thing.}
14
+ spec.homepage = "https://github.com/karlentwistle/auth_proxy"
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 "omniauth-github", "~> 1.1.2"
23
+ spec.add_dependency 'rack', '~> 1.6.4'
24
+ spec.add_dependency 'rack-reverse-proxy', '~> 0.9.0'
25
+ spec.add_dependency 'rack-router', '~> 0.6.0'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.9"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency 'pry', '~> 0.10.1'
30
+ spec.add_development_dependency 'rspec', '~> 3.3.0'
31
+ end
32
+
@@ -0,0 +1,26 @@
1
+ require_relative 'validator'
2
+
3
+ class AuthProxy
4
+ class Callback
5
+ include AuthProxy::Validator
6
+
7
+ def call(env)
8
+ @env = env
9
+
10
+ response = Rack::Response.new
11
+
12
+ if valid_callback?
13
+ response.set_cookie('secret', {path: '/', value: '123'})
14
+ end
15
+
16
+ response.status = 301
17
+ response['location'] = rack_request.base_url + '/'
18
+
19
+ response.finish
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :env
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ class AuthProxy
2
+ class Proxy
3
+ def initialize(options={})
4
+ @app = Rack::ReverseProxy.new do
5
+ reverse_proxy_options preserve_host: true
6
+
7
+ options.each do |path, host|
8
+ reverse_proxy path, host, replace_response_host: true
9
+ end
10
+ end
11
+ end
12
+
13
+ def call(env)
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ class AuthProxy
2
+ module Validator
3
+ def rack_request
4
+ Rack::Request.new(env)
5
+ end
6
+
7
+ def valid_cookie?
8
+ rack_request.cookies['secret'] == '123'
9
+ end
10
+
11
+ def valid_callback?
12
+ env.fetch('omniauth.auth', {})['uid'] == '666397'
13
+ end
14
+
15
+ def authenticated?
16
+ valid_callback? || valid_cookie?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ class AuthProxy
2
+ VERSION = "0.1.0"
3
+ end
data/lib/auth_proxy.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'auth_proxy/version'
2
+ require 'rack'
3
+ require 'rack/reverse_proxy'
4
+ require 'rack/router'
5
+ require 'auth_proxy/callback'
6
+ require 'auth_proxy/proxy'
7
+ require 'auth_proxy/validator'
8
+
9
+ class AuthProxy
10
+ include AuthProxy::Validator
11
+
12
+ def initialize(options={})
13
+ @app = Rack::Router.new do
14
+ get "/auth/github/callback" => AuthProxy::Callback.new
15
+ options.keys.each do |path|
16
+ get path + '/*' => AuthProxy::Proxy.new(options)
17
+ end
18
+ end
19
+ end
20
+
21
+ def call(env)
22
+ @env = env
23
+ return authenticate unless authenticated?
24
+ @app.call(env)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :env
30
+
31
+ def authenticate
32
+ [ 301, {"Location" => rack_request.base_url + '/auth/github'}, [] ]
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auth_proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Karl Entwistle
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-github
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-reverse-proxy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-router
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.3.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.3.0
125
+ description: This is a simple reverse proxy for Rack. It is not meant for production
126
+ systems (although it may work), as the webserver fronting your app is generally
127
+ much better at this sort of thing.
128
+ email:
129
+ - karl@simpleweb.co.uk
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - auth_proxy.gemspec
143
+ - lib/auth_proxy.rb
144
+ - lib/auth_proxy/callback.rb
145
+ - lib/auth_proxy/proxy.rb
146
+ - lib/auth_proxy/validator.rb
147
+ - lib/auth_proxy/version.rb
148
+ homepage: https://github.com/karlentwistle/auth_proxy
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
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: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.6
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: simple reverse proxy for Rack.
172
+ test_files: []