module HTTPX::Plugins::Auth::InstanceMethods

  1. lib/httpx/plugins/auth.rb

Public Class methods

new(*)
[show source]
   # File lib/httpx/plugins/auth.rb
64 def initialize(*)
65   super
66 
67   @auth_header_value = @auth_header_expires_at = nil
68   @auth_header_value_mtx = Thread::Mutex.new
69   @skip_auth_header_value = false
70 end

Public Instance methods

authorization(token = nil, auth_header_type: nil, &blk)

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

[show source]
   # File lib/httpx/plugins/auth.rb
74 def authorization(token = nil, auth_header_type: nil, &blk)
75   with(auth_header_type: auth_header_type, auth_header_value: token || blk)
76 end
bearer_auth(token = nil, &blk)

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

[show source]
   # File lib/httpx/plugins/auth.rb
79 def bearer_auth(token = nil, &blk)
80   authorization(token, auth_header_type: "Bearer", &blk)
81 end
reset_auth_header_value!()

resets authorization information.

[show source]
   # File lib/httpx/plugins/auth.rb
92 def reset_auth_header_value!
93   @auth_header_value_mtx.synchronize do
94     @auth_header_value = @auth_header_expires_at = nil
95   end
96 end
skip_auth_header()

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

[show source]
   # File lib/httpx/plugins/auth.rb
84 def skip_auth_header
85   @skip_auth_header_value = true
86   yield
87 ensure
88   @skip_auth_header_value = false
89 end