Class: Gruf::Authentication::Basic

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

Overview

Handles basic authentication for gRPC requests

Instance Attribute Summary

Attributes inherited from Base

#credentials, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, verify

Methods included from Loggable

#logger

Constructor Details

This class inherits a constructor from Gruf::Authentication::Base

Instance Method Details

#valid?(_call) ⇒ Boolean

Parameters:

  • _call (GRPC::ActiveCall)

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gruf/authentication/basic.rb', line 29

def valid?(_call)
  server_credentials.any? do |cred|
    username = cred.fetch(:username, '').to_s
    password = cred.fetch(:password, '').to_s
    if username.empty?
      request_password == password
    else
      request_credentials == "#{username}:#{password}"
    end
  end
end