rack-oauth_proxy 0.2.0 → 0.2.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/CHANGELOG.md +3 -0
- data/README.md +18 -1
- data/lib/rack/oauth_proxy/client/request.rb +7 -1
- data/lib/rack/oauth_proxy/version.rb +1 -1
- data/spec/rack/oauth_proxy_spec.rb +24 -0
- 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: 91426d44a4b8cbc11799f55cdbd4ba31b258e049
|
4
|
+
data.tar.gz: e26e22d20803eb43ca6b4d908c57b812ebffce30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba13dd2cfece11a802b3a6da9602dd0693d1ea0165d500395efd1edd49e15c53b05ffb923d555142bf833f51342b52ce37fa8c1cf298f5b9f01f03e1b0858892
|
7
|
+
data.tar.gz: cfbc2b1746c623e4d567cdf7e4b62984374e274b32ce0b9c8cac1dcc281cdcb33b5e9cb711effc26a526832e5243cb6c80f5421dc79f52e693ccdb0fe66e4637
|
data/CHANGELOG.md
CHANGED
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
|
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(
|
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
|
@@ -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
|