auth_proxy 0.1.0 → 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 +4 -4
- data/README.md +5 -4
- data/lib/auth_proxy.rb +11 -5
- data/lib/auth_proxy/callback.rb +10 -2
- data/lib/auth_proxy/validator.rb +1 -1
- data/lib/auth_proxy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 525f700cc84f6d0717419c143cb2513cffe5701e
|
4
|
+
data.tar.gz: 4574213b55341538987dba99ce21ca764554d588
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f316ca66c878adc9860a3f8f9403b4fe2a8529904b2d6690a3d262aba6de0332ec3aa764f859724e821880dbd390727723259d13df6e4c09a87f57a4251d499
|
7
|
+
data.tar.gz: 3ca8fa9516719bcd687b0954dcbf7269c460c73871c96c124c676355ed3429ef8c8f7d75d3fa75168a1c8b2f5edf984a627a37c0d672c5759c189e4a5ead6333
|
data/README.md
CHANGED
@@ -5,20 +5,21 @@ This is a simple reverse proxy for Rack. It is not meant for production systems
|
|
5
5
|
## Example usage
|
6
6
|
|
7
7
|
````ruby
|
8
|
-
|
8
|
+
require 'auth_proxy'
|
9
|
+
require 'omniauth-github'
|
9
10
|
|
10
|
-
use Rack::Session::Cookie, secret
|
11
|
+
use Rack::Session::Cookie, :secret => 'change_me'
|
11
12
|
|
12
13
|
use OmniAuth::Builder do
|
13
14
|
provider:github, 'key', 'secret'
|
14
15
|
end
|
15
16
|
|
16
|
-
run AuthProxy.new({
|
17
|
+
run AuthProxy.new(secret: 'change_me', {
|
17
18
|
'/doodles' => 'https://www.google.com/'
|
18
19
|
})
|
19
20
|
````
|
20
21
|
|
21
|
-
Would automatically proxy requests
|
22
|
+
Would automatically proxy requests
|
22
23
|
- http://localhost/doodles => https://www.google.com/doodles
|
23
24
|
- http://localhost/doodles/static/styles.css => https://www.google.com/doodles/static/styles.css
|
24
25
|
|
data/lib/auth_proxy.rb
CHANGED
@@ -9,11 +9,13 @@ require 'auth_proxy/validator'
|
|
9
9
|
class AuthProxy
|
10
10
|
include AuthProxy::Validator
|
11
11
|
|
12
|
-
def initialize(
|
12
|
+
def initialize(auth_options={}, host_options={})
|
13
|
+
@auth_options = auth_options
|
14
|
+
|
13
15
|
@app = Rack::Router.new do
|
14
|
-
get "/auth/github/callback" => AuthProxy::Callback.new
|
15
|
-
|
16
|
-
get path + '/*' => AuthProxy::Proxy.new(
|
16
|
+
get "/auth/github/callback" => AuthProxy::Callback.new(auth_options)
|
17
|
+
host_options.keys.each do |path|
|
18
|
+
get path + '/*' => AuthProxy::Proxy.new(host_options)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -26,7 +28,11 @@ class AuthProxy
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
|
-
attr_reader :env
|
31
|
+
attr_reader :env, :auth_options
|
32
|
+
|
33
|
+
def secret_cookie
|
34
|
+
auth_options.fetch(:secret, 'change_me')
|
35
|
+
end
|
30
36
|
|
31
37
|
def authenticate
|
32
38
|
[ 301, {"Location" => rack_request.base_url + '/auth/github'}, [] ]
|
data/lib/auth_proxy/callback.rb
CHANGED
@@ -4,13 +4,17 @@ class AuthProxy
|
|
4
4
|
class Callback
|
5
5
|
include AuthProxy::Validator
|
6
6
|
|
7
|
+
def initialize(auth_options={}, host_options={})
|
8
|
+
@auth_options = auth_options
|
9
|
+
end
|
10
|
+
|
7
11
|
def call(env)
|
8
12
|
@env = env
|
9
13
|
|
10
14
|
response = Rack::Response.new
|
11
15
|
|
12
16
|
if valid_callback?
|
13
|
-
response.set_cookie('secret', {path: '/', value:
|
17
|
+
response.set_cookie('secret', {path: '/', value: secret_cookie})
|
14
18
|
end
|
15
19
|
|
16
20
|
response.status = 301
|
@@ -21,6 +25,10 @@ class AuthProxy
|
|
21
25
|
|
22
26
|
private
|
23
27
|
|
24
|
-
|
28
|
+
def secret_cookie
|
29
|
+
auth_options.fetch(:secret, 'change_me')
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :env, :auth_options
|
25
33
|
end
|
26
34
|
end
|
data/lib/auth_proxy/validator.rb
CHANGED
data/lib/auth_proxy/version.rb
CHANGED