Sha256: b91c072ab6af1c84666802da428aae20a9602956b763cbf530947e6eabfaf711

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    #
    # Authenticate to Yahoo via OAuth and retrieve basic
    # user information.
    #
    # Usage:
    #
    #    use OmniAuth::Strategies::Yahoo, 'consumerkey', 'consumersecret'
    #
    class Yahoo < OmniAuth::Strategies::OAuth
      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

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

      def user_info
        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

      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oa-oauth-0.3.2 lib/omniauth/strategies/oauth/yahoo.rb
oa-oauth-0.3.0 lib/omniauth/strategies/oauth/yahoo.rb
oa-oauth-0.3.0.rc3 lib/omniauth/strategies/oauth/yahoo.rb