forked from omniauth/omniauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds lots of stuff. Facebook is broken, beware.
- Loading branch information
Michael Bleigh
committed
Apr 10, 2010
1 parent
349cfc3
commit f9dc9ea
Showing
31 changed files
with
250 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ rdoc | |
pkg | ||
|
||
## PROJECT::SPECIFIC | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = "[email protected]" | ||
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) | ||
|
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "[email protected]" | ||
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) | ||
|
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'omniauth/core' | ||
require 'omniauth/strategies/facebook' | ||
require 'mini_fb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
# | ||
# <tt>:permissions</tt> :: An array of Facebook extended permissions, defaults to <tt>%w(email offline_access)</tt>. Use <tt>:all</tt> to include all extended permissions. | ||
# <tt>:scripts</tt> :: A boolean value for whether or not to automatically inject the Facebook Javascripts and XD Receiver into your application. Defaults to <tt>true</tt>. | ||
# | ||
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 | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" > | ||
<head> | ||
<title>Cross-Domain Receiver Page</title> | ||
</head> | ||
<body> | ||
<script src="#{@base_url}/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script> | ||
</body> | ||
</html> | ||
HTML | ||
|
||
Rack::Response.new(xd).finish | ||
end | ||
|
||
def inject_facebook #:nodoc: | ||
status, headers, responses = @app.call(@env) | ||
responses = Array(responses) unless responses.respond_to?(:each) | ||
|
||
if headers["Content-Type"] =~ %r{(text/html)|(application/xhtml+xml)} | ||
resp = [] | ||
responses.each do |r| | ||
r.sub! /(<html[^\/>]*)>/i, '\1 xmlns:fb=\"http://www.facebook.com/2008/fbml\">' | ||
r.sub! /(<body[^\/>]*)>/i, '\1><script src="' + @base_url + '/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>' | ||
r.sub! /<\/body>/i, <<-HTML | ||
<script type="text/javascript"> | ||
FB.init("#{@api_key}", "/auth/facebook/xd_receiver.html"); | ||
OmniAuth = { | ||
Facebook: { | ||
loginSuccess:function() { | ||
FB.Connect.showPermissionDialog("#{Array(@options[:permissions]).join(',')}", function(perms) { | ||
if (perms) { | ||
window.location.href = '/#{OmniAuth.config.path_prefix}/facebook/callback'; | ||
} else { | ||
window.location.href = '/#{OmniAuth.config.path_prefix}/facebook/callback?permissions=denied'; | ||
} | ||
}); | ||
}, | ||
loginFailure:function() { | ||
window.location.href = '/#{OmniAuth.config.path_prefix}/failure?message=user_declined'; | ||
} | ||
} | ||
} | ||
</script></body> | ||
HTML | ||
resp << r | ||
end | ||
end | ||
|
||
Rack::Response.new(resp || responses, status, headers).finish | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version = File.open(File.dirname(__FILE__) + '/VERSION', 'r').read.strip | ||
|
||
Gem::Specification.new do |gem| | ||
gem.name = "oa-facebook" | ||
gem.version = File.open(File.dirname(__FILE__) + '/VERSION', 'r').read.strip | ||
gem.summary = %Q{Facebook strategies for OmniAuth.} | ||
gem.description = %Q{Facebook strategies for OmniAuth.} | ||
gem.email = "[email protected]" | ||
gem.homepage = "http://github.com/intridea/omniauth" | ||
gem.authors = ["Michael Bleigh"] | ||
|
||
gem.files = Dir.glob("{lib}/**/*") + %w(README.rdoc LICENSE.rdoc CHANGELOG.rdoc) | ||
|
||
gem.add_dependency 'oa-core', "~> #{version.gsub(/\d$/,'0')}" | ||
gem.add_dependency 'fb_mini' | ||
|
||
gem.add_development_dependency "rspec", ">= 1.2.9" | ||
gem.add_development_dependency "webmock" | ||
gem.add_development_dependency "rack-test" | ||
gem.add_development_dependency "mg" | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem| | |
gem.summary = %Q{OAuth strategies for OmniAuth.} | ||
gem.description = %Q{OAuth strategies for OmniAuth.} | ||
gem.email = "[email protected]" | ||
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) | ||
|
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module OmniAuth | ||
module Strategies | ||
class Google < OmniAuth::Stratgies::OpenID | ||
def identifier; 'https://www.google.com/accounts/o8/id' end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem| | |
gem.summary = %Q{OpenID strategies for OmniAuth.} | ||
gem.description = %Q{OpenID strategies for OmniAuth.} | ||
gem.email = "[email protected]" | ||
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) | ||
|
Empty file.
Empty file.
Oops, something went wrong.