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) {|arg0, arg1| ... } ⇒ instance

returns a new session where requests will be authorized using token (or what the blk yields), using auth_header_type as header value prefix.

Parameters:

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

Yields:

Yield Parameters:

  • arg0 (requestAuth)
  • arg1 (Boolean)

Yield Returns:

  • (string)

Returns:

  • (instance)


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

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) {|arg0| ... } ⇒ instance

returns a new session which call #authorize while setting "Bearer" as the auth_header_type.

Parameters:

  • token (string) (defaults to: nil)

Yields:

Yield Parameters:

  • arg0 (requestAuth)

Yield Returns:

  • (string)

Returns:

  • (instance)


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

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

#initialize ⇒ Object



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.

resets authorization information.



92
93
94
95
96
# File 'lib/httpx/plugins/auth.rb', line 92

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

#skip_auth_header { ... } ⇒ T

yields a block where authorization (if available) will be bypassed.

Yields:

Yield Returns:

  • (T)

Returns:

  • (T)


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

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