mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
add netflix oauth support
This commit is contained in:
parent
61eb50782b
commit
2768b2310d
4 changed files with 74 additions and 0 deletions
|
@ -30,6 +30,7 @@ OmniAuth currently supports the following external providers:
|
|||
* SoundCloud (credit: [leemartin](http://github.com/leemartin))
|
||||
* SmugMug (credit: [pchilton](http://github.com/pchilton))
|
||||
* GoodReads (credit: [cristoffer](http://github.com/christoffer))
|
||||
* Netflix (credit: [caged](http://github.com/caged))
|
||||
* OpenID
|
||||
* Google Apps (via OpenID)
|
||||
* CAS (Central Authentication Service) (credit: [jamesarosen](http://github.com/jamesarosen))
|
||||
|
|
|
@ -19,5 +19,6 @@ module OmniAuth
|
|||
autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
|
||||
autoload :SmugMug, 'omniauth/strategies/smug_mug'
|
||||
autoload :Goodreads, 'omniauth/strategies/goodreads'
|
||||
autoload :Netflix, 'omniauth/strategies/netflix'
|
||||
end
|
||||
end
|
||||
|
|
67
oa-oauth/lib/omniauth/strategies/netflix.rb
Normal file
67
oa-oauth/lib/omniauth/strategies/netflix.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require 'omniauth/oauth'
|
||||
require 'multi_json'
|
||||
|
||||
module OmniAuth
|
||||
module Strategies
|
||||
#
|
||||
# Authenticate to Netflix via OAuth and retrieve basic user information.
|
||||
# Usage:
|
||||
# use OmniAuth::Strategies::Netflix, 'consumerkey', 'consumersecret', :app => 'ApplicationName'
|
||||
#
|
||||
class Netflix < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
opts = {
|
||||
:site => 'http://api.netflix.com',
|
||||
:request_token_path => "/oauth/request_token",
|
||||
:access_token_path => "/oauth/access_token",
|
||||
:authorize_url => "https://api-user.netflix.com/oauth/login"
|
||||
}
|
||||
super(app, :netflix, consumer_key, consumer_secret, opts, options, &block)
|
||||
end
|
||||
|
||||
def request_phase
|
||||
request_token = consumer.get_request_token(:oauth_callback => callback_url)
|
||||
(session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
||||
r = Rack::Response.new
|
||||
|
||||
if request_token.callback_confirmed?
|
||||
r.redirect(request_token.authorize_url(
|
||||
:oauth_consumer_key => consumer.key
|
||||
))
|
||||
else
|
||||
r.redirect(request_token.authorize_url(
|
||||
:oauth_callback => callback_url,
|
||||
:oauth_consumer_key => consumer.key
|
||||
))
|
||||
end
|
||||
|
||||
r.finish
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
OmniAuth::Utils.deep_merge(super, {
|
||||
'uid' => user_hash['user']['user_id'],
|
||||
'user_info' => user_info,
|
||||
'extra' => { 'user_hash' => user_hash['user'] }
|
||||
})
|
||||
end
|
||||
|
||||
def user_info
|
||||
user = user_hash['user']
|
||||
{
|
||||
'nickname' => user['nickname'],
|
||||
'first_name' => user['first_name'],
|
||||
'last_name' => user['last_name'],
|
||||
'can_instant_watch' => user['can_instant_watch'],
|
||||
'link' => user['link'],
|
||||
'max_maturity_level' => user['max_maturity_level'],
|
||||
'preferred_formats' => user['preferred_formats']
|
||||
}
|
||||
end
|
||||
|
||||
def user_hash
|
||||
@user_hash ||= MultiJson.decode(@access_token.get("http://api.netflix.com/users/#{@access_token.params[:user_id]}?output=json").body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
5
oa-oauth/spec/omniauth/strategies/netflix_spec.rb
Normal file
5
oa-oauth/spec/omniauth/strategies/netflix_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
|
||||
describe OmniAuth::Strategies::Netflix do
|
||||
it_should_behave_like "an oauth strategy"
|
||||
end
|
Loading…
Add table
Reference in a new issue