authlogic_facebook 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/authlogic_facebook.gemspec +61 -0
- data/lib/authlogic_facebook.rb +9 -0
- data/lib/authlogic_facebook/acts_as_authentic.rb +20 -0
- data/lib/authlogic_facebook/helper.rb +4 -0
- data/lib/authlogic_facebook/session.rb +157 -0
- data/spec/authlogic_facebook_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +89 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Rusty Burchfield
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= authlogic_facebook
|
2
|
+
|
3
|
+
This is a Facebook plugin for authlogic. Facebooker is NOT required.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a future version
|
10
|
+
unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have
|
12
|
+
your own version, that is fine but bump version in a commit by itself I can
|
13
|
+
ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Rusty Burchfield. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "authlogic_facebook"
|
8
|
+
gem.summary = %Q{Authlogic plugin to support Facebook without Facebooker}
|
9
|
+
gem.description = %Q{Authlogic plugin to support Facebook without Facebooker}
|
10
|
+
gem.email = "GICodeWarrior@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/GICodeWarrior/authlogic_facebook"
|
12
|
+
gem.authors = ["Rusty Burchfield"]
|
13
|
+
gem.add_dependency "mini_fb", ">= 0.1.0"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "authlogic_facebook #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{authlogic_facebook}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Rusty Burchfield"]
|
12
|
+
s.date = %q{2009-12-03}
|
13
|
+
s.description = %q{Authlogic plugin to support Facebook without Facebooker}
|
14
|
+
s.email = %q{GICodeWarrior@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"authlogic_facebook.gemspec",
|
27
|
+
"lib/authlogic_facebook.rb",
|
28
|
+
"lib/authlogic_facebook/acts_as_authentic.rb",
|
29
|
+
"lib/authlogic_facebook/helper.rb",
|
30
|
+
"lib/authlogic_facebook/session.rb",
|
31
|
+
"spec/authlogic_facebook_spec.rb",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/GICodeWarrior/authlogic_facebook}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Authlogic plugin to support Facebook without Facebooker}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/authlogic_facebook_spec.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<mini_fb>, [">= 0.1.0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<mini_fb>, [">= 0.1.0"])
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<mini_fb>, [">= 0.1.0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'authlogic_facebook/acts_as_authentic'
|
2
|
+
require 'authlogic_facebook/session'
|
3
|
+
require 'authlogic_facebook/helper'
|
4
|
+
|
5
|
+
if ActiveRecord::Base.respond_to?(:add_acts_as_authentic_module)
|
6
|
+
ActiveRecord::Base.send(:include, AuthlogicFacebook::ActsAsAuthentic)
|
7
|
+
Authlogic::Session::Base.send(:include, AuthlogicFacebook::Session)
|
8
|
+
ActionController::Base.helper AuthlogicFacebook::Helper
|
9
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AuthlogicFacebook
|
2
|
+
module ActsAsAuthentic
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
extend Config
|
6
|
+
add_acts_as_authentic_module(Methods, :prepend)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Config
|
11
|
+
end
|
12
|
+
|
13
|
+
module Methods
|
14
|
+
def self.included(klass)
|
15
|
+
klass.class_eval do
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module AuthlogicFacebook
|
2
|
+
module Session
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
extend Config
|
6
|
+
include Methods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Config
|
11
|
+
# REQUIRED
|
12
|
+
#
|
13
|
+
# Specify your api_key.
|
14
|
+
#
|
15
|
+
# * <tt>Default:</tt> nil
|
16
|
+
# * <tt>Accepts:</tt> String
|
17
|
+
def facebook_api_key(value=nil)
|
18
|
+
rw_config(:facebook_api_key, value, nil)
|
19
|
+
end
|
20
|
+
alias_method :facebook_api_key=, :facebook_api_key
|
21
|
+
|
22
|
+
# REQUIRED
|
23
|
+
#
|
24
|
+
# Specify your secret_key.
|
25
|
+
#
|
26
|
+
# * <tt>Default:</tt> nil
|
27
|
+
# * <tt>Accepts:</tt> String
|
28
|
+
def facebook_secret_key(value=nil)
|
29
|
+
rw_config(:facebook_secret_key, value, nil)
|
30
|
+
end
|
31
|
+
alias_method :facebook_secret_key=, :facebook_secret_key
|
32
|
+
|
33
|
+
# What user field should be used for the facebook UID?
|
34
|
+
#
|
35
|
+
# * <tt>Default:</tt> :facebook_uid
|
36
|
+
# * <tt>Accepts:</tt> Symbol
|
37
|
+
def facebook_uid_field(value=nil)
|
38
|
+
rw_config(:facebook_uid_field, value, :facebook_uid)
|
39
|
+
end
|
40
|
+
alias_method :facebook_uid_field=, :facebook_uid_field
|
41
|
+
|
42
|
+
# What extended permissions should be requested from the user?
|
43
|
+
#
|
44
|
+
# * <tt>Default:</tt> []
|
45
|
+
# * <tt>Accepts:</tt> Array of Strings
|
46
|
+
def facebook_permissions(value=nil)
|
47
|
+
rw_config(:facebook_permissions, value, [])
|
48
|
+
end
|
49
|
+
alias_method :facebook_permissions=, :facebook_permissions
|
50
|
+
|
51
|
+
# Should a new user be automatically created if there is no user with
|
52
|
+
# given facebook uid?
|
53
|
+
#
|
54
|
+
# * <tt>Default:</tt> false
|
55
|
+
# * <tt>Accepts:</tt> Boolean
|
56
|
+
def facebook_auto_register(value=true)
|
57
|
+
rw_config(:facebook_auto_register, value, false)
|
58
|
+
end
|
59
|
+
alias_method :facebook_auto_register=, :facebook_auto_register
|
60
|
+
end
|
61
|
+
|
62
|
+
module Methods
|
63
|
+
def self.included(klass)
|
64
|
+
klass.class_eval do
|
65
|
+
validate :validate_by_facebook, :if => :authenticating_with_facebook?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Clears out the block if we are authenticating with Facebook so that we
|
70
|
+
# can redirect without a DoubleRender error.
|
71
|
+
def save(&block)
|
72
|
+
block = nil if !facebook_callback?
|
73
|
+
super(&block)
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
# Override this if you want only some requests to use facebook
|
78
|
+
def authenticating_with_facebook?
|
79
|
+
!self.class.facebook_api_key.blank? &&
|
80
|
+
!self.class.facebook_secret_key.blank?
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def validate_by_facebook
|
85
|
+
if facebook_callback?
|
86
|
+
facebook_uid = facebook_session['uid']
|
87
|
+
self.attempted_record = klass.first(:conditions => {facebook_uid_field => facebook_uid})
|
88
|
+
|
89
|
+
if self.attempted_record || !facebook_auto_register?
|
90
|
+
return !!self.attempted_record
|
91
|
+
else
|
92
|
+
self.attempted_record = klass.new
|
93
|
+
self.attempted_record.send(:"#{facebook_uid_field}=", facebook_uid)
|
94
|
+
if self.attempted_record.respond_to?(:before_connect)
|
95
|
+
self.attempted_record.send(:before_connect, facebook_session)
|
96
|
+
end
|
97
|
+
|
98
|
+
return self.attempted_record.save(false)
|
99
|
+
end
|
100
|
+
else
|
101
|
+
controller.redirect_to(facebook_login_url)
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def facebook_session
|
107
|
+
return @facebook_session if defined?(@facebook_session)
|
108
|
+
session_key = unverified_facebook_params['session_key']
|
109
|
+
params = {'session_key' => session_key, 'format' => 'JSON'}
|
110
|
+
uid = MiniFB.call(self.class.facebook_api_key,
|
111
|
+
self.class.facebook_secret_key,
|
112
|
+
'Users.getLoggedInUser', params)
|
113
|
+
|
114
|
+
@facebook_session = {'uid' => uid, 'session_key' => session_key}
|
115
|
+
end
|
116
|
+
|
117
|
+
def unverified_facebook_params
|
118
|
+
if defined?(@unverified_facebook_params)
|
119
|
+
return @unverified_facebook_params
|
120
|
+
end
|
121
|
+
|
122
|
+
begin
|
123
|
+
params = JSON.parse(controller.params['session'] || '')
|
124
|
+
rescue JSON::JSONError
|
125
|
+
params = {}
|
126
|
+
end
|
127
|
+
|
128
|
+
@unverified_facebook_params = params.is_a?(Hash) ? params : {}
|
129
|
+
end
|
130
|
+
|
131
|
+
def facebook_auto_register?
|
132
|
+
self.class.facebook_auto_register
|
133
|
+
end
|
134
|
+
|
135
|
+
def facebook_callback?
|
136
|
+
!unverified_facebook_params['uid'].blank?
|
137
|
+
end
|
138
|
+
|
139
|
+
def facebook_uid_field
|
140
|
+
self.class.facebook_uid_field
|
141
|
+
end
|
142
|
+
|
143
|
+
def facebook_login_url
|
144
|
+
params = {'api_key' => self.class.facebook_api_key,
|
145
|
+
'req_perms' => self.class.facebook_permissions.join(','),
|
146
|
+
'next' => controller.request.url,
|
147
|
+
'v' => '1.0',
|
148
|
+
'connect_display' => 'popup',
|
149
|
+
'fbconnect' => 'true',
|
150
|
+
'return_session' => 'true'}
|
151
|
+
|
152
|
+
url = 'http://www.facebook.com/login.php?'
|
153
|
+
url << params.map{|k,v| "#{k}=#{CGI.escape(v)}"}.join('&')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authlogic_facebook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rusty Burchfield
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-03 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mini_fb
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.9
|
34
|
+
version:
|
35
|
+
description: Authlogic plugin to support Facebook without Facebooker
|
36
|
+
email: GICodeWarrior@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- authlogic_facebook.gemspec
|
52
|
+
- lib/authlogic_facebook.rb
|
53
|
+
- lib/authlogic_facebook/acts_as_authentic.rb
|
54
|
+
- lib/authlogic_facebook/helper.rb
|
55
|
+
- lib/authlogic_facebook/session.rb
|
56
|
+
- spec/authlogic_facebook_spec.rb
|
57
|
+
- spec/spec.opts
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/GICodeWarrior/authlogic_facebook
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Authlogic plugin to support Facebook without Facebooker
|
87
|
+
test_files:
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/authlogic_facebook_spec.rb
|