Class: Zaikio::Hub::BasicAuthMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/zaikio/hub/basic_auth_middleware.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.credentialsObject



7
8
9
10
# File 'lib/zaikio/hub/basic_auth_middleware.rb', line 7

def self.credentials
  @credentials ||= Concurrent::ThreadLocalVar.new { nil }
  @credentials.value
end

.credentials=(value) ⇒ Object



12
13
14
15
# File 'lib/zaikio/hub/basic_auth_middleware.rb', line 12

def self.credentials=(value)
  @credentials ||= Concurrent::ThreadLocalVar.new { nil }
  @credentials.value = value
end

.reset_credentialsObject



17
18
19
# File 'lib/zaikio/hub/basic_auth_middleware.rb', line 17

def self.reset_credentials
  self.credentials = nil
end

Instance Method Details

#call(request_env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/zaikio/hub/basic_auth_middleware.rb', line 21

def call(request_env)
  if self.class.credentials
    value = Base64.encode64(self.class.credentials.join(":"))
    value.delete!("\n")
    request_env[:request_headers]["Authorization"] = "Basic #{value}"
  end

  @app.call(request_env).on_complete do |response_env|
  end
end