Class: OmniAuth::Strategies::Yahoo

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/yahoo.rb

Overview

Authenticate to Yahoo via OAuth and retrieve basic user information.

Usage:

use OmniAuth::Strategies::Yahoo, 'consumerkey', 'consumersecret'

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Yahoo

Returns a new instance of Yahoo.



15
16
17
18
19
20
21
22
23
24
# File 'lib/omniauth/strategies/yahoo.rb', line 15

def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
  client_options = {
    :site => 'https://api.login.yahoo.com',
    :request_token_path => '/oauth/v2/get_request_token',
    :access_token_path => '/oauth/v2/get_token',
    :authorize_path => "/oauth/v2/request_auth"
  }

  super(app, :yahoo, consumer_key, consumer_secret, client_options, options)
end

Instance Method Details

#auth_hashObject



26
27
28
29
30
31
32
33
# File 'lib/omniauth/strategies/yahoo.rb', line 26

def auth_hash
  ui = 
  OmniAuth::Utils.deep_merge(super, {
    'uid' => ui['uid'],
    'user_info' => ui,
    'extra' => {'user_hash' => user_hash}
  })
end

#user_hashObject



49
50
51
52
# File 'lib/omniauth/strategies/yahoo.rb', line 49

def user_hash
  uid = @access_token.params['xoauth_yahoo_guid']
  @user_hash ||= MultiJson.decode(@access_token.get("http://social.yahooapis.com/v1/user/#{uid}/profile?format=json").body)
end

#user_infoObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/omniauth/strategies/yahoo.rb', line 35

def 
  user_hash = self.user_hash
  profile = user_hash['profile']
  nickname = user_hash['profile']['nickname']
  {
    'uid' => profile['guid'],
    'nickname' => profile['nickname'],
    'name' => profile['givenName'] || nickname,
    'image' => profile['image']['imageUrl'],
    'description' => profile['message'],
    'urls' => {'Profile' => profile['profileUrl'] }
  }
end