Module: HTTPX::Plugins::Auth::InstanceMethods

Defined in:
lib/httpx/plugins/auth.rb,
sig/plugins/auth.rbs

Instance Method Summary collapse

Instance Method Details

#authorization(token = nil, auth_header_type: nil, &blk) ⇒ void

This method returns an undefined value.

Parameters:

  • token (string) (defaults to: nil)
  • auth_header_type: (string) (defaults to: nil)


72
73
74
# File 'lib/httpx/plugins/auth.rb', line 72

def authorization(token = nil, auth_header_type: nil, &blk)
  with(auth_header_type: auth_header_type, auth_header_value: token || blk)
end

#bearer_auth(token = nil, &blk) ⇒ void

This method returns an undefined value.

Parameters:

  • token (string) (defaults to: nil)


76
77
78
# File 'lib/httpx/plugins/auth.rb', line 76

def bearer_auth(token = nil, &blk)
  authorization(token, auth_header_type: "Bearer", &blk)
end

#dynamic_auth_token?(auth_header_value) ⇒ Boolean

Parameters:

  • auth_header_value (auth_header_value_type)

Returns:

  • (Boolean)


140
141
142
# File 'lib/httpx/plugins/auth.rb', line 140

def dynamic_auth_token?(auth_header_value)
  auth_header_value&.respond_to?(:call)
end

#generate_auth_token(request, should_regenerate) ⇒ String?

Parameters:

Returns:

  • (String, nil)


119
120
121
122
123
124
125
# File 'lib/httpx/plugins/auth.rb', line 119

def generate_auth_token(request, should_regenerate)
  return unless (auth_value = @options.auth_header_value)

  auth_value = auth_value.call(request, should_regenerate) if dynamic_auth_token?(auth_value)

  auth_value
end

#initializeObject



64
65
66
67
68
69
70
# File 'lib/httpx/plugins/auth.rb', line 64

def initialize(*)
  super

  @auth_header_value = @auth_header_expires_at = nil
  @auth_header_value_mtx = Thread::Mutex.new
  @skip_auth_header_value = false
end

#reset_auth_header_value!void

This method returns an undefined value.



87
88
89
90
91
# File 'lib/httpx/plugins/auth.rb', line 87

def reset_auth_header_value!
  @auth_header_value_mtx.synchronize do
    @auth_header_value = @auth_header_expires_at = nil
  end
end

#skip_auth_headervoid

This method returns an undefined value.



80
81
82
83
84
85
# File 'lib/httpx/plugins/auth.rb', line 80

def skip_auth_header
  @skip_auth_header_value = true
  yield
ensure
  @skip_auth_header_value = false
end