Skip to content

Commit 62c4eca

Browse files
committed
replace httpclient with faraday v2 & remove MAC
1 parent c21f868 commit 62c4eca

31 files changed

+25
-903
lines changed

README.rdoc

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
= rack-oauth2
22

33
OAuth 2.0 Server & Client Library.
4-
Both Bearer and MAC token type are supported.
4+
Both Bearer token type are supported.
55

66
The OAuth 2.0 Authorization Framework (RFC 6749)
77
http://www.rfc-editor.org/rfc/rfc6749.txt
88

99
The OAuth 2.0 Authorization Framework: Bearer Token Usage (RFC 6750)
1010
http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-06
1111

12-
HTTP Authentication: MAC Access Authentication (draft 01)
13-
http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01
14-
1512
== Installation
1613

1714
gem install rack-oauth2
@@ -29,31 +26,17 @@ http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01
2926
Source on GitHub
3027
https://github.com/nov/rack-oauth2-sample
3128

32-
=== MAC
33-
34-
Source on GitHub
35-
https://github.com/nov/rack-oauth2-sample-mac
36-
3729
== Sample Client
3830

39-
=== Common between Bearer and MAC
40-
4131
Authorization Request (request_type: 'code' and 'token')
4232
https://gist.github.com/862393
4333

4434
Token Request (grant_type: 'client_credentials', 'password', 'authorization_code' and 'refresh_token')
4535
https://gist.github.com/883541
4636

47-
=== Bearer
48-
4937
Resource Request (request both for resource owner resource and for client resource)
5038
https://gist.github.com/883575
5139

52-
=== MAC
53-
54-
Resource Request (request both for resource owner resource and for client resource)
55-
https://gist.github.com/933885
56-
5740
== Note on Patches/Pull Requests
5841

5942
* Fork the project.

lib/rack/oauth2.rb

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'rack'
2-
require 'httpclient'
2+
require 'faraday'
3+
require 'faraday/follow_redirects'
34
require 'logger'
45
require 'active_support'
56
require 'active_support/core_ext'
@@ -40,18 +41,12 @@ def self.debug(&block)
4041
self.debugging = false
4142

4243
def self.http_client(agent_name = "Rack::OAuth2 (#{VERSION})", &local_http_config)
43-
_http_client_ = HTTPClient.new(
44-
agent_name: agent_name
45-
)
46-
47-
# NOTE: httpclient gem seems stopped maintaining root certtificate set, use OS default.
48-
_http_client_.ssl_config.clear_cert_store
49-
_http_client_.ssl_config.cert_store.set_default_paths
50-
51-
http_config.try(:call, _http_client_)
52-
local_http_config.try(:call, _http_client_) unless local_http_config.nil?
53-
_http_client_.request_filter << Debugger::RequestFilter.new if debugging?
54-
_http_client_
44+
Faraday.new(headers: {user_agent: agent_name}) do |faraday|
45+
faraday.response :logger, Rack::OAuth2.logger if debugging?
46+
faraday.adapter Faraday.default_adapter
47+
local_http_config&.call(faraday)
48+
http_config&.call(faraday)
49+
end
5550
end
5651

5752
def self.http_config(&block)
@@ -70,4 +65,3 @@ def self.reset_http_config!
7065
require 'rack/oauth2/server'
7166
require 'rack/oauth2/client'
7267
require 'rack/oauth2/access_token'
73-
require 'rack/oauth2/debugger'

lib/rack/oauth2/access_token.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def initialize(attributes = {})
1919
end
2020

2121
def httpclient
22-
@httpclient ||= Rack::OAuth2.http_client("#{self.class} (#{VERSION})") do |config|
23-
config.request_filter << Authenticator.new(self)
22+
@httpclient ||= Rack::OAuth2.http_client("#{self.class} (#{VERSION})") do |faraday|
23+
Authenticator.new(self).authenticate(faraday)
2424
end
2525
end
2626

@@ -39,6 +39,5 @@ def token_response(options = {})
3939

4040
require 'rack/oauth2/access_token/authenticator'
4141
require 'rack/oauth2/access_token/bearer'
42-
require 'rack/oauth2/access_token/mac'
4342
require 'rack/oauth2/access_token/legacy'
4443
require 'rack/oauth2/access_token/mtls'

lib/rack/oauth2/access_token/authenticator.rb

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@ def initialize(token)
66
@token = token
77
end
88

9-
# Callback called in HTTPClient (before sending a request)
10-
# request:: HTTP::Message
11-
def filter_request(request)
9+
def authenticate(request)
1210
@token.authenticate(request)
1311
end
14-
15-
# Callback called in HTTPClient (after received a response)
16-
# response:: HTTP::Message
17-
# request:: HTTP::Message
18-
def filter_response(response, request)
19-
# nothing to do
20-
end
2112
end
2213
end
2314
end

lib/rack/oauth2/access_token/bearer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module OAuth2
33
class AccessToken
44
class Bearer < AccessToken
55
def authenticate(request)
6-
request.header["Authorization"] = "Bearer #{access_token}"
6+
request.headers["Authorization"] = "Bearer #{access_token}"
77
end
88

99
def to_mtls(attributes = {})

lib/rack/oauth2/access_token/legacy.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(attributes = {})
1111
end
1212

1313
def authenticate(request)
14-
request.header["Authorization"] = "OAuth #{access_token}"
14+
request.headers["Authorization"] = "OAuth #{access_token}"
1515
end
1616
end
1717
end

lib/rack/oauth2/access_token/mac.rb

-103
This file was deleted.

lib/rack/oauth2/access_token/mac/sha256_hex_verifier.rb

-17
This file was deleted.

lib/rack/oauth2/access_token/mac/signature.rb

-34
This file was deleted.

lib/rack/oauth2/access_token/mac/verifier.rb

-44
This file was deleted.

lib/rack/oauth2/client.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def access_token!(*args)
7676
handle_response do
7777
http_client.post(
7878
absolute_uri_for(token_endpoint),
79-
Util.compact_hash(params),
79+
Util.compact_hash(params).to_query,
8080
headers
8181
)
8282
end
@@ -213,8 +213,6 @@ def handle_success_response(response)
213213
case (@forced_token_type || token_hash[:token_type]).try(:downcase)
214214
when 'bearer'
215215
AccessToken::Bearer.new(token_hash)
216-
when 'mac'
217-
AccessToken::MAC.new(token_hash)
218216
when nil
219217
AccessToken::Legacy.new(token_hash)
220218
else

lib/rack/oauth2/debugger.rb

-3
This file was deleted.

0 commit comments

Comments
 (0)