Class: OmniAuth::Strategies::Yahoo

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/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
# File 'lib/omniauth/strategies/oauth/yahoo.rb', line 15

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

Instance Method Details

#auth_hashObject



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

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

#user_hashObject



54
55
56
57
# File 'lib/omniauth/strategies/oauth/yahoo.rb', line 54

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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/omniauth/strategies/oauth/yahoo.rb', line 38

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