Class: Hooksmith::Verifiers::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/hooksmith/verifiers/base.rb

Overview

This class is abstract.

Subclass and override #verify! to implement custom verification.

Base class for webhook request verifiers.

Verifiers are responsible for authenticating incoming webhook requests before they are processed. Each provider can have its own verifier configured to handle provider-specific authentication schemes.

Examples:

Creating a custom verifier

class MyCustomVerifier < Hooksmith::Verifiers::Base
  def verify!(request)
    token = request.headers['X-Custom-Token']
    raise Hooksmith::VerificationError, 'Invalid token' unless valid_token?(token)
  end

  private

  def valid_token?(token)
    token == @options[:expected_token]
  end
end

Direct Known Subclasses

BearerToken, Hmac

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Base

Initializes the verifier with options.

Parameters:

  • options (Hash)

    verifier-specific options



34
35
36
# File 'lib/hooksmith/verifiers/base.rb', line 34

def initialize(**options)
  @options = options
end

Instance Attribute Details

#optionsHash (readonly)

Returns options passed to the verifier.

Returns:

  • (Hash)

    options passed to the verifier



29
30
31
# File 'lib/hooksmith/verifiers/base.rb', line 29

def options
  @options
end

Instance Method Details

#enabled?Boolean

Returns whether the verifier is configured and should be used.

Returns:

  • (Boolean)

    true if the verifier should be applied



50
51
52
# File 'lib/hooksmith/verifiers/base.rb', line 50

def enabled?
  true
end

#verify!(request) ⇒ void

This method returns an undefined value.

Verifies the incoming webhook request.

Parameters:

Raises:



43
44
45
# File 'lib/hooksmith/verifiers/base.rb', line 43

def verify!(request)
  raise NotImplementedError, 'Subclasses must implement #verify!'
end