Class: Gruf::Authentication::Base

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/gruf/authentication/base.rb

Overview

Base interface for Authentication strategies. All derived strategies must define the ‘valid?` method.

Direct Known Subclasses

Basic, None

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(credentials, options = {}) ⇒ Base

Initialize the authentication middleware

Parameters:

  • credentials (String)

    The credentials sent in the request

  • options (Hash) (defaults to: {})

    A hash of authentication options



36
37
38
39
40
# File 'lib/gruf/authentication/base.rb', line 36

def initialize(credentials, options = {})
  opts = Gruf.authentication_options || {}
  @credentials = credentials
  @options = opts.merge(options)
end

Instance Attribute Details

#credentialsString (readonly)

Returns The credentials sent in the request.

Returns:

  • (String)

    The credentials sent in the request



26
27
28
# File 'lib/gruf/authentication/base.rb', line 26

def credentials
  @credentials
end

#optionsHash (readonly)

Returns A hash of authentication options.

Returns:

  • (Hash)

    A hash of authentication options



28
29
30
# File 'lib/gruf/authentication/base.rb', line 28

def options
  @options
end

Class Method Details

.verify(call, credentials = '', options = {}) ⇒ Object

Verify the credentials. Helper class method.

Parameters:

  • call (GRPC::ActiveCall)

    The gRPC active call for the given operation

  • credentials (String) (defaults to: '')

    The credentials sent in the request

  • options (Hash) (defaults to: {})

    A hash of authentication options



49
50
51
# File 'lib/gruf/authentication/base.rb', line 49

def self.verify(call, credentials = '', options = {})
  new(credentials, options).valid?(call)
end

Instance Method Details

#valid?(_call) ⇒ Boolean

Abstract method that is required to be implemented in every derivative class. Return true if the call is authenticated, false if a permission denied error is to be sent.

Parameters:

  • _call (GRPC::ActiveCall)

    The gRPC active call for the given operation

Returns:

  • (Boolean)

    True if the call was authenticated

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/gruf/authentication/base.rb', line 60

def valid?(_call)
  raise NotImplementedError
end