Class: Gruf::Rspec::AuthenticationHydrators::Basic

Inherits:
Base
  • Object
show all
Defined in:
lib/gruf/rspec/authentication_hydrators/basic.rb

Overview

Automatically hydrate request metadata with basic authentication options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Gruf::Rspec::AuthenticationHydrators::Base

Instance Method Details

#hydrate(metadata) ⇒ Hash

Returns The hydrated metadata.

Parameters:

  • metadata (Hash)

    The incoming request metadata

Returns:

  • (Hash)

    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