forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_auth.rb
More file actions
31 lines (26 loc) · 743 Bytes
/
Copy pathbasic_auth.rb
File metadata and controls
31 lines (26 loc) · 743 Bytes
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
# encoding: utf-8
require 'faraday'
require 'base64'
module Github
module Request
class BasicAuth < Faraday::Middleware
dependency 'base64'
def call(env)
env[:request_headers].merge!('Authorization' => "Basic #{@auth}\"")
@app.call env
end
def initialize(app, *args)
@app = app
credentials = ""
options = args.extract_options!
if options.has_key? :login
credentials = "#{options[:login]}:#{options[:password]}"
elsif options.has_key? :basic_auth
credentials = "#{options[:basic_auth]}"
end
@auth = Base64.encode64(credentials)
@auth.gsub!("\n", "")
end
end # BasicAuth
end # Request
end # Github