class Oauthio::Providers::Oauthio

Public Class Methods

new(access_token, secret, options) click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 4
def initialize(access_token, secret, options)
  @access_token = access_token
  @secret = secret
  @options = options
end

Public Instance Methods

_raw_info() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 42
def _raw_info
  @_raw_info ||= @access_token.me()['data'] || {}
  @_raw_info
end
appsecret_proof() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 59
def appsecret_proof
  # @appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, @secret, @access_token.token)
end
credentials() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 63
def credentials
  hash = {}
  unless @access_token.token.empty?
    hash.merge!('token' => @access_token.token)
  end
  has_oauth_token = !@access_token.oauth_token.empty?
  has_oauth_token_secret = !@access_token.oauth_token_secret.empty?
  if has_oauth_token && has_oauth_token_secret
    hash.merge!('oauth_token' => @access_token.oauth_token,
                'oauth_token_secret' => @access_token.oauth_token_secret)
  end
  if @access_token.expires? && @access_token.refresh_token
    hash.merge!('refresh_token' => @access_token.refresh_token)
  end
  if @access_token.expires?
    hash.merge!('expires_at' => @access_token.expires_at)
  end
  hash.merge!('expires' => @access_token.expires?)
  hash
end
extra() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 36
def extra
  hash = {}
  hash['raw_info'] = raw_info unless skip_info?
  prune! hash
end
info() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 20
def info
  # Map OAuth.io info to standard OmniAuth keys, e.g., OAuth.io's alias
  # becomes nickname.
  # See https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
  prune!({'nickname' => _raw_info['alias'],
          'description' => _raw_info['bio'],
          'image' => _raw_info['avatar'],
          'first_name' => _raw_info['firstname'],
          'last_name' => _raw_info['lastname'],
          'phone' => _raw_info['phones'],
          'email' => _raw_info['email'],
          'name' => _raw_info['name'],
          'location' => _raw_info['location'],
          'urls' => _raw_info['urls']})
end
info_options() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 51
def info_options
  # params = {:appsecret_proof => appsecret_proof}
  # params.merge!({:fields => @options[:info_fields]}) if @options[:info_fields]
  # params.merge!({:locale => @options[:locale]}) if @options[:locale]
  #
  # {:params => params}
end
prune!(hash) click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 84
def prune!(hash)
  hash.delete_if do |_, v|
    prune!(v) if v.is_a?(Hash)
    v.nil? || (v.respond_to?(:empty?) && v.empty?)
  end
end
raw_info() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 47
def raw_info
  @raw_info ||= _raw_info['raw'] || {}
end
skip_info?() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 16
def skip_info?
  false
end
uid() click to toggle source
# File lib/oauthio/providers/oauthio.rb, line 10
def uid
  # This might not be uniform across all providers. Need to talk to oauthd guys to see if we can get the id
  # in the list of things parsed out of the raw data.
  raw_info['id']
end