rack-token_auth 0.0.1 → 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGNlZmQzMzc0NTE5ZDFlMzU4NWZjNmEwNzFkMmQ2MTExMjQwZDQ2YQ==
5
+ data.tar.gz: !binary |-
6
+ YTVhYzM0ZjI1OTExMTJjMzk5MjY3N2JjY2VkZThmYzM0NDBkNTM2NQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTc4YjI2ZDcyYjdmMGU3MjI5YmI3NDIyMTNjMWFjYzY3NzFiYzljY2Q3MzA2
10
+ MGI2YjUyZTc5ZThkNGQzOWU5YWRhMmY4MDYwMzVjOGFlOWZiMTE5MjE0OTYx
11
+ ZjcyNWZhMjI4NmQ3N2JkZDIxZmEwZGQwNDgxYzk1NDMzZjhhZTA=
12
+ data.tar.gz: !binary |-
13
+ YWUzN2E5NTA1OTcwOGUwYzdkOGJiMTVlZjM3OGI2MzhjYTNjYzNjYjNiOWI2
14
+ MzE3YjNlYzUyM2VjMDI3NzZlNWMwNjA0MGFmYzEzZTMyM2VlZDc4MDQzMWYw
15
+ OWE5Yjg3MmZiYzM2N2JkYTcwMDNlNmE3NTA4MTI5MDk3NTliNDY=
data/README.md CHANGED
@@ -19,7 +19,7 @@ Add to your middleware chain, add it to `config.ru`:
19
19
  ``` ruby
20
20
  require 'rack/token_auth'
21
21
 
22
- use Rack::TokenAuth do |token, options|
22
+ use Rack::TokenAuth do |token, options, env|
23
23
  token == "my secret token"
24
24
  end
25
25
 
@@ -32,7 +32,7 @@ returns false, the request will halt with a 401 (Unauthorized) response.
32
32
  If you're using Rails, add to `config/environments/production.rb`:
33
33
 
34
34
  ``` ruby
35
- config.middleware.use Rack::TokenAuth do |token, options|
35
+ config.middleware.use Rack::TokenAuth do |token, options, env|
36
36
  # etc...
37
37
  end
38
38
  ```
@@ -43,8 +43,8 @@ The response in case of an unauthorized request can be modified, by specifying
43
43
  a Rack app, like this:
44
44
 
45
45
  ``` ruby
46
- unauthorized_app = lambda { |env| [ 401, {}, ["Please speak to our sales dep. for access"] }
47
- use Rack::TokenAuth, :unauthorized_app => unauthorized_app do |token, options|
46
+ unauthorized_app = lambda { |env| [ 401, {}, ["Please speak to our sales dep. for access"] ] }
47
+ use Rack::TokenAuth, :unauthorized_app => unauthorized_app do |token, options, env|
48
48
  # etc...
49
49
  end
50
50
  ```
@@ -53,8 +53,8 @@ If the authorization header is malformed, the middleware chain will also be
53
53
  halted and a 400 response will be returned. You can also specify this:
54
54
 
55
55
  ``` ruby
56
- unprocessable_header_app = lambda { |env| [ 400, {}, ["You idiot!"] }
57
- use Rack::TokenAuth, :unprocessable_header_app => unprocessable_header_app do |token, options|
56
+ unprocessable_header_app = lambda { |env| [ 400, {}, ["You idiot!"] ] }
57
+ use Rack::TokenAuth, :unprocessable_header_app => unprocessable_header_app do |token, options, env|
58
58
  # etc...
59
59
  end
60
60
  ```
@@ -12,12 +12,13 @@ module Rack
12
12
  end
13
13
 
14
14
  def call(env)
15
- if @block.call(*token_and_options(env["HTTP_AUTHORIZATION"]))
15
+ token, options = *token_and_options(env["HTTP_AUTHORIZATION"])
16
+ if @block.call(token, options, env)
16
17
  @app.call(env)
17
18
  else
18
19
  unauthorized_app.call(env)
19
20
  end
20
- rescue UnprocessableHeader => error
21
+ rescue UnprocessableHeader
21
22
  unprocessable_header_app.call(env)
22
23
  end
23
24
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class TokenAuth
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -11,18 +11,21 @@ describe Rack::TokenAuth do
11
11
  let(:app) { build_app(&block) }
12
12
 
13
13
  it "evaluates the block with token and options" do
14
- block.should_receive(:call).with("abc", "foo" => "bar")
15
- app.call("HTTP_AUTHORIZATION" => %(Token token="abc", foo="bar"))
14
+ env = { "HTTP_AUTHORIZATION" => %(Token token="abc", foo="bar") }
15
+ block.should_receive(:call).with("abc", {"foo" => "bar"}, env)
16
+ app.call(env)
16
17
  end
17
18
 
18
19
  it "handles absent header" do
19
- block.should_receive(:call).with(nil, {})
20
- app.call({})
20
+ env = {}
21
+ block.should_receive(:call).with(nil, {}, env)
22
+ app.call(env)
21
23
  end
22
24
 
23
25
  it "handles other authorization header" do
24
- block.should_receive(:call).with(nil, {})
25
- app.call("HTTP_AUTHORIZATION" => %(Basic QWxhZGluOnNlc2FtIG9wZW4=))
26
+ env = { "HTTP_AUTHORIZATION" => %(Basic QWxhZGluOnNlc2FtIG9wZW4=) }
27
+ block.should_receive(:call).with(nil, {}, env)
28
+ app.call(env)
26
29
  end
27
30
 
28
31
  it "handles misformed authorization header" do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-token_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - iain
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-20 00:00:00.000000000 Z
11
+ date: 2013-05-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -79,27 +72,27 @@ files:
79
72
  - spec/rack_token_auth_spec.rb
80
73
  homepage: https://github.com/iain/rack-token_auth
81
74
  licenses: []
75
+ metadata: {}
82
76
  post_install_message:
83
77
  rdoc_options: []
84
78
  require_paths:
85
79
  - lib
86
80
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
81
  requirements:
89
82
  - - ! '>='
90
83
  - !ruby/object:Gem::Version
91
84
  version: '0'
92
85
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
86
  requirements:
95
87
  - - ! '>='
96
88
  - !ruby/object:Gem::Version
97
89
  version: '0'
98
90
  requirements: []
99
91
  rubyforge_project:
100
- rubygems_version: 1.8.23
92
+ rubygems_version: 2.0.3
101
93
  signing_key:
102
- specification_version: 3
94
+ specification_version: 4
103
95
  summary: Rack middleware for using the Authorization header with token authentication
104
96
  test_files:
105
97
  - spec/rack_token_auth_spec.rb
98
+ has_rdoc: