Sha256: 768a4f05f6e5f0e86f87756b956ed71158fb9f117c0482bae19a30747702ad37

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

# у Цукерберга всё оригинально, нужен дополнительный запрос для получения user_id и token expired

class OauthFb < Oauth

  def oauth_access_card_params result
    begin
      base_access_token = ActiveSupport::JSON.decode(result.body)
      unless base_access_token['error'].present?

        uri = URI CONFIG[:oauth][:fb][:auth][:debug_token][:uri]
        params = ({input_token: base_access_token['access_token'], access_token: "#{CONFIG[:oauth][:fb][:auth][:united_params][:client_id]}|#{CONFIG[:oauth][:fb][:auth][:debug_token][:client_secret]}"})
        uri.query = URI.encode_www_form params

        result = Net::HTTP.get_response uri
        access_token_details = ActiveSupport::JSON.decode(result.body)

        unless access_token_details['error'].present?
          user_picture = user_picture({access_token: base_access_token['access_token']})
          {
              state: :ok,
              oauth_name: @name,
              oauth_uid: access_token_details['data']['user_id'],
              access_token: base_access_token['access_token'],
              token_expired: Time.at(access_token_details['data']['expires_at']).to_datetime.to_s(:db),
              photourl: user_picture['data']['url']
          }
        else
          error_response access_token_details['error']['message']
        end
      else
        error_response base_access_token['error']['message']
      end
    rescue Exception => error
      error_response error.message
    end
  end

  def user_picture access_params
    uri = URI "#{CONFIG[:oauth][@name][:api][:uri]}#{CONFIG[:oauth][@name][:api][:get_picture][:prefix]}"
    params = {width: 200, height: 200, redirect: false}
    params.merge!(access_params) unless access_params.nil?
    uri.query = URI.encode_www_form params
    result = Net::HTTP.get_response uri

    ActiveSupport::JSON.decode(result.body)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
digital_heroes_startkit-0.1.1.4 lib/oauth/oauth_fb.rb
digital_heroes_startkit-0.1.1.3 lib/oauth/oauth_fb.rb
digital_heroes_startkit-0.1.1.2 lib/oauth/oauth_fb.rb
digital_heroes_startkit-0.1.1.1 lib/oauth/oauth_fb.rb
digital_heroes_startkit-0.1.1 lib/oauth/oauth_fb.rb