Class: Gruf::Rspec::AuthenticationHydrators::Basic
- Defined in:
- lib/gruf/rspec/authentication_hydrators/basic.rb
Overview
Automatically hydrate request metadata with basic authentication options
Instance Method Summary collapse
-
#hydrate(metadata) ⇒ Hash
The hydrated metadata.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Gruf::Rspec::AuthenticationHydrators::Base
Instance Method Details
#hydrate(metadata) ⇒ Hash
Returns The hydrated metadata.
31 32 33 34 35 36 37 |
# File 'lib/gruf/rspec/authentication_hydrators/basic.rb', line 31 def hydrate() username = auth_opts.fetch(:username, '') password = auth_opts.fetch(:password, '') auth_string = username.to_s.empty? ? password : "#{username}:#{password}" [auth_opts.fetch(:header_key, 'authorization').to_s] = "Basic #{::Base64.encode64(auth_string)}" unless auth_string.empty? end |