class Gems::OTPAuthenticator

Authenticator that adds a one-time passcode for multi-factor authentication

Wraps another authenticator and adds the OTP header to its headers.

@api private

Attributes

The authenticator providing the underlying credentials @api private @return [Authenticator] the wrapped authenticator @example Get the wrapped authenticator

authenticator.authenticator

The one-time passcode @api private @return [String] the one-time passcode @example Get the one-time passcode

authenticator.otp

Public Class Methods

Initialize a new OTPAuthenticator

@api private @param authenticator [Authenticator] the authenticator providing the underlying credentials @param otp [String] the one-time passcode @return [OTPAuthenticator] a new instance @example Create an OTP authenticator around an API key authenticator

authenticator = Gems::OTPAuthenticator.new(authenticator: Gems::APIKeyAuthenticator.new(key: "key"), otp: "123456")
# File lib/gems/otp_authenticator.rb, line 38
def initialize(authenticator:, otp:)
  @authenticator = authenticator
  @otp = otp
end

Public Instance Methods

Generate the authentication headers for a request

@api private @param request [Net::HTTPRequest] the HTTP request @return [Hash{String => String}] the wrapped authenticator’s headers plus the OTP header @example Generate authentication headers with a one-time passcode

authenticator.header(request)
# File lib/gems/otp_authenticator.rb, line 50
def header(request)
  authenticator.header(request).merge(OTP_HEADER => otp)
end

Summarize the authenticator for the console

@api private @return [String] the summary, which includes the wrapped authenticator but not the passcode @example Inspect an OTP authenticator

authenticator.inspect # => #<Gems::OTPAuthenticator authenticator=#<Gems::APIKeyAuthenticator>>
# File lib/gems/otp_authenticator.rb, line 60
def inspect
  "#<#{self.class} authenticator=#{authenticator.inspect}>"
end