diff --git a/.gitignore b/.gitignore index c795954..7e0d7ad 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ rdoc pkg ## PROJECT::SPECIFIC +*.gem \ No newline at end of file diff --git a/Rakefile b/Rakefile index 1e58d72..e86c8e8 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require 'term/ansicolor' include Term::ANSIColor -OMNIAUTH_GEMS = %w(oa-core oa-basic oa-oauth oa-openid) +OMNIAUTH_GEMS = %w(oa-core oa-basic oa-oauth oa-openid oa-facebook) desc 'Run specs for all of the gems.' task :spec do @@ -15,4 +15,6 @@ task :spec do end end end + +task :default => :spec \ No newline at end of file diff --git a/oa-basic/CHANGELOG.rdoc b/oa-basic/CHANGELOG.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-basic/LICENSE.rdoc b/oa-basic/LICENSE.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-basic/README.rdoc b/oa-basic/README.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-basic/oa-basic.gemspec b/oa-basic/oa-basic.gemspec index 1a2e634..dd00a92 100644 --- a/oa-basic/oa-basic.gemspec +++ b/oa-basic/oa-basic.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |gem| gem.summary = %Q{HTTP Basic strategies for OmniAuth.} gem.description = %Q{HTTP Basic strategies for OmniAuth.} gem.email = "michael@intridea.com" - gem.homepage = "http://github.com/intridea/omni_auth" + gem.homepage = "http://github.com/intridea/omniauth" gem.authors = ["Michael Bleigh"] gem.files = Dir.glob("{lib}/**/*") + %w(README.rdoc LICENSE.rdoc CHANGELOG.rdoc) diff --git a/oa-core/CHANGELOG.rdoc b/oa-core/CHANGELOG.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-core/LICENSE.rdoc b/oa-core/LICENSE.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-core/README.rdoc b/oa-core/README.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-core/lib/omniauth/strategy.rb b/oa-core/lib/omniauth/strategy.rb index d10a40c..8c1b031 100644 --- a/oa-core/lib/omniauth/strategy.rb +++ b/oa-core/lib/omniauth/strategy.rb @@ -12,17 +12,21 @@ module OmniAuth end def call(env) - dup._call(env) + dup.call!(env) end - def _call(env) + def call!(env) @env = env if request.path == "#{OmniAuth.config.path_prefix}/#{name}" request_phase elsif request.path == "#{OmniAuth.config.path_prefix}/#{name}/callback" callback_phase else - @app.call(env) + if respond_to?(:other_phase) + other_phase + else + @app.call(env) + end end end @@ -31,7 +35,8 @@ module OmniAuth end def callback_phase - raise NotImplementedError + request['auth'] = auth_hash + @app.call(env) end def auth_hash diff --git a/oa-core/oa-core.gemspec b/oa-core/oa-core.gemspec index fdfe91a..9f34b3f 100644 --- a/oa-core/oa-core.gemspec +++ b/oa-core/oa-core.gemspec @@ -1,10 +1,10 @@ Gem::Specification.new do |gem| - gem.name = "oa-basic" + gem.name = "oa-core" gem.version = File.open(File.dirname(__FILE__) + '/VERSION', 'r').read.strip gem.summary = %Q{HTTP Basic strategies for OmniAuth.} gem.description = %Q{HTTP Basic strategies for OmniAuth.} gem.email = "michael@intridea.com" - gem.homepage = "http://github.com/intridea/omni_auth" + gem.homepage = "http://github.com/intridea/omniauth" gem.authors = ["Michael Bleigh"] gem.files = Dir.glob("{lib}/**/*") + %w(README.rdoc LICENSE.rdoc CHANGELOG.rdoc) diff --git a/oa-facebook/CHANGELOG.rdoc b/oa-facebook/CHANGELOG.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-facebook/LICENSE.rdoc b/oa-facebook/LICENSE.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-facebook/README.rdoc b/oa-facebook/README.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-facebook/Rakefile b/oa-facebook/Rakefile new file mode 100644 index 0000000..8e74b34 --- /dev/null +++ b/oa-facebook/Rakefile @@ -0,0 +1,13 @@ +require 'rubygems' +require 'rake' + +require 'mg' +MG.new('oa-facebook.gemspec') + +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << '../oa-core/lib' << 'lib' << 'spec' + spec.spec_files = FileList['spec/**/*_spec.rb'] +end + +task :default => :spec \ No newline at end of file diff --git a/oa-facebook/VERSION b/oa-facebook/VERSION new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/oa-facebook/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/oa-facebook/lib/omniauth/facebook.rb b/oa-facebook/lib/omniauth/facebook.rb new file mode 100644 index 0000000..00327bb --- /dev/null +++ b/oa-facebook/lib/omniauth/facebook.rb @@ -0,0 +1,3 @@ +require 'omniauth/core' +require 'omniauth/strategies/facebook' +require 'mini_fb' \ No newline at end of file diff --git a/oa-facebook/lib/omniauth/strategies/facebook.rb b/oa-facebook/lib/omniauth/strategies/facebook.rb new file mode 100644 index 0000000..1f1f72f --- /dev/null +++ b/oa-facebook/lib/omniauth/strategies/facebook.rb @@ -0,0 +1,128 @@ +module OmniAuth + module Strategies + # An Authentication strategy that utilizes Facebook Connect. + class Facebook + include OmniAuth::Strategy + EXTENDED_PERMISSIONS = %w(publish_stream read_stream email read_mailbox offline_access create_event rsvp_event sms status_update video_upload create_note share_item) + + # Initialize the middleware. Requires a Facebook API key and secret + # and takes the following options: + # + # :permissions :: An array of Facebook extended permissions, defaults to %w(email offline_access). Use :all to include all extended permissions. + # :scripts :: A boolean value for whether or not to automatically inject the Facebook Javascripts and XD Receiver into your application. Defaults to true. + # + def initialize(app, api_key, api_secret, options = {}) + super app, :facebook + + options[:permissions] = EXTENDED_PERMISSIONS if options[:permissions] == :all + @options = { + :permissions => %w(email offline_access), + :scripts => true + }.merge(options) + + @api_key = api_key + @api_secret = api_secret + + self.extend PageInjections if @options[:scripts] + end + + def auth_hash + OmniAuth.deep_merge(super, { + 'provider' => 'facebook', + 'uid' => request.cookies["#{@api_key}_user"], + 'credentials' => { + 'key' => request.cookies["#{@api_key}_session_key"], + 'secret' => request.cookies["#{@api_key}_ss"], + 'expires' => (Time.at(request.cookies["#{@api_key}_expires"].to_i) if request.cookies["#{@api_key}_expires"].to_i > 0) + }, + 'user_info' => user_info(session_key, user_id) + }) + end + + def user_info + hash = MiniFB.call(@api_key, @api_secret, "Users.getInfo", 'uids' => request[:auth][:user_id], 'fields' => [:name, :first_name, :last_name, :username, :pic_square, :current_location])[0] + { + 'name' => user[:name], + 'first_name' => user[:first_name], + 'last_name' => user[:last_name], + 'nickname' => user[:username], + 'image' => user[:pic_square], + 'location' => user[:locale] + } + end + + def call(env) + dup = self.dup + dup.extend PageInjections if @options[:scripts] + dup.call!(env) + end + + module PageInjections + def call!(env) + super + @base_url = (request.scheme.downcase == 'https' ? 'https://ssl.connect.facebook.com' : 'http://static.ak.connect.facebook.com') + case request.path + when "/#{OmniAuth.config.path_prefix}/facebook/xd_receiver.html" + xd_receiver + else + inject_facebook + end + end + + def xd_receiver #:nodoc: + xd = <<-HTML + + +
+