@@ -11,49 +11,37 @@ class HttpBasic
11
11
option :title , "Http Basic"
12
12
option :headers , { }
13
13
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
20
19
21
20
def callback_phase
22
21
return fail! ( :invalid_credentials ) if !authentication_response
23
- return fail! ( :invalid_credentials ) if authentication_response . code . to_i >= 400
24
22
super
25
23
end
26
24
27
25
protected
28
26
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
33
30
end
34
31
35
32
def username
36
- request [ 'username' ]
33
+ user_name_and_password . first
37
34
end
38
35
39
36
def password
40
- request [ 'password' ]
37
+ user_name_and_password . last
41
38
end
42
39
43
40
def authentication_response
44
41
unless @authentication_response
45
42
return unless username && password
46
43
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 )
57
45
end
58
46
59
47
@authentication_response
0 commit comments