rack-oauth_proxy 0.2.0 → 0.2.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: 99386f17d5ddd6f0ddc8308d40ebdeaedfd48e20
4
- data.tar.gz: a4c3ddb81f3c181adc915c84ff1f7b3fca6c92f8
3
+ metadata.gz: 91426d44a4b8cbc11799f55cdbd4ba31b258e049
4
+ data.tar.gz: e26e22d20803eb43ca6b4d908c57b812ebffce30
5
5
  SHA512:
6
- metadata.gz: 4088da5b01435bd30d7160742a260a2f4f2e6069fab7821cb244f8f0c44439d962192ae68753b7c5fe5181ca35b9f07adb21d9037b0901a4dc59713c3e4ef873
7
- data.tar.gz: 770fcd4e6ddf166764ce63ea4da869da42aa4d229b16700219196eb6c4b9895359798a4053896a59893cfc849d0f8de7db70e64865974e7aac51dbef0ad53479
6
+ metadata.gz: ba13dd2cfece11a802b3a6da9602dd0693d1ea0165d500395efd1edd49e15c53b05ffb923d555142bf833f51342b52ce37fa8c1cf298f5b9f01f03e1b0858892
7
+ data.tar.gz: cfbc2b1746c623e4d567cdf7e4b62984374e274b32ce0b9c8cac1dcc281cdcb33b5e9cb711effc26a526832e5243cb6c80f5421dc79f52e693ccdb0fe66e4637
@@ -1,3 +1,6 @@
1
+ ## 0.2.1
2
+ * Add `:propagated_params` option
3
+
1
4
  ## 0.2.0
2
5
  * `env["rack-oauth_proxy.response"]` is a Faraday::Response
3
6
 
data/README.md CHANGED
@@ -6,7 +6,24 @@ Delegates OAuth authentication to other authentication server.
6
6
  For Rails example:
7
7
 
8
8
  ```ruby
9
- class ApplicationController < ActionController::Base
9
+ class BlogsController < ApplicationController
10
10
  use Rack::OauthProxy, url: "http://auth.example.com/oauth/token"
11
+
12
+ before_action :require_authorization
13
+
14
+ def show
15
+ ...
16
+ end
17
+
18
+ private
19
+
20
+ def require_authorization
21
+ raise UnauthorizedError unless has_authorization?
22
+ end
23
+
24
+ # env["rack-oauth_proxy.resopnse"] is a Faraday::Response object.
25
+ def has_authorization?
26
+ env["rack-oauth_proxy.resopnse"].status == 200
27
+ end
11
28
  end
12
29
  ```
@@ -8,6 +8,8 @@ module Rack
8
8
  class Request
9
9
  DEFAULT_PROPAGATED_HEADER_FIELDS = ["Authorization"]
10
10
 
11
+ DEFAULT_PROPAGATED_PARAMS = ["access_token", "bearer_token"]
12
+
11
13
  attr_reader :env, :options
12
14
 
13
15
  def initialize(env, options = {})
@@ -26,7 +28,7 @@ module Rack
26
28
  end
27
29
 
28
30
  def params
29
- rack_request.params.slice("access_token", "bearer_token")
31
+ rack_request.params.slice(*propagated_params)
30
32
  end
31
33
 
32
34
  private
@@ -38,6 +40,10 @@ module Rack
38
40
  def propagated_header_fields
39
41
  options[:propagated_header_fields] || DEFAULT_PROPAGATED_HEADER_FIELDS
40
42
  end
43
+
44
+ def propagated_params
45
+ options[:propagated_params] || DEFAULT_PROPAGATED_PARAMS
46
+ end
41
47
  end
42
48
  end
43
49
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class OauthProxy
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -28,10 +28,15 @@ describe Rack::OauthProxy do
28
28
  {
29
29
  "HTTP_AUTHORIZATION" => "Bearer #{token}",
30
30
  "HTTP_DUMMY" => "dummy",
31
+ "QUERY_STRING" => query_string,
31
32
  "rack.input" => StringIO.new,
32
33
  }
33
34
  end
34
35
 
36
+ let(:query_string) do
37
+ ""
38
+ end
39
+
35
40
  let(:token) do
36
41
  SecureRandom.hex(32)
37
42
  end
@@ -94,5 +99,24 @@ describe Rack::OauthProxy do
94
99
  a_request(:get, url).with(headers: { "DUMMY" => "dummy" }).should have_been_made
95
100
  end
96
101
  end
102
+
103
+ context "with propagated params option" do
104
+ before do
105
+ options[:propagated_params] = ["access_token"]
106
+ end
107
+
108
+ let(:url) do
109
+ "http://example.com/oauth/token?access_token=#{token}"
110
+ end
111
+
112
+ let(:query_string) do
113
+ "access_token=#{token}"
114
+ end
115
+
116
+ it "propagates specified params" do
117
+ result.should be_a Faraday::Response
118
+ a_request(:get, url).should have_been_made
119
+ end
120
+ end
97
121
  end
98
122
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-oauth_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura