From a94a63a1b455698e73d3b5715a7c5da29de0f09e Mon Sep 17 00:00:00 2001 From: Jai-Gouk Kim Date: Tue, 11 Jan 2011 09:27:38 +0900 Subject: [PATCH 01/35] need to change google_health.rb --- oa-oauth/lib/omniauth/oauth.rb | 1 + .../lib/omniauth/strategies/google_health.rb | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 oa-oauth/lib/omniauth/strategies/google_health.rb diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index cf61adcf9..efd6fc05b 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -22,6 +22,7 @@ module Strategies autoload :Yahoo, 'omniauth/strategies/yahoo' autoload :TypePad, 'omniauth/strategies/type_pad' autoload :Google, 'omniauth/strategies/google' + autoload :GoogleHealth, 'omniauth/startegies/google_health' autoload :Netflix, 'omniauth/strategies/netflix' end end diff --git a/oa-oauth/lib/omniauth/strategies/google_health.rb b/oa-oauth/lib/omniauth/strategies/google_health.rb new file mode 100644 index 000000000..95bc02acf --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/google_health.rb @@ -0,0 +1,76 @@ +require 'omniauth/oauth' +require 'multi_json' + +module OmniAuth + module Strategies + # + # Authenticate to Google via OAuth and retrieve basic + # user information. + # + # Usage: + # + # use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret' + # + class GoogleHealth < 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, :google, 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 + email = user_hash['feed']['id']['$t'] + + name = user_hash['feed']['author'].first['name']['$t'] + name = email if name.strip == '(unknown)' + + { + 'email' => email, + 'uid' => email, + 'name' => name + } + end + + def user_hash + # Google is very strict about keeping authorization and + # authentication separated. + # They give no endpoint to get a user's profile directly that I can + # find. We *can* get their name and email out of the contacts feed, + # however. It will fail in the extremely rare case of a user who has + # a Google Account but has never even signed up for Gmail. This has + # not been seen in the field. + @user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json").body) + end + + # Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call + def request_phase + request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => "http://www.google.com/m8/feeds"}) + + (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 47e9ef26d3bdf464f7f1c8bb6dd8e2ab6abf5789 Mon Sep 17 00:00:00 2001 From: Gordon DuQuesnay Date: Tue, 11 Jan 2011 02:43:25 +0000 Subject: [PATCH 02/35] working on google health --- oa-oauth/lib/omniauth/strategies/google_health.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oa-oauth/lib/omniauth/strategies/google_health.rb b/oa-oauth/lib/omniauth/strategies/google_health.rb index 95bc02acf..c85357715 100644 --- a/oa-oauth/lib/omniauth/strategies/google_health.rb +++ b/oa-oauth/lib/omniauth/strategies/google_health.rb @@ -53,7 +53,7 @@ def user_hash # however. It will fail in the extremely rare case of a user who has # a Google Account but has never even signed up for Gmail. This has # not been seen in the field. - @user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json").body) + @user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/health/feeds/profile/default/default?digest=true&alt=json").body) end # Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call From 689215de8bff38fa5d6a88ab8bddf380244ad586 Mon Sep 17 00:00:00 2001 From: Gordon DuQuesnay Date: Tue, 11 Jan 2011 04:14:46 +0000 Subject: [PATCH 03/35] no such file to load -- omniauth/startegies/google_health (LoadError) --- oa-oauth/lib/omniauth/strategies/google_health.rb | 4 ++-- oa-oauth/spec/omniauth/strategies/google_health_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 oa-oauth/spec/omniauth/strategies/google_health_spec.rb diff --git a/oa-oauth/lib/omniauth/strategies/google_health.rb b/oa-oauth/lib/omniauth/strategies/google_health.rb index c85357715..4591a3a77 100644 --- a/oa-oauth/lib/omniauth/strategies/google_health.rb +++ b/oa-oauth/lib/omniauth/strategies/google_health.rb @@ -20,7 +20,7 @@ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &bl :authorize_path => '/accounts/OAuthAuthorizeToken' } - super(app, :google, consumer_key, consumer_secret, client_options, options) + super(app, :google_health, consumer_key, consumer_secret, client_options, options) end def auth_hash @@ -58,7 +58,7 @@ def user_hash # Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call def request_phase - request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => "http://www.google.com/m8/feeds"}) + request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => "http://www.google.com/health/feeds"}) (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 diff --git a/oa-oauth/spec/omniauth/strategies/google_health_spec.rb b/oa-oauth/spec/omniauth/strategies/google_health_spec.rb new file mode 100644 index 000000000..df7214146 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/google_health_spec.rb @@ -0,0 +1,5 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe OmniAuth::Strategies::GoogleHealth do + it_should_behave_like 'an oauth strategy' +end From 98e49d05f2a612a674fd05327f1a33bf9f85452c Mon Sep 17 00:00:00 2001 From: Jai-Gouk Kim Date: Tue, 11 Jan 2011 13:16:14 +0900 Subject: [PATCH 04/35] fixed a typo --- oa-oauth/lib/omniauth/oauth.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index efd6fc05b..2a246619c 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -22,7 +22,7 @@ module Strategies autoload :Yahoo, 'omniauth/strategies/yahoo' autoload :TypePad, 'omniauth/strategies/type_pad' autoload :Google, 'omniauth/strategies/google' - autoload :GoogleHealth, 'omniauth/startegies/google_health' + autoload :GoogleHealth, 'omniauth/strategies/google_health' autoload :Netflix, 'omniauth/strategies/netflix' end end From 7eb0991123c10a8f9a31aec6bab786f885136845 Mon Sep 17 00:00:00 2001 From: Jai-Gouk Kim Date: Tue, 11 Jan 2011 13:34:33 +0900 Subject: [PATCH 05/35] added Google Health Sandbox --- oa-oauth/lib/omniauth/oauth.rb | 1 + .../strategies/google_health_sandbox.rb | 76 +++++++++++++++++++ .../strategies/google_health_sandbox_spec.rb | 5 ++ 3 files changed, 82 insertions(+) create mode 100644 oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb create mode 100644 oa-oauth/spec/omniauth/strategies/google_health_sandbox_spec.rb diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index 2a246619c..093495767 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -23,6 +23,7 @@ module Strategies autoload :TypePad, 'omniauth/strategies/type_pad' autoload :Google, 'omniauth/strategies/google' autoload :GoogleHealth, 'omniauth/strategies/google_health' + autoload :GoogleHealthSandbox,'omniauth/strategies/google_health_sandbox' autoload :Netflix, 'omniauth/strategies/netflix' end end diff --git a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb new file mode 100644 index 000000000..4c241e3e7 --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb @@ -0,0 +1,76 @@ +require 'omniauth/oauth' +require 'multi_json' + +module OmniAuth + module Strategies + # + # Authenticate to Google via OAuth and retrieve basic + # user information. + # + # Usage: + # + # use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret' + # + class GoogleHealthSandbox < 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, :google_health_sandbox, 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 + email = user_hash['feed']['id']['$t'] + + name = user_hash['feed']['author'].first['name']['$t'] + name = email if name.strip == '(unknown)' + + { + 'email' => email, + 'uid' => email, + 'name' => name + } + end + + def user_hash + # Google is very strict about keeping authorization and + # authentication separated. + # They give no endpoint to get a user's profile directly that I can + # find. We *can* get their name and email out of the contacts feed, + # however. It will fail in the extremely rare case of a user who has + # a Google Account but has never even signed up for Gmail. This has + # not been seen in the field. + @user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/h9/feeds/profile/default/default?digest=true&alt=json").body) + end + + # Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call + def request_phase + request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => "http://www.google.com/h9/feeds"}) + + (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 diff --git a/oa-oauth/spec/omniauth/strategies/google_health_sandbox_spec.rb b/oa-oauth/spec/omniauth/strategies/google_health_sandbox_spec.rb new file mode 100644 index 000000000..162c9ac44 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/google_health_sandbox_spec.rb @@ -0,0 +1,5 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe OmniAuth::Strategies::GoogleHealthSandbox do + it_should_behave_like 'an oauth strategy' +end From 8fc55e88614c816b1f311601546f0b954db5fe48 Mon Sep 17 00:00:00 2001 From: Jai-Gouk Kim Date: Tue, 11 Jan 2011 14:21:41 +0900 Subject: [PATCH 06/35] working on redicret --- oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb index 4c241e3e7..433948a59 100644 --- a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb +++ b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb @@ -64,7 +64,7 @@ def request_phase r = Rack::Response.new if request_token.callback_confirmed? - r.redirect(request_token.authorize_url) + r.redirect("http://localhost:3000")#request_token.authorize_url) else r.redirect(request_token.authorize_url(:oauth_callback => callback_url)) end From feccb99aff85da91f0ddafcae0590c49763b51cf Mon Sep 17 00:00:00 2001 From: Jai-Gouk Kim Date: Tue, 11 Jan 2011 14:39:03 +0900 Subject: [PATCH 07/35] working on redicret --- oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb index 433948a59..e1fa26d0e 100644 --- a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb +++ b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb @@ -63,11 +63,11 @@ def request_phase (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("http://localhost:3000")#request_token.authorize_url) - else + #if request_token.callback_confirmed? + # r.redirect(#request_token.authorize_url) + #else r.redirect(request_token.authorize_url(:oauth_callback => callback_url)) - end + #end r.finish end From 82c6ee7b725cceb69697f8e4b1ed4da6c6f28a1d Mon Sep 17 00:00:00 2001 From: Jai-Gouk Kim Date: Tue, 11 Jan 2011 21:41:12 +0900 Subject: [PATCH 08/35] user hash --- .../lib/omniauth/strategies/google_health_sandbox.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb index e1fa26d0e..1224123e5 100644 --- a/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb +++ b/oa-oauth/lib/omniauth/strategies/google_health_sandbox.rb @@ -53,7 +53,7 @@ def user_hash # however. It will fail in the extremely rare case of a user who has # a Google Account but has never even signed up for Gmail. This has # not been seen in the field. - @user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/h9/feeds/profile/default/default?digest=true&alt=json").body) + @user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/h9/feeds/profile/default/default?digest=true&oauth_signature_method=RSA-SHA1&oauth_version=1.0").body) end # Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call @@ -63,11 +63,11 @@ def request_phase (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 + if request_token.callback_confirmed? + r.redirect(request_token.authorize_url) + else r.redirect(request_token.authorize_url(:oauth_callback => callback_url)) - #end + end r.finish end From 42617afc8379fde14e3e0df9ba49c3c7287b415c Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Wed, 30 Mar 2011 15:32:19 -0300 Subject: [PATCH 09/35] 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 10/35] 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 11/35] 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 12/35] 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 13/35] 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 14/35] 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 From 3da4ed8a77e892bd6aa38372e1becba0eb70d953 Mon Sep 17 00:00:00 2001 From: Gatis Tomsons Date: Mon, 16 May 2011 21:44:00 +0300 Subject: [PATCH 15/35] Added Draugiem strategy --- oa-more/lib/omniauth/more.rb | 1 + oa-more/lib/omniauth/strategies/draugiem.rb | 85 +++++++++++++++++++ .../spec/omniauth/strategies/draugiem_spec.rb | 50 +++++++++++ oa-more/spec/spec_helper.rb | 1 + 4 files changed, 137 insertions(+) create mode 100644 oa-more/lib/omniauth/strategies/draugiem.rb create mode 100644 oa-more/spec/omniauth/strategies/draugiem_spec.rb diff --git a/oa-more/lib/omniauth/more.rb b/oa-more/lib/omniauth/more.rb index 7ebb4cba4..5bde7b517 100644 --- a/oa-more/lib/omniauth/more.rb +++ b/oa-more/lib/omniauth/more.rb @@ -6,5 +6,6 @@ module Strategies autoload :Flickr, 'omniauth/strategies/flickr' autoload :Yupoo, 'omniauth/strategies/yupoo' autoload :Ign, 'omniauth/strategies/ign' + autoload :Draugiem, 'omniauth/strategies/draugiem' end end diff --git a/oa-more/lib/omniauth/strategies/draugiem.rb b/oa-more/lib/omniauth/strategies/draugiem.rb new file mode 100644 index 000000000..da3c9756e --- /dev/null +++ b/oa-more/lib/omniauth/strategies/draugiem.rb @@ -0,0 +1,85 @@ +require 'omniauth/core' +require 'digest/md5' +require 'rest-client' +require 'multi_json' + +module OmniAuth + module Strategies + class Draugiem + include OmniAuth::Strategy + attr_accessor :api_key, :app_id, :options + + def initialize(app, api_key, app_id) + super(app, :draugiem) + @api_key = api_key + @app_id = app_id + end + + protected + + def request_phase + params = { + :app => @app_id, + :redirect => callback_url, + :hash => Digest::MD5.hexdigest("#{@api_key}#{callback_url}") + } + query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&') + redirect "http://api.draugiem.lv/authorize/?#{query_string}" + end + + def callback_phase + if request.params['dr_auth_status'] == 'ok' && request.params['dr_auth_code'] + response = RestClient.get('http://api.draugiem.lv/json/', { :params => draugiem_authorize_params(request.params['dr_auth_code']) }) + auth = MultiJson.decode(response.to_s) + unless auth['error'] + @auth_data = auth + super + else + fail!(auth['error']['code'].to_s,auth["error"]["description"].to_s) + end + else + fail!(:invalid_request) + end + rescue Exception => e + fail!(:invalid_response, e) + end + + def auth_hash + user_info = if @auth_data['users'][@auth_data['uid']] + user = @auth_data['users'][@auth_data['uid']] + { + 'name' => "#{user['name']} #{user['surname']}", + 'nickname' => user['nick'], + 'first_name' => user['name'], + 'last_name' => user['surname'], + 'location' => user['place'], + 'age' => user['age'], + 'adult' => user['adult'], + 'image' => user['img'], + 'sex' => user['sex'] + } + else + {} + end + OmniAuth::Utils.deep_merge(super, { + 'uid' => @auth_data['uid'], + 'user_info' => user_info, + 'credentials' => { + 'apikey' => @auth_data['apikey'] + }, + 'extra' => { 'user_hash' => @auth_data } + }) + end + + private + + def draugiem_authorize_params code + { + :action => 'authorize', + :app => @api_key, + :code => code + } + end + end + end +end diff --git a/oa-more/spec/omniauth/strategies/draugiem_spec.rb b/oa-more/spec/omniauth/strategies/draugiem_spec.rb new file mode 100644 index 000000000..0a9fd3d87 --- /dev/null +++ b/oa-more/spec/omniauth/strategies/draugiem_spec.rb @@ -0,0 +1,50 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe 'OmniAuth::Strategies::Draugiem', :type => :strategy do + + include OmniAuth::Test::StrategyTestCase + + def strategy + [OmniAuth::Strategies::Draugiem, "abc",123] + end + + it 'should initialize with api key and app id' do + lambda{OmniAuth::Strategies::Draugiem.new({},'abc','123')}.should_not raise_error + end + + describe '/auth/draugiem' do + + it 'should redirect to api.draugiem.lv' do + get '/auth/draugiem' + last_response.should be_redirect + last_response.headers['Location'].should == "http://api.draugiem.lv/authorize/?app=123&redirect=http%3A%2F%2Fexample.org%2Fauth%2Fdraugiem%2Fcallback&hash=2d5698ba02ddd42c441998a5a2c2946b" + end + + it 'should gather user data after success authorization' do + stub_request(:get, "http://api.draugiem.lv/json/?action=authorize&app=abc&code=123456"). + to_return(:body => MultiJson.encode({ + 'apikey'=>"123456789", + 'uid'=>"100", + 'language'=>"lv", + 'users'=>{ + '100'=>{ + 'uid'=>"100", + 'name'=>"John", + 'surname'=>"Lenon", + 'nick'=>"johnybravo", + 'place'=>"Durbe", + 'age'=>"false", + 'adult'=>"1", + 'img'=>"http://4.bp.blogspot.com/_ZmXOoYjxXog/Sg2jby1RFSI/AAAAAAAAE_Q/1LpfjimAz50/s400/JohnnyBravo3.gif", + 'sex'=>"M" + } + } + })) + get '/auth/draugiem/callback?dr_auth_status=ok&dr_auth_code=123456' + debugger + + last_request.env['omniauth.auth']['credentials']['apikey'].should == "123456789" + last_request.env['omniauth.auth']['user_info']['location'].should == "Durbe" + end + end +end diff --git a/oa-more/spec/spec_helper.rb b/oa-more/spec/spec_helper.rb index 495e09f65..adc41482f 100644 --- a/oa-more/spec/spec_helper.rb +++ b/oa-more/spec/spec_helper.rb @@ -3,6 +3,7 @@ require 'rspec' require 'rack/test' require 'webmock/rspec' +$:< Date: Mon, 16 May 2011 21:46:16 +0300 Subject: [PATCH 16/35] added Basic usage --- oa-more/lib/omniauth/strategies/draugiem.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/oa-more/lib/omniauth/strategies/draugiem.rb b/oa-more/lib/omniauth/strategies/draugiem.rb index da3c9756e..5239bf123 100644 --- a/oa-more/lib/omniauth/strategies/draugiem.rb +++ b/oa-more/lib/omniauth/strategies/draugiem.rb @@ -5,6 +5,12 @@ module OmniAuth module Strategies + # + # Authenticate to draugiem.lv and frype.com and others. + # + # @example Basic Usage + # + # use OmniAuth::Strategies::Draugiem, 'API Key', 'App id' class Draugiem include OmniAuth::Strategy attr_accessor :api_key, :app_id, :options From 9cd749f447ce76ef53abb1f0bb1d906783c7b05e Mon Sep 17 00:00:00 2001 From: Gatis Tomsons Date: Mon, 16 May 2011 21:54:40 +0300 Subject: [PATCH 17/35] extracted method --- oa-more/lib/omniauth/strategies/draugiem.rb | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/oa-more/lib/omniauth/strategies/draugiem.rb b/oa-more/lib/omniauth/strategies/draugiem.rb index 5239bf123..f27fff52b 100644 --- a/oa-more/lib/omniauth/strategies/draugiem.rb +++ b/oa-more/lib/omniauth/strategies/draugiem.rb @@ -51,7 +51,20 @@ def callback_phase end def auth_hash - user_info = if @auth_data['users'][@auth_data['uid']] + OmniAuth::Utils.deep_merge(super, { + 'uid' => @auth_data['uid'], + 'user_info' => get_user_info, + 'credentials' => { + 'apikey' => @auth_data['apikey'] + }, + 'extra' => { 'user_hash' => @auth_data } + }) + end + + private + + def get_user_info + if @auth_data['users'] && @auth_data['users'][@auth_data['uid']] user = @auth_data['users'][@auth_data['uid']] { 'name' => "#{user['name']} #{user['surname']}", @@ -67,17 +80,7 @@ def auth_hash else {} end - OmniAuth::Utils.deep_merge(super, { - 'uid' => @auth_data['uid'], - 'user_info' => user_info, - 'credentials' => { - 'apikey' => @auth_data['apikey'] - }, - 'extra' => { 'user_hash' => @auth_data } - }) end - - private def draugiem_authorize_params code { From 3be1f837ecb38ff3d5b39feb96089a88e8e84cb7 Mon Sep 17 00:00:00 2001 From: Gatis Tomsons Date: Tue, 17 May 2011 10:04:24 +0300 Subject: [PATCH 18/35] updated initializer, added more help --- oa-more/lib/omniauth/strategies/draugiem.rb | 20 ++++++++++++++----- .../spec/omniauth/strategies/draugiem_spec.rb | 5 ++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/oa-more/lib/omniauth/strategies/draugiem.rb b/oa-more/lib/omniauth/strategies/draugiem.rb index f27fff52b..726f0b8df 100644 --- a/oa-more/lib/omniauth/strategies/draugiem.rb +++ b/oa-more/lib/omniauth/strategies/draugiem.rb @@ -8,17 +8,27 @@ module Strategies # # Authenticate to draugiem.lv and frype.com and others. # - # @example Basic Usage + # @example Basic Rails Usage + # + # Add this to config/initializers/omniauth.rb + # + # Rails.application.config.middleware.use OmniAuth::Builder do + # provider :draugiem, 'App id', 'API Key' + # end + # + # @example Basic Rack example + # + # use Rack::Session::Cookie + # use OmniAuth::Strategies::Draugiem, 'App id', 'API Key' # - # use OmniAuth::Strategies::Draugiem, 'API Key', 'App id' class Draugiem include OmniAuth::Strategy - attr_accessor :api_key, :app_id, :options + attr_accessor :app_id, :api_key - def initialize(app, api_key, app_id) + def initialize(app, app_id, api_key) super(app, :draugiem) - @api_key = api_key @app_id = app_id + @api_key = api_key end protected diff --git a/oa-more/spec/omniauth/strategies/draugiem_spec.rb b/oa-more/spec/omniauth/strategies/draugiem_spec.rb index 0a9fd3d87..ba4a8d526 100644 --- a/oa-more/spec/omniauth/strategies/draugiem_spec.rb +++ b/oa-more/spec/omniauth/strategies/draugiem_spec.rb @@ -5,11 +5,11 @@ include OmniAuth::Test::StrategyTestCase def strategy - [OmniAuth::Strategies::Draugiem, "abc",123] + [OmniAuth::Strategies::Draugiem, '123', "abc"] end it 'should initialize with api key and app id' do - lambda{OmniAuth::Strategies::Draugiem.new({},'abc','123')}.should_not raise_error + lambda{OmniAuth::Strategies::Draugiem.new({},'123','abc')}.should_not raise_error end describe '/auth/draugiem' do @@ -41,7 +41,6 @@ def strategy } })) get '/auth/draugiem/callback?dr_auth_status=ok&dr_auth_code=123456' - debugger last_request.env['omniauth.auth']['credentials']['apikey'].should == "123456789" last_request.env['omniauth.auth']['user_info']['location'].should == "Durbe" From 36d35f0e06e714166d42c989d3a965c539ce58aa Mon Sep 17 00:00:00 2001 From: Gatis Tomsons Date: Tue, 17 May 2011 16:35:27 +0300 Subject: [PATCH 19/35] updated hash valus --- oa-more/lib/omniauth/strategies/draugiem.rb | 8 ++++---- oa-more/spec/omniauth/strategies/draugiem_spec.rb | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/oa-more/lib/omniauth/strategies/draugiem.rb b/oa-more/lib/omniauth/strategies/draugiem.rb index 726f0b8df..6262efe74 100644 --- a/oa-more/lib/omniauth/strategies/draugiem.rb +++ b/oa-more/lib/omniauth/strategies/draugiem.rb @@ -47,8 +47,8 @@ def callback_phase if request.params['dr_auth_status'] == 'ok' && request.params['dr_auth_code'] response = RestClient.get('http://api.draugiem.lv/json/', { :params => draugiem_authorize_params(request.params['dr_auth_code']) }) auth = MultiJson.decode(response.to_s) - unless auth['error'] - @auth_data = auth + unless auth['error'] + @auth_data = auth super else fail!(auth['error']['code'].to_s,auth["error"]["description"].to_s) @@ -82,8 +82,8 @@ def get_user_info 'first_name' => user['name'], 'last_name' => user['surname'], 'location' => user['place'], - 'age' => user['age'], - 'adult' => user['adult'], + 'age' => user['age'] =~ /^0-9$/ ? user['age'] : nil, + 'adult' => user['adult'] == '1' ? true : false, 'image' => user['img'], 'sex' => user['sex'] } diff --git a/oa-more/spec/omniauth/strategies/draugiem_spec.rb b/oa-more/spec/omniauth/strategies/draugiem_spec.rb index ba4a8d526..e36f4ce9c 100644 --- a/oa-more/spec/omniauth/strategies/draugiem_spec.rb +++ b/oa-more/spec/omniauth/strategies/draugiem_spec.rb @@ -44,6 +44,8 @@ def strategy last_request.env['omniauth.auth']['credentials']['apikey'].should == "123456789" last_request.env['omniauth.auth']['user_info']['location'].should == "Durbe" + last_request.env['omniauth.auth']['user_info']['age'].should be_nil + last_request.env['omniauth.auth']['user_info']['adult'].should be_true end end end From 43ecdfb1c5fc3382b6715cbadf2bd3d27d98cd91 Mon Sep 17 00:00:00 2001 From: jugyo Date: Wed, 18 May 2011 15:55:35 +0900 Subject: [PATCH 20/35] fix to refresh the access token properly no test! --- oa-oauth/lib/omniauth/strategies/oauth2.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/oa-oauth/lib/omniauth/strategies/oauth2.rb b/oa-oauth/lib/omniauth/strategies/oauth2.rb index 080adea3b..5a3d1115b 100644 --- a/oa-oauth/lib/omniauth/strategies/oauth2.rb +++ b/oa-oauth/lib/omniauth/strategies/oauth2.rb @@ -64,16 +64,7 @@ def callback_phase end @access_token = build_access_token - - if @access_token.expires? && @access_token.expires_in <= 0 - client.request(:post, client.access_token_url, { - 'client_id' => client_id, - 'grant_type' => 'refresh_token', - 'client_secret' => client_secret, - 'refresh_token' => @access_token.refresh_token - }.merge(options)) - @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options)) - end + @access_token = client.web_server.refresh_access_token(@access_token.refresh_token) if @access_token.expired? super rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e @@ -84,11 +75,8 @@ def callback_phase fail!(:timeout, e) end - def verifier - request.params['code'] - end - def build_access_token + verifier = request.params['code'] client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options)) end From 9c456b4fdd846504ca765cc80e24f11f534b4040 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Wed, 18 May 2011 08:46:04 -0400 Subject: [PATCH 21/35] Update yard dependency to version 0.7 --- Gemfile | 4 ---- oa-basic/Gemfile | 4 ---- oa-basic/oa-basic.gemspec | 2 +- oa-core/Gemfile | 4 ---- oa-core/oa-core.gemspec | 2 +- oa-enterprise/Gemfile | 4 ---- oa-enterprise/oa-enterprise.gemspec | 2 +- oa-more/Gemfile | 4 ---- oa-more/oa-more.gemspec | 2 +- oa-oauth/Gemfile | 4 ---- oa-oauth/oa-oauth.gemspec | 2 +- oa-openid/Gemfile | 4 ---- oa-openid/oa-openid.gemspec | 2 +- 13 files changed, 6 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index da5b4cfa0..3080aad00 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,6 @@ platforms :jruby do gem 'jruby-openssl', '~> 0.7' end -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec :path => 'oa-basic' gemspec :path => 'oa-core' gemspec :path => 'oa-enterprise' diff --git a/oa-basic/Gemfile b/oa-basic/Gemfile index af3f2effc..1e01eae63 100644 --- a/oa-basic/Gemfile +++ b/oa-basic/Gemfile @@ -4,8 +4,4 @@ platforms :jruby do gem 'jruby-openssl', '~> 0.7' end -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec diff --git a/oa-basic/oa-basic.gemspec b/oa-basic/oa-basic.gemspec index 276807fa3..bdde539ec 100644 --- a/oa-basic/oa-basic.gemspec +++ b/oa-basic/oa-basic.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rake', '~> 0.8' gem.add_development_dependency 'rspec', '~> 2.5' gem.add_development_dependency 'webmock', '~> 1.6' - # gem.add_development_dependency 'yard', '~> 0.7' + gem.add_development_dependency 'yard', '~> 0.7' gem.add_development_dependency 'ZenTest', '~> 4.5' gem.name = 'oa-basic' gem.version = OmniAuth::Version::STRING diff --git a/oa-core/Gemfile b/oa-core/Gemfile index 3c1dac600..d65e2a669 100644 --- a/oa-core/Gemfile +++ b/oa-core/Gemfile @@ -1,7 +1,3 @@ source 'http://rubygems.org' -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec diff --git a/oa-core/oa-core.gemspec b/oa-core/oa-core.gemspec index 21be5b110..12614c032 100644 --- a/oa-core/oa-core.gemspec +++ b/oa-core/oa-core.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rack-test', '~> 0.5' gem.add_development_dependency 'rake', '~> 0.8' gem.add_development_dependency 'rspec', '~> 2.5' - # gem.add_development_dependency 'yard', '~> 0.7' + gem.add_development_dependency 'yard', '~> 0.7' gem.add_development_dependency 'ZenTest', '~> 4.5' gem.name = 'oa-core' gem.version = OmniAuth::Version::STRING diff --git a/oa-enterprise/Gemfile b/oa-enterprise/Gemfile index af3f2effc..1e01eae63 100644 --- a/oa-enterprise/Gemfile +++ b/oa-enterprise/Gemfile @@ -4,8 +4,4 @@ platforms :jruby do gem 'jruby-openssl', '~> 0.7' end -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec diff --git a/oa-enterprise/oa-enterprise.gemspec b/oa-enterprise/oa-enterprise.gemspec index a0fcc016b..fece3659c 100644 --- a/oa-enterprise/oa-enterprise.gemspec +++ b/oa-enterprise/oa-enterprise.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rake', '~> 0.8' gem.add_development_dependency 'rspec', '~> 2.5' gem.add_development_dependency 'webmock', '~> 1.6' - # gem.add_development_dependency 'yard', '~> 0.7' + gem.add_development_dependency 'yard', '~> 0.7' gem.add_development_dependency 'ZenTest', '~> 4.5' gem.name = 'oa-enterprise' gem.version = OmniAuth::Version::STRING diff --git a/oa-more/Gemfile b/oa-more/Gemfile index af3f2effc..1e01eae63 100644 --- a/oa-more/Gemfile +++ b/oa-more/Gemfile @@ -4,8 +4,4 @@ platforms :jruby do gem 'jruby-openssl', '~> 0.7' end -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec diff --git a/oa-more/oa-more.gemspec b/oa-more/oa-more.gemspec index d617cc9ac..eb355e05e 100644 --- a/oa-more/oa-more.gemspec +++ b/oa-more/oa-more.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rspec', '~> 2.5' gem.add_development_dependency 'simplecov', '~> 0.4' gem.add_development_dependency 'webmock', '~> 1.6' - # gem.add_development_dependency 'yard', '~> 0.7' + gem.add_development_dependency 'yard', '~> 0.7' gem.add_development_dependency 'ZenTest', '~> 4.5' gem.name = 'oa-more' gem.version = OmniAuth::Version::STRING diff --git a/oa-oauth/Gemfile b/oa-oauth/Gemfile index af3f2effc..1e01eae63 100644 --- a/oa-oauth/Gemfile +++ b/oa-oauth/Gemfile @@ -4,8 +4,4 @@ platforms :jruby do gem 'jruby-openssl', '~> 0.7' end -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec diff --git a/oa-oauth/oa-oauth.gemspec b/oa-oauth/oa-oauth.gemspec index 0e0f3d8bf..0f7e56570 100644 --- a/oa-oauth/oa-oauth.gemspec +++ b/oa-oauth/oa-oauth.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rspec', '~> 2.5' gem.add_development_dependency 'simplecov', '~> 0.4' gem.add_development_dependency 'webmock', '~> 1.6' - # gem.add_development_dependency 'yard', '~> 0.7' + gem.add_development_dependency 'yard', '~> 0.7' gem.add_development_dependency 'ZenTest', '~> 4.5' gem.name = 'oa-oauth' gem.version = OmniAuth::Version::STRING diff --git a/oa-openid/Gemfile b/oa-openid/Gemfile index af3f2effc..1e01eae63 100644 --- a/oa-openid/Gemfile +++ b/oa-openid/Gemfile @@ -4,8 +4,4 @@ platforms :jruby do gem 'jruby-openssl', '~> 0.7' end -group :development do - gem 'yard', :git => 'https://github.com/lsegal/yard.git' -end - gemspec diff --git a/oa-openid/oa-openid.gemspec b/oa-openid/oa-openid.gemspec index 386452768..522f80b95 100644 --- a/oa-openid/oa-openid.gemspec +++ b/oa-openid/oa-openid.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rspec', '~> 2.5' gem.add_development_dependency 'simplecov', '~> 0.4' gem.add_development_dependency 'webmock', '~> 1.6' - # gem.add_development_dependency 'yard', '~> 0.7' + gem.add_development_dependency 'yard', '~> 0.7' gem.add_development_dependency 'ZenTest', '~> 4.5' gem.name = 'oa-openid' gem.version = OmniAuth::Version::STRING From b9e8fd1be98b026672da85e2c4b4e63c3b4f1640 Mon Sep 17 00:00:00 2001 From: albb0920 Date: Thu, 19 May 2011 00:57:54 +0800 Subject: [PATCH 22/35] add plurk strategy --- README.md | 1 + oa-oauth/lib/omniauth/oauth.rb | 1 + oa-oauth/lib/omniauth/strategies/plurk.rb | 58 +++++++++++++++++++ .../spec/omniauth/strategies/plurk_spec.rb | 5 ++ 4 files changed, 65 insertions(+) create mode 100644 oa-oauth/lib/omniauth/strategies/plurk.rb create mode 100644 oa-oauth/spec/omniauth/strategies/plurk_spec.rb diff --git a/README.md b/README.md index 9aeaf4655..1fec37811 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ OmniAuth currently supports the following external providers: * Miso (credit: [rickenharp](https://github.com/rickenharp)) * Mixi (credit: [kiyoshi](https://github.com/kiyoshi)) * Netflix (credit: [caged](https://github.com/caged)) + * Plurk (credit: [albb0920](http://github.com/albb0920)) * Qzone (credit: [quake](https://github.com/quake)) * Rdio (via [brandonweiss](https://github.com/brandonweiss)) * Renren (credit: [quake](https://github.com/quake)) diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index cda935563..549ed2bae 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -28,6 +28,7 @@ module Strategies autoload :Mixi, 'omniauth/strategies/mixi' autoload :Netflix, 'omniauth/strategies/netflix' autoload :Qzone, 'omniauth/strategies/qzone' + autoload :Plurk, 'omniauth/strategies/plurk' autoload :Rdio, 'omniauth/strategies/rdio' autoload :Renren, 'omniauth/strategies/renren' autoload :Salesforce, 'omniauth/strategies/salesforce' diff --git a/oa-oauth/lib/omniauth/strategies/plurk.rb b/oa-oauth/lib/omniauth/strategies/plurk.rb new file mode 100644 index 000000000..637f2c55f --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/plurk.rb @@ -0,0 +1,58 @@ +require 'omniauth/oauth' +require 'multi_json' + +module OmniAuth + module Strategies + # + # Authenticate to Plurk via OAuth and retrieve basic user info. + # + # Please note that this strategy relies on Plurk API 2.0, + # which is still in Beta. + # + # Usage: + # use OmniAuth::Strategies::Plurk + class Plurk < OmniAuth::Strategies::OAuth + + # @param [Rack Application] app standard middleware application parameter + # @param [String] client_key App key [registered on plurk] (http://www.plurk.com/PlurkApp/register) + # @param [String] client_secret App secret registered on plurk + def initialize(app, client_key = nil, client_secret = nil, options = {}, &block) + client_options = { :site => 'http://www.plurk.com', + :request_token_path => '/OAuth/request_token', + :access_token_path => '/OAuth/access_token', + :authorize_path => '/OAuth/authorize' } + + super(app, :plurk, client_key, client_secret, client_options, options) + end + + def auth_hash + user = self.user_hash + OmniAuth::Utils.deep_merge(super, { + 'uid' => user['id'], + 'user_info' => user_info, + 'extra' => {'user_hash' => user_hash} + }) + end + + def user_info + user = self.user_hash + { + 'name' => user['full_name'], + 'nickname' => user['display_name'] || user['nick_name'], + 'location' => user['location'], + 'image' => if user['has_profile_image'] == 1 + "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif" + else + "http://www.plurk.com/static/default_medium.gif" + end, + 'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']} + } + end + + def user_hash + @user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info'] + end + + end + end +end diff --git a/oa-oauth/spec/omniauth/strategies/plurk_spec.rb b/oa-oauth/spec/omniauth/strategies/plurk_spec.rb new file mode 100644 index 000000000..d92d8d8a5 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/plurk_spec.rb @@ -0,0 +1,5 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe OmniAuth::Strategies::Plurk do + it_should_behave_like 'an oauth strategy' +end From cc9fbe6a46277cad6663e51cdad907b1f1683d57 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 19 May 2011 10:40:43 -0400 Subject: [PATCH 23/35] Added initial spec to LDAP strategy. Adopting the idea that an empty file is better than no file, and a single spec is better than no spec. --- .../spec/omniauth/strategies/ldap_spec.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 oa-enterprise/spec/omniauth/strategies/ldap_spec.rb diff --git a/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb b/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb new file mode 100644 index 000000000..29b4ae5c0 --- /dev/null +++ b/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb @@ -0,0 +1,30 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'cgi' + +describe OmniAuth::Strategies::LDAP, :type => :strategy do + + include OmniAuth::Test::StrategyTestCase + + def strategy + @ldap_server ||= 'ldap.example.org' + [OmniAuth::Strategies::LDAP, { + :host => @ldap_server, + :port => 636, + :method => :ssl, + :uid => 'jeremyf', + :base => 'o="University of OmniAuth", st=Sublime, c=RubyNation', + }] + end + + describe 'GET /auth/ldap' do + before do + get '/auth/ldap' + end + + # TODO: Add checks that page has authentication form; I attempted + # to use `should have_tag` but that was not working. + it 'should get authentication page' do + last_response.status.should == 200 + end + end +end \ No newline at end of file From 5b2858ef3033779ac3237f037707f5e225f22596 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 19 May 2011 13:26:10 -0400 Subject: [PATCH 24/35] Added second test to verify POST behavior to /auth/ldap. --- oa-enterprise/spec/omniauth/strategies/ldap_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb b/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb index 29b4ae5c0..0517fbd13 100644 --- a/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb +++ b/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb @@ -27,4 +27,15 @@ def strategy last_response.status.should == 200 end end + + describe 'POST /auth/ldap' do + before do + post '/auth/ldap', {:username => 'jeremy', :password => 'valid_password' } + end + + it 'should redirect us to /auth/ldap/callback' do + last_response.should be_redirect + last_response.location.should == '/auth/ldap/callback' + end + end end \ No newline at end of file From c3d474a7538013f89c8850d6b3fe1720a46d15e3 Mon Sep 17 00:00:00 2001 From: Leo Lou Date: Sat, 21 May 2011 02:28:45 +0800 Subject: [PATCH 25/35] Added Taobao strategy --- README.md | 1 + oa-oauth/lib/omniauth/oauth.rb | 1 + oa-oauth/lib/omniauth/strategies/taobao.rb | 79 +++++++++++++++++++ .../spec/omniauth/strategies/taobao_spec.rb | 5 ++ 4 files changed, 86 insertions(+) create mode 100644 oa-oauth/lib/omniauth/strategies/taobao.rb create mode 100644 oa-oauth/spec/omniauth/strategies/taobao_spec.rb diff --git a/README.md b/README.md index 1fec37811..87da6f70b 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ OmniAuth currently supports the following external providers: * SmugMug (credit: [pchilton](https://github.com/pchilton)) * SoundCloud (credit: [leemartin](https://github.com/leemartin)) * T163 (credit: [quake](https://github.com/quake)) + * Taobao (credit: [l4u](https://github.com/l4u)) * TeamBox (credit [jrom](https://github.com/jrom)) * Tqq (credit: [quake](https://github.com/quake)) * TradeMe (credit: [pchilton](https://github.com/pchilton)) diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index 549ed2bae..105b5f952 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -35,6 +35,7 @@ module Strategies autoload :SmugMug, 'omniauth/strategies/smug_mug' autoload :SoundCloud, 'omniauth/strategies/sound_cloud' autoload :T163, 'omniauth/strategies/t163' + autoload :Taobao, 'omniauth/strategies/taobao' autoload :Teambox, 'omniauth/strategies/teambox' autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals' autoload :Tqq, 'omniauth/strategies/tqq' diff --git a/oa-oauth/lib/omniauth/strategies/taobao.rb b/oa-oauth/lib/omniauth/strategies/taobao.rb new file mode 100644 index 000000000..f9bf8735b --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/taobao.rb @@ -0,0 +1,79 @@ +require 'omniauth/oauth' +require 'multi_json' +require 'digest/md5' +require 'net/http' + +module OmniAuth + module Strategies + # Authenticate to Renren utilizing OAuth 2.0 and retrieve + # basic user information. + # + # @example Basic Usage + # use OmniAuth::Strategies::Taobao, 'client_id', 'client_secret' + class Taobao < OAuth2 + # @param [Rack Application] app standard middleware application parameter + # @param [String] client_id the app key at taobao open platform + # @param [String] client_secret the app secret at taobao open platform + # @option options [String] + + def initialize(app, client_id = nil, client_secret = nil, options = {}, &block) + client_options = { + :site => "https://oauth.taobao.com/", + :authorize_url => "/authorize", + :access_token_url => "/token" + } + + super(app, :taobao, client_id, client_secret, client_options, options, &block) + end + + def user_data + # TODO to be moved in options + url = 'http://gw.api.taobao.com/router/rest' + + query_param = { + :app_key => client_id, + + # TODO to be moved in options + # TODO add more default fields (http://my.open.taobao.com/apidoc/index.htm#categoryId:1-dataStructId:3) + :fields => 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind', + :format => 'json', + :method => 'taobao.user.get', + :session => @access_token.token, + :sign_method => 'md5', + :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S"), + :v => '2.0' + } + query_param = generate_sign(query_param) + res = Net::HTTP.post_form(URI.parse(url), query_param) + @data ||= MultiJson.decode(res.body)["user_get_response"]["user"] + end + + def request_phase + options[:state] ||= '1' + super + end + + def user_info + { + 'name' => user_data["nick"], + 'email' => (user_data["email"] if user_data["email"]), + } + end + + def auth_hash + OmniAuth::Utils.deep_merge(super, { + 'uid' => user_data['uid'], + 'user_info' => user_info, + 'extra' => {'user_hash' => user_data} + }) + end + + def generate_sign(params) + str = client_secret + (params.sort.collect { |k, v| "#{k}#{v}" }).join + client_secret + params["sign"] = Digest::MD5.hexdigest(str).upcase! + params + end + + end + end +end diff --git a/oa-oauth/spec/omniauth/strategies/taobao_spec.rb b/oa-oauth/spec/omniauth/strategies/taobao_spec.rb new file mode 100644 index 000000000..e40c4d250 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/taobao_spec.rb @@ -0,0 +1,5 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe OmniAuth::Strategies::Taobao do + it_should_behave_like "an oauth2 strategy" +end From 189177a77855d392b9682ec9a6ef495feefd5831 Mon Sep 17 00:00:00 2001 From: Leo Lou Date: Sat, 21 May 2011 03:22:13 +0800 Subject: [PATCH 26/35] changed taobao to tb because their API doesnt allow the use of the word taobao in the callback url --- oa-oauth/lib/omniauth/oauth.rb | 2 +- oa-oauth/lib/omniauth/strategies/taobao.rb | 6 +++--- oa-oauth/spec/omniauth/strategies/taobao_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index 105b5f952..24de93857 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -35,7 +35,7 @@ module Strategies autoload :SmugMug, 'omniauth/strategies/smug_mug' autoload :SoundCloud, 'omniauth/strategies/sound_cloud' autoload :T163, 'omniauth/strategies/t163' - autoload :Taobao, 'omniauth/strategies/taobao' + autoload :TB, 'omniauth/strategies/taobao' autoload :Teambox, 'omniauth/strategies/teambox' autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals' autoload :Tqq, 'omniauth/strategies/tqq' diff --git a/oa-oauth/lib/omniauth/strategies/taobao.rb b/oa-oauth/lib/omniauth/strategies/taobao.rb index f9bf8735b..59bb7eb1a 100644 --- a/oa-oauth/lib/omniauth/strategies/taobao.rb +++ b/oa-oauth/lib/omniauth/strategies/taobao.rb @@ -9,8 +9,8 @@ module Strategies # basic user information. # # @example Basic Usage - # use OmniAuth::Strategies::Taobao, 'client_id', 'client_secret' - class Taobao < OAuth2 + # use OmniAuth::Strategies::TB, 'client_id', 'client_secret' + class TB < OAuth2 # @param [Rack Application] app standard middleware application parameter # @param [String] client_id the app key at taobao open platform # @param [String] client_secret the app secret at taobao open platform @@ -23,7 +23,7 @@ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block) :access_token_url => "/token" } - super(app, :taobao, client_id, client_secret, client_options, options, &block) + super(app, :tb, client_id, client_secret, client_options, options, &block) end def user_data diff --git a/oa-oauth/spec/omniauth/strategies/taobao_spec.rb b/oa-oauth/spec/omniauth/strategies/taobao_spec.rb index e40c4d250..fd87051f8 100644 --- a/oa-oauth/spec/omniauth/strategies/taobao_spec.rb +++ b/oa-oauth/spec/omniauth/strategies/taobao_spec.rb @@ -1,5 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe OmniAuth::Strategies::Taobao do +describe OmniAuth::Strategies::TB do it_should_behave_like "an oauth2 strategy" end From 9c1e5ce8ce4504d1ffa9a6b6619a2e5216fdda24 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Fri, 20 May 2011 15:56:36 -0500 Subject: [PATCH 27/35] Fix addressable dependency in oa-enterprise. --- oa-enterprise/oa-enterprise.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oa-enterprise/oa-enterprise.gemspec b/oa-enterprise/oa-enterprise.gemspec index fece3659c..0338fc141 100644 --- a/oa-enterprise/oa-enterprise.gemspec +++ b/oa-enterprise/oa-enterprise.gemspec @@ -2,7 +2,7 @@ require File.expand_path('../lib/omniauth/version', __FILE__) Gem::Specification.new do |gem| - gem.add_runtime_dependency 'addressable', '~> 2.2.6' + gem.add_runtime_dependency 'addressable', '2.2.4' gem.add_runtime_dependency 'nokogiri', '~> 1.4.2' gem.add_runtime_dependency 'net-ldap', '~> 0.2.2' gem.add_runtime_dependency 'oa-core', OmniAuth::Version::STRING From 0fefb9c8d7053598d7b643796e5ad9a17a689b61 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Fri, 20 May 2011 14:03:50 -0700 Subject: [PATCH 28/35] Cleanup EOL whitespace --- oa-core/lib/omniauth/strategy.rb | 8 +++---- .../cas/service_ticket_validator.rb | 4 ++-- oa-more/lib/omniauth/strategies/draugiem.rb | 16 ++++++------- oa-more/lib/omniauth/strategies/ign.rb | 24 +++++++++---------- oa-more/lib/omniauth/strategies/yupoo.rb | 16 ++++++------- .../spec/omniauth/strategies/draugiem_spec.rb | 24 +++++++++---------- oa-oauth/lib/omniauth/oauth.rb | 2 +- oa-oauth/lib/omniauth/strategies/linked_in.rb | 4 ++-- oa-oauth/lib/omniauth/strategies/mailru.rb | 24 +++++++++---------- oa-oauth/lib/omniauth/strategies/plurk.rb | 4 ++-- oa-oauth/lib/omniauth/strategies/taobao.rb | 4 ++-- oa-openid/lib/omniauth/strategies/steam.rb | 6 ++--- 12 files changed, 68 insertions(+), 68 deletions(-) diff --git a/oa-core/lib/omniauth/strategy.rb b/oa-core/lib/omniauth/strategy.rb index cce594ad6..273206cee 100644 --- a/oa-core/lib/omniauth/strategy.rb +++ b/oa-core/lib/omniauth/strategy.rb @@ -3,7 +3,7 @@ module OmniAuth class NoSessionError < StandardError; end # The Strategy is the base unit of OmniAuth's ability to - # wrangle multiple providers. Each strategy provided by + # wrangle multiple providers. Each strategy provided by # OmniAuth includes this mixin to gain the default functionality # necessary to be compatible with the OmniAuth library. module Strategy @@ -41,9 +41,9 @@ def call!(env) return request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym) return callback_call if on_callback_path? return other_phase if respond_to?(:other_phase) - @app.call(env) + @app.call(env) end - + # Performs the steps necessary to run the request phase of a strategy. def request_call setup_phase @@ -81,7 +81,7 @@ def on_callback_path? end def mock_call!(env) - return mock_request_call if on_request_path? + return mock_request_call if on_request_path? return mock_callback_call if on_callback_path? call_app! end diff --git a/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb b/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb index 7433e0a4d..0a1249ab4 100644 --- a/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +++ b/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb @@ -39,14 +39,14 @@ def user_info def parse_user_info(node) return nil if node.nil? hash = {} - node.children.each do |e| + node.children.each do |e| unless e.kind_of?(Nokogiri::XML::Text) || e.name == 'cas:proxies' || e.name == 'proxies' # There are no child elements if e.element_children.count == 0 hash[e.name.sub(/^cas:/, '')] = e.content - elsif e.element_children.count + elsif e.element_children.count hash[e.name.sub(/^cas:/, '')] = [] if hash[e.name.sub(/^cas:/, '')].nil? hash[e.name.sub(/^cas:/, '')].push parse_user_info e end diff --git a/oa-more/lib/omniauth/strategies/draugiem.rb b/oa-more/lib/omniauth/strategies/draugiem.rb index 6262efe74..e7a659cf2 100644 --- a/oa-more/lib/omniauth/strategies/draugiem.rb +++ b/oa-more/lib/omniauth/strategies/draugiem.rb @@ -9,10 +9,10 @@ module Strategies # Authenticate to draugiem.lv and frype.com and others. # # @example Basic Rails Usage - # + # # Add this to config/initializers/omniauth.rb - # - # Rails.application.config.middleware.use OmniAuth::Builder do + # + # Rails.application.config.middleware.use OmniAuth::Builder do # provider :draugiem, 'App id', 'API Key' # end # @@ -32,7 +32,7 @@ def initialize(app, app_id, api_key) end protected - + def request_phase params = { :app => @app_id, @@ -42,7 +42,7 @@ def request_phase query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&') redirect "http://api.draugiem.lv/authorize/?#{query_string}" end - + def callback_phase if request.params['dr_auth_status'] == 'ok' && request.params['dr_auth_code'] response = RestClient.get('http://api.draugiem.lv/json/', { :params => draugiem_authorize_params(request.params['dr_auth_code']) }) @@ -59,7 +59,7 @@ def callback_phase rescue Exception => e fail!(:invalid_response, e) end - + def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => @auth_data['uid'], @@ -70,8 +70,8 @@ def auth_hash 'extra' => { 'user_hash' => @auth_data } }) end - - private + + private def get_user_info if @auth_data['users'] && @auth_data['users'][@auth_data['uid']] diff --git a/oa-more/lib/omniauth/strategies/ign.rb b/oa-more/lib/omniauth/strategies/ign.rb index 27e367580..8d4a964d3 100644 --- a/oa-more/lib/omniauth/strategies/ign.rb +++ b/oa-more/lib/omniauth/strategies/ign.rb @@ -6,7 +6,7 @@ module Strategies class Ign include OmniAuth::Strategy IDENTIFIER_URL_PARAMETER = "" - + class CallbackError < StandardError attr_accessor :error, :error_reason def initialize(error, error_reason) @@ -14,32 +14,32 @@ def initialize(error, error_reason) self.error_reason = error_reason end end - + def initialize(app, api_key, hostname=nil, options = {}) options[:name] ||= "ign" super(app, :ign) @api_key = api_key @hostname = hostname end - + protected - + def request_phase OmniAuth::Form.build(:title => 'IGN Authentication', :header_info=>js) do label_field('Identifying you with the IGN server', IDENTIFIER_URL_PARAMETER) end.to_response end - + def callback_phase signature = OpenSSL::HMAC.hexdigest('sha1', @api_key, ("#{request.params["username"]}::#{request.params["timestamp"]}")) - + raise CallbackError.new("Invalid Signature","The supplied and calculated signature did not match, user not approved.") if signature != request.params["signature"] - + super rescue CallbackError => e fail!(:invalid_response, e) end - + def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => "ign-" + request.params["username"], @@ -48,13 +48,13 @@ def auth_hash 'extra' => { 'user_hash' => request.params } }) end - + def user_info { 'nickname' => request.params["username"], } end - + def js @js = <<-JS $(document).ready(function() { @@ -87,7 +87,7 @@ def js "\n" + "\n" end - + end end -end \ No newline at end of file +end diff --git a/oa-more/lib/omniauth/strategies/yupoo.rb b/oa-more/lib/omniauth/strategies/yupoo.rb index 1d471a8c3..a76b58180 100644 --- a/oa-more/lib/omniauth/strategies/yupoo.rb +++ b/oa-more/lib/omniauth/strategies/yupoo.rb @@ -8,7 +8,7 @@ module Strategies class Yupoo include OmniAuth::Strategy attr_accessor :api_key, :secret_key, :options - + class CallbackError < StandardError attr_accessor :error, :error_reason @@ -26,30 +26,30 @@ def initialize(app, api_key, secret_key, options = {}) end protected - + def request_phase params = { :api_key => api_key, :perms => options[:scope] } params[:api_sig] = yupoo_sign(params) query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&') redirect "http://www.yupoo.com/services/auth/?#{query_string}" end - + def callback_phase params = { :api_key => api_key, :method => 'yupoo.auth.getToken', :frob => request.params['frob'], :format => 'json', :nojsoncallback => '1' } params[:api_sig] = yupoo_sign(params) - + response = RestClient.get('http://www.yupoo.com/api/rest/', { :params => params }) auth = MultiJson.decode(response.to_s) raise CallbackError.new(auth['code'],auth['message']) if auth['stat'] == 'fail' - + @user = auth['auth']['user'] @access_token = auth['auth']['token']['_content'] - + super rescue CallbackError => e fail!(:invalid_response, e) end - + def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => @user['nsid'], @@ -58,7 +58,7 @@ def auth_hash 'extra' => { 'user_hash' => @user } }) end - + def yupoo_sign(params) Digest::MD5.hexdigest(secret_key + params.sort{|a,b| a[0].to_s <=> b[0].to_s }.flatten.join) end diff --git a/oa-more/spec/omniauth/strategies/draugiem_spec.rb b/oa-more/spec/omniauth/strategies/draugiem_spec.rb index e36f4ce9c..413b8db7a 100644 --- a/oa-more/spec/omniauth/strategies/draugiem_spec.rb +++ b/oa-more/spec/omniauth/strategies/draugiem_spec.rb @@ -15,7 +15,7 @@ def strategy describe '/auth/draugiem' do it 'should redirect to api.draugiem.lv' do - get '/auth/draugiem' + get '/auth/draugiem' last_response.should be_redirect last_response.headers['Location'].should == "http://api.draugiem.lv/authorize/?app=123&redirect=http%3A%2F%2Fexample.org%2Fauth%2Fdraugiem%2Fcallback&hash=2d5698ba02ddd42c441998a5a2c2946b" end @@ -23,19 +23,19 @@ def strategy it 'should gather user data after success authorization' do stub_request(:get, "http://api.draugiem.lv/json/?action=authorize&app=abc&code=123456"). to_return(:body => MultiJson.encode({ - 'apikey'=>"123456789", - 'uid'=>"100", - 'language'=>"lv", + 'apikey'=>"123456789", + 'uid'=>"100", + 'language'=>"lv", 'users'=>{ '100'=>{ - 'uid'=>"100", - 'name'=>"John", - 'surname'=>"Lenon", - 'nick'=>"johnybravo", - 'place'=>"Durbe", - 'age'=>"false", - 'adult'=>"1", - 'img'=>"http://4.bp.blogspot.com/_ZmXOoYjxXog/Sg2jby1RFSI/AAAAAAAAE_Q/1LpfjimAz50/s400/JohnnyBravo3.gif", + 'uid'=>"100", + 'name'=>"John", + 'surname'=>"Lenon", + 'nick'=>"johnybravo", + 'place'=>"Durbe", + 'age'=>"false", + 'adult'=>"1", + 'img'=>"http://4.bp.blogspot.com/_ZmXOoYjxXog/Sg2jby1RFSI/AAAAAAAAE_Q/1LpfjimAz50/s400/JohnnyBravo3.gif", 'sex'=>"M" } } diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index 24de93857..65b3284f6 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -51,6 +51,6 @@ module Strategies autoload :Yahoo, 'omniauth/strategies/yahoo' autoload :Yammer, 'omniauth/strategies/yammer' autoload :YouTube, 'omniauth/strategies/you_tube' - autoload :Mailru, 'omniauth/strategies/mailru' + autoload :Mailru, 'omniauth/strategies/mailru' end end diff --git a/oa-oauth/lib/omniauth/strategies/linked_in.rb b/oa-oauth/lib/omniauth/strategies/linked_in.rb index 019c9fd79..b533865eb 100644 --- a/oa-oauth/lib/omniauth/strategies/linked_in.rb +++ b/oa-oauth/lib/omniauth/strategies/linked_in.rb @@ -40,13 +40,13 @@ def user_hash(access_token) 'description' => person['headline'], 'public_profile_url' => person['public_profile_url'] } - hash['urls']={} + hash['urls']={} member_urls = person['member_url_resources']['member_url'] if (!member_urls.nil?) and (!member_urls.empty?) [member_urls].flatten.each do |url| hash['urls']["#{url['name']}"]=url['url'] end - end + end hash['urls']['LinkedIn'] = person['public_profile_url'] hash['name'] = "#{hash['first_name']} #{hash['last_name']}" hash diff --git a/oa-oauth/lib/omniauth/strategies/mailru.rb b/oa-oauth/lib/omniauth/strategies/mailru.rb index c12e5b5dd..ddeec9d8a 100644 --- a/oa-oauth/lib/omniauth/strategies/mailru.rb +++ b/oa-oauth/lib/omniauth/strategies/mailru.rb @@ -14,30 +14,30 @@ module Strategies class Mailru < OAuth2 # @param [Rack Application] app standard middleware application parameter # @param [String] api_key the application id as [registered in Mailru] - # @param [String] secret_key the application secret as [registered in Mailru] + # @param [String] secret_key the application secret as [registered in Mailru] def initialize(app, api_key = nil, secret_key = nil, options = {}, &block) client_options = { :site => 'https://connect.mail.ru', :authorize_path => '/oauth/authorize', :access_token_path => '/oauth/token' } - - @private_key = options[:private_key] + + @private_key = options[:private_key] super(app, :mailru, api_key, secret_key, client_options, options, &block) end protected - + def request_phase options[:response_type] ||= 'code' super - end - + end + def calculate_signature(params) str = params['uids'] + (params.sort.collect { |c| "#{c[0]}=#{c[1]}" }).join('') + @private_key Digest::MD5.hexdigest(str) - end + end def user_data request_params = { @@ -46,7 +46,7 @@ def user_data 'session_key' => @access_token.token, 'uids' => @access_token['x_mailru_vid'] } - + request_params.merge!('sig' => calculate_signature(request_params)) @data ||= MultiJson.decode(client.request(:get, 'http://www.appsmail.ru/platform/api', request_params))[0] end @@ -82,7 +82,7 @@ def user_data #} def user_info - { + { 'nickname' => user_data['nick'], 'email' => user_data['email'], 'first_name' => user_data["first_name"], @@ -91,8 +91,8 @@ def user_info 'image' => @data['pic'], 'urls' => { 'Mailru' => user_data["link"] - } - } + } + } end def auth_hash @@ -102,6 +102,6 @@ def auth_hash 'extra' => {'user_hash' => user_data} }) end - end + end end end diff --git a/oa-oauth/lib/omniauth/strategies/plurk.rb b/oa-oauth/lib/omniauth/strategies/plurk.rb index 637f2c55f..19ae647f3 100644 --- a/oa-oauth/lib/omniauth/strategies/plurk.rb +++ b/oa-oauth/lib/omniauth/strategies/plurk.rb @@ -6,7 +6,7 @@ module Strategies # # Authenticate to Plurk via OAuth and retrieve basic user info. # - # Please note that this strategy relies on Plurk API 2.0, + # Please note that this strategy relies on Plurk API 2.0, # which is still in Beta. # # Usage: @@ -45,7 +45,7 @@ def user_info else "http://www.plurk.com/static/default_medium.gif" end, - 'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']} + 'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']} } end diff --git a/oa-oauth/lib/omniauth/strategies/taobao.rb b/oa-oauth/lib/omniauth/strategies/taobao.rb index 59bb7eb1a..31fac20fb 100644 --- a/oa-oauth/lib/omniauth/strategies/taobao.rb +++ b/oa-oauth/lib/omniauth/strategies/taobao.rb @@ -12,9 +12,9 @@ module Strategies # use OmniAuth::Strategies::TB, 'client_id', 'client_secret' class TB < OAuth2 # @param [Rack Application] app standard middleware application parameter - # @param [String] client_id the app key at taobao open platform + # @param [String] client_id the app key at taobao open platform # @param [String] client_secret the app secret at taobao open platform - # @option options [String] + # @option options [String] def initialize(app, client_id = nil, client_secret = nil, options = {}, &block) client_options = { diff --git a/oa-openid/lib/omniauth/strategies/steam.rb b/oa-openid/lib/omniauth/strategies/steam.rb index 4169c9350..18f87ec3d 100644 --- a/oa-openid/lib/omniauth/strategies/steam.rb +++ b/oa-openid/lib/omniauth/strategies/steam.rb @@ -5,10 +5,10 @@ class Steam < OmniAuth::Strategies::OpenID def initialize(app, store = nil, api_key = nil, options = {}, &block) options[:identifier] ||= "http://steamcommunity.com/openid" options[:name] ||= 'steam' - @api_key = api_key + @api_key = api_key super(app, store, options, &block) end - + def user_info(response=nil) player = user_hash['response']['players']['player'].first nickname = player["personaname"] @@ -25,7 +25,7 @@ def user_info(response=nil) 'location' => "#{city}, #{state}, #{country}" } end - + def user_hash # Steam provides no information back on a openid response other than a 64bit user id # Need to use this information and make a API call to get user information from steam. From 0e4edcfdf8ee5d8af71bd0862d05fc4fe1877ce9 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Fri, 20 May 2011 14:05:22 -0700 Subject: [PATCH 29/35] Fix spec that depended on hash ordering --- oa-more/spec/omniauth/strategies/draugiem_spec.rb | 2 +- oa-more/spec/spec_helper.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/oa-more/spec/omniauth/strategies/draugiem_spec.rb b/oa-more/spec/omniauth/strategies/draugiem_spec.rb index 413b8db7a..757c5ae8b 100644 --- a/oa-more/spec/omniauth/strategies/draugiem_spec.rb +++ b/oa-more/spec/omniauth/strategies/draugiem_spec.rb @@ -17,7 +17,7 @@ def strategy it 'should redirect to api.draugiem.lv' do get '/auth/draugiem' last_response.should be_redirect - last_response.headers['Location'].should == "http://api.draugiem.lv/authorize/?app=123&redirect=http%3A%2F%2Fexample.org%2Fauth%2Fdraugiem%2Fcallback&hash=2d5698ba02ddd42c441998a5a2c2946b" + last_response.headers['Location'].should match %r{http://api\.draugiem\.lv/authorize/} end it 'should gather user data after success authorization' do diff --git a/oa-more/spec/spec_helper.rb b/oa-more/spec/spec_helper.rb index adc41482f..8f8fcfa2c 100644 --- a/oa-more/spec/spec_helper.rb +++ b/oa-more/spec/spec_helper.rb @@ -3,10 +3,9 @@ require 'rspec' require 'rack/test' require 'webmock/rspec' -$:< Date: Fri, 20 May 2011 16:07:58 -0500 Subject: [PATCH 30/35] Bumping version to 0.2.6 --- lib/omniauth/version.rb | 2 +- oa-basic/lib/omniauth/version.rb | 2 +- oa-core/lib/omniauth/version.rb | 2 +- oa-enterprise/lib/omniauth/version.rb | 2 +- oa-more/lib/omniauth/version.rb | 2 +- oa-oauth/lib/omniauth/version.rb | 2 +- oa-openid/lib/omniauth/version.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/omniauth/version.rb b/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/lib/omniauth/version.rb +++ b/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil diff --git a/oa-basic/lib/omniauth/version.rb b/oa-basic/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/oa-basic/lib/omniauth/version.rb +++ b/oa-basic/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil diff --git a/oa-core/lib/omniauth/version.rb b/oa-core/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/oa-core/lib/omniauth/version.rb +++ b/oa-core/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil diff --git a/oa-enterprise/lib/omniauth/version.rb b/oa-enterprise/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/oa-enterprise/lib/omniauth/version.rb +++ b/oa-enterprise/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil diff --git a/oa-more/lib/omniauth/version.rb b/oa-more/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/oa-more/lib/omniauth/version.rb +++ b/oa-more/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil diff --git a/oa-oauth/lib/omniauth/version.rb b/oa-oauth/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/oa-oauth/lib/omniauth/version.rb +++ b/oa-oauth/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil diff --git a/oa-openid/lib/omniauth/version.rb b/oa-openid/lib/omniauth/version.rb index e7d56b2ea..91476f067 100644 --- a/oa-openid/lib/omniauth/version.rb +++ b/oa-openid/lib/omniauth/version.rb @@ -7,7 +7,7 @@ module Version MINOR = 2 end unless defined?(::OmniAuth::Version::PATCH) - PATCH = 5 + PATCH = 6 end unless defined?(::OmniAuth::Version::PRE) PRE = nil From 0e07f3f219e7c073a51285bb2ec6f3d4e308de4b Mon Sep 17 00:00:00 2001 From: Qi He Date: Mon, 2 May 2011 07:06:48 +0800 Subject: [PATCH 31/35] sina --- oa-oauth/lib/omniauth/strategies/tsina.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/oa-oauth/lib/omniauth/strategies/tsina.rb b/oa-oauth/lib/omniauth/strategies/tsina.rb index 89cd6819f..fdf83e1ac 100644 --- a/oa-oauth/lib/omniauth/strategies/tsina.rb +++ b/oa-oauth/lib/omniauth/strategies/tsina.rb @@ -66,6 +66,13 @@ def request_phase rescue ::Timeout::Error => e fail!(:timeout, e) end + + # MonkeyPath to symbolize tina parameters + def callback_phase + session[:oauth].symbolize_keys! + session[:oauth][name.to_sym].symbolize_keys! if session[:oauth][name.to_sym] + super + end def user_hash # http://api.t.sina.com.cn/users/show/:id.json?source=appkey From 1bfab1ea5832302413a0b7c32e215ac07298d43d Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 24 May 2011 15:15:14 -0700 Subject: [PATCH 32/35] Add credentials params --- oa-oauth/lib/omniauth/strategies/mixi.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/oa-oauth/lib/omniauth/strategies/mixi.rb b/oa-oauth/lib/omniauth/strategies/mixi.rb index 6cadb0ed0..eb336bacd 100644 --- a/oa-oauth/lib/omniauth/strategies/mixi.rb +++ b/oa-oauth/lib/omniauth/strategies/mixi.rb @@ -43,7 +43,7 @@ def user_info { 'nickname' => user_data['entry']['displayName'], 'image' => user_data['entry']['thumbnailUrl'], - 'urls' => {:profile => user_data['entry']['profileUrl']} + 'urls' => {:profile => user_data['entry']['profileUrl']}, } end @@ -51,7 +51,8 @@ def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user_data['entry']['id'], 'user_info' => user_info, - 'extra' => {'user_hash' => user_data['entry']} + 'credentials' => {'refresh_token' => @access_token.refresh_token}, + 'extra' => {'user_hash' => user_data['entry']}, }) end end From 5271a9d353741f9de80445b24b9a1c258ee4e079 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 24 May 2011 15:26:50 -0700 Subject: [PATCH 33/35] Allow passing params from initial auth link to callback --- oa-core/lib/omniauth/strategy.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/oa-core/lib/omniauth/strategy.rb b/oa-core/lib/omniauth/strategy.rb index 273206cee..0d8cb5ad4 100644 --- a/oa-core/lib/omniauth/strategy.rb +++ b/oa-core/lib/omniauth/strategy.rb @@ -126,6 +126,8 @@ def request_phase def callback_phase @env['omniauth.auth'] = auth_hash + @env['omniauth.params'] = session['query_params'] || {} + session['query_params'] = nil if session['query_params'] call_app! end @@ -155,6 +157,7 @@ def query_string def call_through_to_app status, headers, body = *call_app! + session['query_params'] = Rack::Request.new(env).params @response = Rack::Response.new(body, status, headers) status == 404 ? nil : @response.finish From 9ddad05aa14b784486e62eacc037263b90e36b59 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 24 May 2011 23:06:52 -0700 Subject: [PATCH 34/35] Don't test against Ruby 1.9.1 until Rack restores compatibility https://github.com/rack/rack/pull/173 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dbee03319..5ceb7062c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ script: "bundle exec rake test" rvm: - 1.8.7 - - 1.9.1 - 1.9.2 - jruby - rbx From 21e6ef8cfc9f59a749cdd5667f3cb2ec1ac51593 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Wed, 25 May 2011 08:45:23 -0700 Subject: [PATCH 35/35] Add Google Health to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9c2aa604a..23b32a0ed 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ OmniAuth currently supports the following external providers: * Foursquare (credit: [mbleigh](https://github.com/mbleigh)) * GitHub (credit: [mbleigh](https://github.com/mbleigh)) * GoodReads (credit: [cristoffer](https://github.com/christoffer)) + * Google Health (credit: [jaigouk](https://github.com/jaigouk)) * Gowalla (credit: [kvnsmth](https://github.com/kvnsmth)) * Hyves (credit: [mrdg](https://github.com/mrdg)) * Identi.ca (credit: [dcu](https://github.com/dcu))