Sha256: d79aa7bf4dcbcff6dd478971544b35235be22d2285c44dcfba7869a405c67c0a

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'omniauth-oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    class YouTube < OmniAuth::Strategies::OAuth
      option :name, 'youtube'
      option :client_options, {
        :site => 'https://www.google.com',
        :request_token_path => '/accounts/OAuthGetRequestToken',
        :access_token_path => '/accounts/OAuthGetAccessToken',
        :authorize_path => '/accounts/OAuthAuthorizeToken',
      }

      # For the time being this option requires a fork of omniauth-oauth:
      # http://github.com/jamiew/omniauth-oauth
      option :request_params, {
        :scope => 'http://gdata.youtube.com'
      }

      uid { user['id'] }

      info do
        {
          'uid' => user['id']['$t'],
          'nickname' => user['author'].first['name']['$t'],
          'first_name' => user['yt$firstName'] && user['yt$firstName']['$t'],
          'last_name' => user['yt$lastName'] && user['yt$lastName']['$t'],
          'image' => user['media$thumbnail'] && user['media$thumbnail']['url'],
          'description' => user['yt$description'] && user['yt$description']['$t'],
          'location' => user['yt$location'] && user['yt$location']['$t']
        }
      end

      extra do
        { 'user_hash' => user }
      end

      def user
        user_hash['entry']
      end

      def user_hash
        @user_hash ||= MultiJson.decode(@access_token.get("http://gdata.youtube.com/feeds/api/users/default?alt=json").body)
      end

    end
  end
end

OmniAuth.config.add_camelization 'youtube', 'YouTube'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-youtube-1.0 lib/omniauth/strategies/youtube.rb