forked from omniauth/omniauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_basic.rb
33 lines (26 loc) · 790 Bytes
/
http_basic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'restclient'
module OmniAuth
module Strategies
class HttpBasic
include OmniAuth::Strategy
def initialize(app, name, endpoint, headers = {})
super
@endpoint = endpoint
@request_headers = headers
end
attr_reader :endpoint, :request_headers
def request_phase
@response = RestClient.get(endpoint, request_headers)
request.POST['auth'] = auth_hash
@env['REQUEST_METHOD'] = 'GET'
@env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
@app.call(@env)
rescue RestClient::Request::Unauthorized
fail!(:invalid_credentials)
end
def callback_phase
[401, {}, 'Unauthorized']
end
end
end
end