Module: HTTPX::Plugins::Auth::OptionsMethods

Defined in:
lib/httpx/plugins/auth.rb

Overview

adds support for the following options:

:auth_header_value

the token to use as a string, or a callable which returns a string when called.

:auth_header_type

the authentication type to use in the “authorization” header value (i.e. “Bearer”, “Digest”…)

:auth_header_expires_at

timestamp at which the auth header will be discarded. should be a callable (like a proc) receiving the request as an argument, and should return either a Time object, or an integer (UNIX time).

:auth_header_expires_in

time (in seconds) since the first use of an auth header after which that header will be discarded.

:generate_auth_value_on_retry

callable which returns whether the request should regenerate the auth_header_value when the request is retried (this option will only work if the session also loads the :retries plugin).

Instance Method Summary collapse

Instance Method Details

#option_auth_header_expires_at(value) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/httpx/plugins/auth.rb', line 38

def option_auth_header_expires_at(value)
  unless value.respond_to?(:call)
    value = Float(value)
    raise TypeError, "`:auth_header_expires_at` must be positive" unless value.positive?
  end

  value
end

#option_auth_header_expires_in(value) ⇒ Object

Raises:

  • (TypeError)


47
48
49
50
51
52
# File 'lib/httpx/plugins/auth.rb', line 47

def option_auth_header_expires_in(value)
  value = Float(value)
  raise TypeError, "`:auth_header_expires_in` must be positive" unless value.positive?

  value
end

#option_auth_header_type(value) ⇒ Object



34
35
36
# File 'lib/httpx/plugins/auth.rb', line 34

def option_auth_header_type(value)
  value
end

#option_auth_header_value(value) ⇒ Object



30
31
32
# File 'lib/httpx/plugins/auth.rb', line 30

def option_auth_header_value(value)
  value
end

#option_generate_auth_value_on_retry(value) ⇒ Object

Raises:

  • (TypeError)


54
55
56
57
58
# File 'lib/httpx/plugins/auth.rb', line 54

def option_generate_auth_value_on_retry(value)
  raise TypeError, "`:generate_auth_value_on_retry` must be a callable" unless value.respond_to?(:call)

  value
end