class OauthFb

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

Public Instance Methods

oauth_access_card_params(result) click to toggle source
# File lib/oauth/oauth_fb.rb, line 5
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
user_picture(access_params) click to toggle source
# File lib/oauth/oauth_fb.rb, line 38
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