\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef/embedded/lib/ruby/gems/2.7.0/gems/httpclient-2.8.3/lib/

Viewing File: oauthclient.rb

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015  NAKAMURA, Hiroshi  <nahi@ruby-lang.org>.
#
# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.


require 'httpclient'

module HTTP
  class Message
    attr_accessor :oauth_params
  end
end


# OAuthClient provides OAuth related methods in addition to HTTPClient.
#
# See sample/ dir how to use OAuthClient. There are sample clients for Twitter,
# FriendFeed and Google Buzz.
class OAuthClient < HTTPClient

  # HTTPClient::OAuth::Config:: OAuth configurator.
  attr_accessor :oauth_config

  # Creates a OAuthClient instance which provides OAuth related methods in
  # addition to HTTPClient.
  #
  # Method signature is as same as HTTPClient.  See HTTPClient.new
  def initialize(*arg)
    super
    @oauth_config = HTTPClient::OAuth::Config.new
    self.www_auth.oauth.set_config(nil, @oauth_config)
    self.www_auth.oauth.challenge(nil)
    self.strict_response_size_check = true
  end

  # Get request token.
  # uri:: URI for request token.
  # callback:: callback String. This can be nil for OAuth 1.0a
  # param:: Additional query parameter Hash.
  #
  # It returns a HTTP::Message instance as a response. When the request is made
  # successfully, you can retrieve a pair of request token and secret like
  # following;
  #   res = client.get_request_token(...)
  #   token = res.oauth_params['oauth_token']
  #   secret = res.oauth_params['oauth_token_secret']
  def get_request_token(uri, callback = nil, param = nil)
    oauth_config.token = nil
    oauth_config.secret = nil
    oauth_config.callback = callback
    oauth_config.verifier = nil
    res = request(oauth_config.http_method, uri, param)
    filter_response(res)
    res
  end

  # Get access token.
  # uri:: URI for request token.
  # request_token:: a request token String. See get_access_token.
  # request_token_secret:: a request secret String. See get_access_token.
  # verifier:: a verifier tag String.
  #
  # When the request succeeds and the server returns a pair of access token
  # and secret, oauth_config.token and oauth_token.secret are updated with
  # the access token. Then you can call OAuthClient#get, #post, #delete, etc.
  # All requests are signed.
  def get_access_token(uri, request_token, request_token_secret, verifier = nil)
    oauth_config.token = request_token
    oauth_config.secret = request_token_secret
    oauth_config.callback = nil
    oauth_config.verifier = verifier
    res = request(oauth_config.http_method, uri)
    filter_response(res)
    oauth_config.verifier = nil
    res
  end

  # Parse response and returns a Hash.
  def get_oauth_response(res)
    enc = res.header['content-encoding']
    body = nil
    if enc and enc[0] and enc[0].downcase == 'gzip'
      body = Zlib::GzipReader.wrap(StringIO.new(res.content)) { |gz| gz.read }
    else
      body = res.content
    end
    body.split('&').inject({}) { |r, e|
      key, value = e.split('=', 2)
      r[unescape(key)] = unescape(value)
      r
    }
  end

private

  def unescape(escaped)
    escaped ? ::HTTP::Message.unescape(escaped) : nil
  end

  def filter_response(res)
    if res.status == 200
      if res.oauth_params = get_oauth_response(res)
        oauth_config.token = res.oauth_params['oauth_token']
        oauth_config.secret = res.oauth_params['oauth_token_secret']
      end
    end
  end
end