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)


70
71
72
# File 'lib/httpx/plugins/auth.rb', line 70

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)


74
75
76
# File 'lib/httpx/plugins/auth.rb', line 74

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)


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

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

#generate_auth_tokenString?

Returns:

  • (String, nil)


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

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

  auth_value = auth_value.call(self) if dynamic_auth_token?(auth_value)

  auth_value
end

#initializeObject



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

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.



85
86
87
88
89
# File 'lib/httpx/plugins/auth.rb', line 85

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.



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

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