From 42617afc8379fde14e3e0df9ba49c3c7287b415c Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Wed, 30 Mar 2011 15:32:19 -0300 Subject: [PATCH 1/6] Trying to add blogger support --- oa-oauth/lib/omniauth/oauth.rb | 1 + oa-oauth/lib/omniauth/strategies/blogger.rb | 74 +++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 oa-oauth/lib/omniauth/strategies/blogger.rb diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index cd90d7c82..8b736be75 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -27,6 +27,7 @@ module Strategies autoload :Bitly, 'omniauth/strategies/bitly' autoload :Vimeo, 'omniauth/strategies/vimeo' autoload :YouTube, 'omniauth/strategies/you_tube' + autoload :Blogger, 'omniauth/strategies/blogger' autoload :Hyves, 'omniauth/strategies/hyves' autoload :Miso, 'omniauth/strategies/miso' autoload :Dailymile, 'omniauth/strategies/dailymile' diff --git a/oa-oauth/lib/omniauth/strategies/blogger.rb b/oa-oauth/lib/omniauth/strategies/blogger.rb new file mode 100644 index 000000000..811bb16a6 --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/blogger.rb @@ -0,0 +1,74 @@ +# Based heavily on the Google strategy, monkeypatch and all + +require 'omniauth/oauth' +require 'multi_json' + +module OmniAuth + module Strategies + # + # Authenticate to YouTube via OAuth and retrieve basic user info. + # + # Usage: + # + # use OmniAuth::Strategies::YouTube, 'consumerkey', 'consumersecret' + # + class Blogger < OmniAuth::Strategies::OAuth + def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) + client_options = { + :site => 'https://www.google.com', + :request_token_path => '/accounts/OAuthGetRequestToken', + :access_token_path => '/accounts/OAuthGetAccessToken', + :authorize_path => '/accounts/OAuthAuthorizeToken' + } + + super(app, :blogger, consumer_key, consumer_secret, client_options, options) + 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 + entry = user_hash['entry'] + { + debugger + 'uid' => entry['id']['$t'], + 'nickname' => entry['author'].first['name']['$t'], + 'first_name' => entry['yt$firstName'] && entry['yt$firstName']['$t'], + 'last_name' => entry['yt$lastName'] && entry['yt$lastName']['$t'], + 'image' => entry['media$thumbnail'] && entry['media$thumbnail']['url'], + 'description' => entry['yt$description'] && entry['yt$description']['$t'], + 'location' => entry['yt$location'] && entry['yt$location']['$t'] + } + end + + def user_hash + # YouTube treats 'default' as the currently logged-in user + # via http://apiblog.youtube.com/2010/11/update-to-clientlogin-url.html + @user_hash ||= MultiJson.decode(@access_token.get("http://www.blogger.com/feeds/api/users/default?alt=json").body) + end + + # Monkeypatch consumer.get_request_token but specify YouTube scope rather than Google Contacts + # TODO this is an easy patch to the underlying OAuth strategy a la OAuth2 + def request_phase + request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://www.blogger.com/feeds'}) + session['oauth'] ||= {} + 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) + else + r.redirect(request_token.authorize_url(:oauth_callback => callback_url)) + end + + r.finish + end + end + end +end From f2307edfd2490c49185ac687a811c0e71b010d4f Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Wed, 30 Mar 2011 15:43:31 -0300 Subject: [PATCH 2/6] fix typo --- oa-oauth/lib/omniauth/strategies/blogger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oa-oauth/lib/omniauth/strategies/blogger.rb b/oa-oauth/lib/omniauth/strategies/blogger.rb index 811bb16a6..57685e99a 100644 --- a/oa-oauth/lib/omniauth/strategies/blogger.rb +++ b/oa-oauth/lib/omniauth/strategies/blogger.rb @@ -34,9 +34,9 @@ def auth_hash end def user_info + debugger entry = user_hash['entry'] { - debugger 'uid' => entry['id']['$t'], 'nickname' => entry['author'].first['name']['$t'], 'first_name' => entry['yt$firstName'] && entry['yt$firstName']['$t'], From 0c28f4db70a655f38a971f5fafa7219f7ce7949f Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Wed, 30 Mar 2011 17:24:24 -0300 Subject: [PATCH 3/6] Blogger integration up and running --- oa-oauth/lib/omniauth/strategies/blogger.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/oa-oauth/lib/omniauth/strategies/blogger.rb b/oa-oauth/lib/omniauth/strategies/blogger.rb index 57685e99a..5d44d4458 100644 --- a/oa-oauth/lib/omniauth/strategies/blogger.rb +++ b/oa-oauth/lib/omniauth/strategies/blogger.rb @@ -34,29 +34,19 @@ def auth_hash end def user_info - debugger - entry = user_hash['entry'] { - 'uid' => entry['id']['$t'], - 'nickname' => entry['author'].first['name']['$t'], - 'first_name' => entry['yt$firstName'] && entry['yt$firstName']['$t'], - 'last_name' => entry['yt$lastName'] && entry['yt$lastName']['$t'], - 'image' => entry['media$thumbnail'] && entry['media$thumbnail']['url'], - 'description' => entry['yt$description'] && entry['yt$description']['$t'], - 'location' => entry['yt$location'] && entry['yt$location']['$t'] + 'uid' => user_hash['feed']['author'][0]['email']['$t'], + 'nickname' => user_hash['feed']['author'][0]['name']['$t'] } end def user_hash - # YouTube treats 'default' as the currently logged-in user - # via http://apiblog.youtube.com/2010/11/update-to-clientlogin-url.html - @user_hash ||= MultiJson.decode(@access_token.get("http://www.blogger.com/feeds/api/users/default?alt=json").body) + # Using Contact feed + @user_hash ||= MultiJson.decode(@access_token.get("https://www.google.com/m8/feeds/contacts/default/full/?alt=json").body) end - # Monkeypatch consumer.get_request_token but specify YouTube scope rather than Google Contacts - # TODO this is an easy patch to the underlying OAuth strategy a la OAuth2 def request_phase - request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://www.blogger.com/feeds'}) + request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://www.blogger.com/feeds/ http://www.google.com/m8/feeds/'}) session['oauth'] ||= {} 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 From 8a4eb3ebf54a33774ecc8abd1356b3c4eed57aa6 Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Thu, 31 Mar 2011 15:02:31 -0300 Subject: [PATCH 4/6] Forcing change of version --- oa-oauth/lib/omniauth/strategies/blogger.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/oa-oauth/lib/omniauth/strategies/blogger.rb b/oa-oauth/lib/omniauth/strategies/blogger.rb index 5d44d4458..6f5324240 100644 --- a/oa-oauth/lib/omniauth/strategies/blogger.rb +++ b/oa-oauth/lib/omniauth/strategies/blogger.rb @@ -33,6 +33,7 @@ def auth_hash }) end + # TODO: Remove contact list from hash returned to the application def user_info { 'uid' => user_hash['feed']['author'][0]['email']['$t'], From 83fc468360c68be72f2a0b60f2e8be215ee238b6 Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Thu, 31 Mar 2011 15:04:13 -0300 Subject: [PATCH 5/6] More revision changing --- oa-oauth/lib/omniauth/strategies/blogger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oa-oauth/lib/omniauth/strategies/blogger.rb b/oa-oauth/lib/omniauth/strategies/blogger.rb index 6f5324240..c394ad348 100644 --- a/oa-oauth/lib/omniauth/strategies/blogger.rb +++ b/oa-oauth/lib/omniauth/strategies/blogger.rb @@ -33,7 +33,7 @@ def auth_hash }) end - # TODO: Remove contact list from hash returned to the application + #TODO: Remove contact list from hash returned to the application def user_info { 'uid' => user_hash['feed']['author'][0]['email']['$t'], From 2e4a534b15109b585ee7fdf24e139a956adac598 Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Thu, 31 Mar 2011 15:07:31 -0300 Subject: [PATCH 6/6] More revision changing --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0ea3a944b..f6f6a850b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.0revc