Class: Oauthio::Providers::Oauthio
- Inherits:
-
Object
- Object
- Oauthio::Providers::Oauthio
- Defined in:
- lib/oauthio/providers/oauthio.rb
Instance Method Summary collapse
- #_raw_info ⇒ Object
- #appsecret_proof ⇒ Object
- #credentials ⇒ Object
- #extra ⇒ Object
- #info ⇒ Object
- #info_options ⇒ Object
-
#initialize(access_token, secret, options) ⇒ Oauthio
constructor
A new instance of Oauthio.
- #prune!(hash) ⇒ Object
- #raw_info ⇒ Object
- #skip_info? ⇒ Boolean
- #uid ⇒ Object
Constructor Details
#initialize(access_token, secret, options) ⇒ Oauthio
Returns a new instance of Oauthio.
4 5 6 7 8 |
# File 'lib/oauthio/providers/oauthio.rb', line 4 def initialize(access_token, secret, ) @access_token = access_token @secret = secret @options = end |
Instance Method Details
#_raw_info ⇒ Object
42 43 44 45 |
# File 'lib/oauthio/providers/oauthio.rb', line 42 def _raw_info @_raw_info ||= @access_token.me()['data'] || {} @_raw_info end |
#appsecret_proof ⇒ Object
59 60 61 |
# 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 ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
36 37 38 39 40 |
# File 'lib/oauthio/providers/oauthio.rb', line 36 def extra hash = {} hash['raw_info'] = raw_info unless skip_info? prune! hash end |
#info ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/oauthio/providers/oauthio.rb', line 51 def # 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) ⇒ Object
84 85 86 87 88 89 |
# 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 ⇒ Object
47 48 49 |
# File 'lib/oauthio/providers/oauthio.rb', line 47 def raw_info @raw_info ||= _raw_info['raw'] || {} end |
#skip_info? ⇒ Boolean
16 17 18 |
# File 'lib/oauthio/providers/oauthio.rb', line 16 def skip_info? false end |
#uid ⇒ Object
10 11 12 13 14 |
# 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 |