Skip to content

Commit f4e3062

Browse files
committed
WIP
Ale and I spent some time spiking out our own http basic omni strategy for the Doblet API.
1 parent d1c407c commit f4e3062

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

lib/omniauth/strategies/http_basic.rb

+11-23
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,37 @@ class HttpBasic
1111
option :title, "Http Basic"
1212
option :headers, {}
1313

14-
def request_phase
15-
OmniAuth::Form.build(:title => options.title, :url => callback_path) do
16-
text_field 'Username', 'username'
17-
password_field 'Password', 'password'
18-
end.to_response
19-
end
14+
# NOT IMPLEMENTED FOR HTTP BASIC
15+
# There's no need to make a request as the username and password are
16+
# encoded in the HTTP Authentication header.
17+
# def request_phase
18+
# end
2019

2120
def callback_phase
2221
return fail!(:invalid_credentials) if !authentication_response
23-
return fail!(:invalid_credentials) if authentication_response.code.to_i >= 400
2422
super
2523
end
2624

2725
protected
2826

29-
# by default we use static uri. If dynamic uri is required, override
30-
# this method.
31-
def api_uri
32-
options.endpoint
27+
def user_name_and_password
28+
# TODO: hard dependency on Rails. is this okay?
29+
@user_name_and_password ||= HttpAuthentication::Basic.user_name_and_password
3330
end
3431

3532
def username
36-
request['username']
33+
user_name_and_password.first
3734
end
3835

3936
def password
40-
request['password']
37+
user_name_and_password.last
4138
end
4239

4340
def authentication_response
4441
unless @authentication_response
4542
return unless username && password
4643

47-
uri = URI(api_uri)
48-
http = Net::HTTP.new(uri.host, uri.port)
49-
if uri.scheme == 'https'
50-
http.use_ssl = true
51-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52-
end
53-
54-
req = Net::HTTP::Get.new(uri.request_uri)
55-
req.basic_auth username, password
56-
@authentication_response = http.request(req)
44+
@authentication_response = User.authenticate(username, password)
5745
end
5846

5947
@authentication_response

0 commit comments

Comments
 (0)