Module: HTTPX::Plugins::OAuth::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#initializeObject



242
243
244
245
246
247
248
249
250
# File 'lib/httpx/plugins/oauth.rb', line 242

def initialize(*)
  super

  @oauth_session = if @options.oauth_options
    OAuthSession.new(**@options.oauth_options)
  elsif @options.oauth_session
    @oauth_session = @options.oauth_session.dup
  end
end

#initialize_dup(other) ⇒ Object



252
253
254
255
# File 'lib/httpx/plugins/oauth.rb', line 252

def initialize_dup(other)
  super
  @oauth_session = other.instance_variable_get(:@oauth_session).dup
end

#oauth_auth(**args) ⇒ Object



257
258
259
260
261
262
# File 'lib/httpx/plugins/oauth.rb', line 257

def oauth_auth(**args)
  warn "DEPRECATION WARNING: `#{__method__}` is deprecated. " \
       "Use `with(oauth_options: options)` instead."

  with(oauth_options: args)
end

#refresh_oauth_tokens!Object

will eagerly negotiate new oauth tokens with the issuer



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/httpx/plugins/oauth.rb', line 265

def refresh_oauth_tokens!
  return unless @oauth_session

  @oauth_session.reset!
  @oauth_session.fetch_access_token(self)
  if (expires_at = @oauth_session.expires_at)
    @auth_header_value_mtx.synchronize do
      @auth_header_expires_at = expires_at
    end
  end
end

#reset_auth_header_value!Object



291
292
293
294
295
# File 'lib/httpx/plugins/oauth.rb', line 291

def reset_auth_header_value!
  super.tap do
    @oauth_session.reset if @oauth_session
  end
end

#with_access_tokenObject

TODO: deprecate



278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/httpx/plugins/oauth.rb', line 278

def with_access_token
  warn "DEPRECATION WARNING: `#{__method__}` is deprecated. " \
       "The session will automatically handle token lifecycles for you."

  other_session = dup # : instance
  oauth_session = other_session.oauth_session
  oauth_session.fetch_access_token(other_session)
  if (expires_at = oauth_session.expires_at)
    @auth_header_expires_at = expires_at
  end
  other_session
end