Sha256: 1e11f6d48a5b92c10395d00a2c25f19dbdaed7f7b97e47a16a56681652bae9c2

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'omniauth-oauth'

module OmniAuth
  module Strategies
    class Netflix < OmniAuth::Strategies::OAuth
      option :client_options, {
        :site               => 'http://api.netflix.com',
        :authorize_url      => 'https://api-user.netflix.com/oauth/login',
        :request_token_url  => 'http://api.netflix.com/oauth/request_token',
        :access_token_url   => 'http://api.netflix.com/oauth/access_token'
      }

      uid { raw_info['user']['user_id'] }

      info do
      {
        'nickname'    => raw_info['user']['nickname'],
        'first_name'  => raw_info['user']['first_name'],
        'last_name'   => raw_info['user']['last_name'],
        'name'        => "#{raw_info['user']['first_name']} #{raw_info['user']['last_name']}"
      }
      end

      extra do
        { 'raw_info' => raw_info }
      end

      def request_phase
        request_token = consumer.get_request_token(:oauth_callback => callback_url)
        session['oauth'] ||= {}
        session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}

        if request_token.callback_confirmed?
          redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_consumer_key => consumer.key))
        else
          redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url, :oauth_consumer_key => consumer.key))
        end

      rescue ::Timeout::Error => e
        fail!(:timeout, e)
      rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
        fail!(:service_unavailable, e)
      end

      def raw_info
        @raw_info ||= MultiJson.decode(access_token.get("http://api.netflix.com/users/#{@access_token.params[:user_id]}?output=json").body)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-netflix-0.1.0 lib/omniauth/strategies/netflix.rb