auth_proxy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba659f59091d66a0ceac172732b28d56c1d97808
4
- data.tar.gz: 862403034b1bcbeaa55aea3d26abfec5922c86ff
3
+ metadata.gz: 525f700cc84f6d0717419c143cb2513cffe5701e
4
+ data.tar.gz: 4574213b55341538987dba99ce21ca764554d588
5
5
  SHA512:
6
- metadata.gz: 66354bb618bf0cdf498ed6bd9b67a171c1501619ec779ff2bac1d2a740efc890dfdeee5dbc62228403b38d09923a520ce25d942efc960994478a42668c71bcdd
7
- data.tar.gz: 14074aa6997ed8d5fc858de20ff12ede1dbd9f23fbba8ca0d0784dbf18bdf7ab1172dfddd861d9c332c5fba3e078bad9443adcbea78292c832ad1491058032ff
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
- require_relative 'lib/auth_proxy'
8
+ require 'auth_proxy'
9
+ require 'omniauth-github'
9
10
 
10
- use Rack::Session::Cookie, secret: 'change_me'
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
 
@@ -9,11 +9,13 @@ require 'auth_proxy/validator'
9
9
  class AuthProxy
10
10
  include AuthProxy::Validator
11
11
 
12
- def initialize(options={})
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
- options.keys.each do |path|
16
- get path + '/*' => AuthProxy::Proxy.new(options)
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'}, [] ]
@@ -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: '123'})
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
- attr_reader :env
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
@@ -5,7 +5,7 @@ class AuthProxy
5
5
  end
6
6
 
7
7
  def valid_cookie?
8
- rack_request.cookies['secret'] == '123'
8
+ rack_request.cookies['secret'] == secret_cookie
9
9
  end
10
10
 
11
11
  def valid_callback?
@@ -1,3 +1,3 @@
1
1
  class AuthProxy
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle