fboauth2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/Fboauth2.gemspec +81 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +123 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +87 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/app/controller/facebookoauth_controller.rb +42 -0
- data/config/fbconfig_test.yml +17 -0
- data/config/routes.rb +5 -0
- data/lib/Fboauth2.rb +120 -0
- data/pkg/Fboauth2-0.1.0.gem +0 -0
- data/spec/fboauth2_spec.rb +25 -0
- data/test/helper.rb +20 -0
- data/test/test_Fboauth2.rb +24 -0
- metadata +204 -0
data/.rspec
ADDED
data/Fboauth2.gemspec
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fboauth2}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Hugo Rincon"]
|
12
|
+
s.date = %q{2011-07-06}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{hugo@bakedweb.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rspec",
|
21
|
+
"Fboauth2.gemspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"app/controller/facebookoauth_controller.rb",
|
29
|
+
"config/fbconfig_test.yml",
|
30
|
+
"config/routes.rb",
|
31
|
+
"lib/Fboauth2.rb",
|
32
|
+
"pkg/Fboauth2-0.1.0.gem",
|
33
|
+
"spec/fboauth2_spec.rb",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_Fboauth2.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/hugoerg56/Fboauth2}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.7.2}
|
41
|
+
s.summary = %q{simple facebook auth}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/fboauth2_spec.rb",
|
44
|
+
"test/helper.rb",
|
45
|
+
"test/test_Fboauth2.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<fbgraph>, ["~> 1.6.0"])
|
53
|
+
s.add_development_dependency(%q<rspec>, ["= 2.5.0"])
|
54
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
57
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rails>, ["= 3.0.0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<fbgraph>, ["~> 1.6.0"])
|
62
|
+
s.add_dependency(%q<rspec>, ["= 2.5.0"])
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rails>, ["= 3.0.0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<fbgraph>, ["~> 1.6.0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["= 2.5.0"])
|
73
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
76
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
77
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rails>, ["= 3.0.0"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'fbgraph', "~> 1.6.0"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "rspec", "2.5.0"
|
7
|
+
gem "shoulda", ">= 0"
|
8
|
+
gem "bundler", "~> 1.0.0"
|
9
|
+
gem "jeweler", "~> 1.5.2"
|
10
|
+
gem "rcov", ">= 0"
|
11
|
+
gem "autotest"
|
12
|
+
gem "rails", "3.0.0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.5.0)
|
5
|
+
abstract (1.0.0)
|
6
|
+
actionmailer (3.0.0)
|
7
|
+
actionpack (= 3.0.0)
|
8
|
+
mail (~> 2.2.5)
|
9
|
+
actionpack (3.0.0)
|
10
|
+
activemodel (= 3.0.0)
|
11
|
+
activesupport (= 3.0.0)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
erubis (~> 2.6.6)
|
14
|
+
i18n (~> 0.4.1)
|
15
|
+
rack (~> 1.2.1)
|
16
|
+
rack-mount (~> 0.6.12)
|
17
|
+
rack-test (~> 0.5.4)
|
18
|
+
tzinfo (~> 0.3.23)
|
19
|
+
activemodel (3.0.0)
|
20
|
+
activesupport (= 3.0.0)
|
21
|
+
builder (~> 2.1.2)
|
22
|
+
i18n (~> 0.4.1)
|
23
|
+
activerecord (3.0.0)
|
24
|
+
activemodel (= 3.0.0)
|
25
|
+
activesupport (= 3.0.0)
|
26
|
+
arel (~> 1.0.0)
|
27
|
+
tzinfo (~> 0.3.23)
|
28
|
+
activeresource (3.0.0)
|
29
|
+
activemodel (= 3.0.0)
|
30
|
+
activesupport (= 3.0.0)
|
31
|
+
activesupport (3.0.0)
|
32
|
+
addressable (2.2.6)
|
33
|
+
arel (1.0.1)
|
34
|
+
activesupport (~> 3.0.0)
|
35
|
+
autotest (4.4.6)
|
36
|
+
ZenTest (>= 4.4.1)
|
37
|
+
builder (2.1.2)
|
38
|
+
diff-lcs (1.1.2)
|
39
|
+
erubis (2.6.6)
|
40
|
+
abstract (>= 1.0.0)
|
41
|
+
faraday (0.6.1)
|
42
|
+
addressable (~> 2.2.4)
|
43
|
+
multipart-post (~> 1.1.0)
|
44
|
+
rack (< 2, >= 1.1.0)
|
45
|
+
fbgraph (1.6.0)
|
46
|
+
activesupport
|
47
|
+
activesupport
|
48
|
+
hashie
|
49
|
+
hashie
|
50
|
+
json
|
51
|
+
json
|
52
|
+
oauth2
|
53
|
+
oauth2
|
54
|
+
rest-client
|
55
|
+
rest-client
|
56
|
+
git (1.2.5)
|
57
|
+
hashie (1.0.0)
|
58
|
+
i18n (0.4.2)
|
59
|
+
jeweler (1.5.2)
|
60
|
+
bundler (~> 1.0.0)
|
61
|
+
git (>= 1.2.5)
|
62
|
+
rake
|
63
|
+
json (1.5.3)
|
64
|
+
mail (2.2.19)
|
65
|
+
activesupport (>= 2.3.6)
|
66
|
+
i18n (>= 0.4.0)
|
67
|
+
mime-types (~> 1.16)
|
68
|
+
treetop (~> 1.4.8)
|
69
|
+
mime-types (1.16)
|
70
|
+
multi_json (1.0.3)
|
71
|
+
multipart-post (1.1.2)
|
72
|
+
oauth2 (0.4.1)
|
73
|
+
faraday (~> 0.6.1)
|
74
|
+
multi_json (>= 0.0.5)
|
75
|
+
polyglot (0.3.1)
|
76
|
+
rack (1.2.3)
|
77
|
+
rack-mount (0.6.14)
|
78
|
+
rack (>= 1.0.0)
|
79
|
+
rack-test (0.5.7)
|
80
|
+
rack (>= 1.0)
|
81
|
+
rails (3.0.0)
|
82
|
+
actionmailer (= 3.0.0)
|
83
|
+
actionpack (= 3.0.0)
|
84
|
+
activerecord (= 3.0.0)
|
85
|
+
activeresource (= 3.0.0)
|
86
|
+
activesupport (= 3.0.0)
|
87
|
+
bundler (~> 1.0.0)
|
88
|
+
railties (= 3.0.0)
|
89
|
+
railties (3.0.0)
|
90
|
+
actionpack (= 3.0.0)
|
91
|
+
activesupport (= 3.0.0)
|
92
|
+
rake (>= 0.8.4)
|
93
|
+
thor (~> 0.14.0)
|
94
|
+
rake (0.9.2)
|
95
|
+
rcov (0.9.9)
|
96
|
+
rest-client (1.6.3)
|
97
|
+
mime-types (>= 1.16)
|
98
|
+
rspec (2.5.0)
|
99
|
+
rspec-core (~> 2.5.0)
|
100
|
+
rspec-expectations (~> 2.5.0)
|
101
|
+
rspec-mocks (~> 2.5.0)
|
102
|
+
rspec-core (2.5.2)
|
103
|
+
rspec-expectations (2.5.0)
|
104
|
+
diff-lcs (~> 1.1.2)
|
105
|
+
rspec-mocks (2.5.0)
|
106
|
+
shoulda (2.11.3)
|
107
|
+
thor (0.14.6)
|
108
|
+
treetop (1.4.9)
|
109
|
+
polyglot (>= 0.3.1)
|
110
|
+
tzinfo (0.3.29)
|
111
|
+
|
112
|
+
PLATFORMS
|
113
|
+
ruby
|
114
|
+
|
115
|
+
DEPENDENCIES
|
116
|
+
autotest
|
117
|
+
bundler (~> 1.0.0)
|
118
|
+
fbgraph (~> 1.6.0)
|
119
|
+
jeweler (~> 1.5.2)
|
120
|
+
rails (= 3.0.0)
|
121
|
+
rcov
|
122
|
+
rspec (= 2.5.0)
|
123
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Hugo Rincon
|
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,87 @@
|
|
1
|
+
= Fboauth2
|
2
|
+
|
3
|
+
=== Requirements
|
4
|
+
|
5
|
+
* fbgraph 1.6.0
|
6
|
+
|
7
|
+
|
8
|
+
=== Installation
|
9
|
+
|
10
|
+
1) Just place a link like this on your site:
|
11
|
+
/oauth2_facebook/fb_auth?config=example_config_name¶m1=any data
|
12
|
+
|
13
|
+
* config_name: You can see this in the yml file example.
|
14
|
+
* param1(optional): You can pass any number of parameters through this url
|
15
|
+
|
16
|
+
2) create a yml file on your config folder named "fbconfig.yml" /config/fbconfig.yml
|
17
|
+
|
18
|
+
=== Exaple fbconfig.yml:
|
19
|
+
|
20
|
+
credentials:
|
21
|
+
production:
|
22
|
+
api_key: your_api_key
|
23
|
+
api_secret: your_api_secret
|
24
|
+
permission: offline_access,email #you can see a full list a permissions on http://developers.facebook.com/docs/reference/api/permissions/
|
25
|
+
|
26
|
+
development:
|
27
|
+
api_key: your_api_key
|
28
|
+
api_secret: your_api_secret
|
29
|
+
permission: offline_access,email #you can see a full list a permissions on http://developers.facebook.com/docs/reference/api/permissions/
|
30
|
+
|
31
|
+
test:
|
32
|
+
api_key: your_api_key
|
33
|
+
api_secret: your_api_secret
|
34
|
+
permission: offline_access,email #you can see a full list a permissions on http://developers.facebook.com/docs/reference/api/permissions/
|
35
|
+
|
36
|
+
|
37
|
+
example_config_name:
|
38
|
+
redirect: /redirect_url
|
39
|
+
hmodel: t #(t or f) t= create a 'model'
|
40
|
+
model:
|
41
|
+
name: ModelName
|
42
|
+
params:
|
43
|
+
email: fboauh2@emailexample.com
|
44
|
+
phone: 123456
|
45
|
+
hsubmodel: t #(t or f) t= create a 'submodel' into 'model'
|
46
|
+
submodel:
|
47
|
+
name: SubCateg
|
48
|
+
params:
|
49
|
+
subcateg:
|
50
|
+
0:
|
51
|
+
firstname: examplename
|
52
|
+
lastname: examplelastname
|
53
|
+
hfbmsg: t #(t or f) t= create a message on facebook user wall
|
54
|
+
facebook: #optional, only if hfbmsg is "t"
|
55
|
+
message: Message Title #optional, only if hfbmsg is "t"
|
56
|
+
title: ¡message subtitle! #optional, only if hfbmsg is "t"
|
57
|
+
link: http://www.link_on_the_message.com #optional, only if hfbmsg is "t"
|
58
|
+
picture: http://www.link_on_the_message.com/icon.png #optional, only if hfbmsg is "t"
|
59
|
+
description: Message description... #optional, only if hfbmsg is "t"
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
=== Params on redirect url
|
64
|
+
|
65
|
+
you can do:
|
66
|
+
* redirect: /redirect_url/ pm_name_of_param
|
67
|
+
* redirect: /redirect_url?param= pm_name_of_param
|
68
|
+
* redirect: /redirect_url/ pm_name_of_param /delete
|
69
|
+
|
70
|
+
|
71
|
+
== Contributing
|
72
|
+
|
73
|
+
If you'd like to contribute a feature or bugfix: Thanks! To make sure your fix/feature has a high chance of being included, please read the following guidelines:
|
74
|
+
|
75
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
76
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
77
|
+
* Fork the project
|
78
|
+
* Start a feature/bugfix branch
|
79
|
+
* Commit and push until you are happy with your contribution
|
80
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
81
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
82
|
+
|
83
|
+
== Copyright
|
84
|
+
|
85
|
+
Copyright (c) 2011 Hugo Rincon. See LICENSE.txt for
|
86
|
+
further details.
|
87
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "fboauth2"
|
16
|
+
gem.homepage = "http://github.com/hugoerg56/Fboauth2"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{simple facebook auth}
|
19
|
+
gem.description = %Q{}
|
20
|
+
gem.email = "hugo@bakedweb.net"
|
21
|
+
gem.authors = ["Hugo Rincon"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "Fboauth2 #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fboauth2'
|
2
|
+
|
3
|
+
class FacebookoauthController < ApplicationController
|
4
|
+
|
5
|
+
def auth
|
6
|
+
url = Fboauth2::Newfbclient.get_auth(request.env["HTTP_HOST"], params) #piden la creacion de un nuevo fb client y regresa la url para hacer el redirect a fb, se envia el url del host como parametro
|
7
|
+
redirect_to url #redirect a facebook para hacer el auth
|
8
|
+
end
|
9
|
+
|
10
|
+
def callback
|
11
|
+
#callback functions
|
12
|
+
|
13
|
+
conf_data = Fboauth2::Newfbclient.get_conf_data
|
14
|
+
|
15
|
+
if !conf_data[params[:config]].nil? && conf_data[params[:config]] != "" && !params[:code].nil? && params[:code] != ""
|
16
|
+
|
17
|
+
#toma los datos del usuario de facebook y los coloca en fb_user despues del auth
|
18
|
+
client = Fboauth2::Newfbclient.auth_callback(params[:code], Fboauth2::Newfbclient.get_url(request.env["HTTP_HOST"]))
|
19
|
+
fb_user = client.selection.me.info!
|
20
|
+
|
21
|
+
#crea un nuevo registro en la db
|
22
|
+
if conf_data[params[:config]]["hmodel"] == "t"
|
23
|
+
Fboauth2::Newfbclient.crate_new_m(conf_data, params, fb_user)
|
24
|
+
end
|
25
|
+
|
26
|
+
#Publica mensaje en facebook
|
27
|
+
if conf_data[params[:config]]["hfbmsg"] == "t"
|
28
|
+
Fboauth2::Newfbclient.send_fb_msg(params[:config], fb_user)
|
29
|
+
end
|
30
|
+
|
31
|
+
redirect_to Fboauth2::Newfbclient.get_redirect_path(params)
|
32
|
+
|
33
|
+
else
|
34
|
+
|
35
|
+
puts "**** Fboauth2 ERROR: config parameter is required or fbuser not allow permission to app****"
|
36
|
+
redirect_to "/"
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
credentials:
|
2
|
+
development:
|
3
|
+
api_key: 146e8668ff2b1551a79a7c7e84c10cb7
|
4
|
+
api_secret: 543fc3de422a169dc861b33ccbc5fbb0
|
5
|
+
permission: offline_access,email,user_birthday,publish_stream,user_status,user_website,user_about_me,user_interests
|
6
|
+
|
7
|
+
test:
|
8
|
+
api_key: c942b8909bcc1adda6a77ab7bed75014
|
9
|
+
api_secret: 81f2d437553d1455535b37012867c035
|
10
|
+
permission: offline_access,email,user_birthday,publish_stream,user_status,user_website,user_about_me,user_interests
|
11
|
+
|
12
|
+
test:
|
13
|
+
redirect: /
|
14
|
+
hmodel: f
|
15
|
+
hsubmodel: f
|
16
|
+
hfbmsg: f
|
17
|
+
|
data/config/routes.rb
ADDED
data/lib/Fboauth2.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'fbgraph'
|
4
|
+
|
5
|
+
|
6
|
+
module Fboauth2
|
7
|
+
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
config.fboauth2 = Fboauth2
|
10
|
+
config.autoload_paths << File.expand_path(File.join(File.dirname(__FILE__), "..")) if config.respond_to? :autoload_paths
|
11
|
+
end
|
12
|
+
|
13
|
+
class Newfbclient
|
14
|
+
|
15
|
+
@facebook_client
|
16
|
+
@params
|
17
|
+
def self.get_auth(host, params)
|
18
|
+
@params = params
|
19
|
+
@fb_data = Newfbclient.get_conf_data
|
20
|
+
url = Newfbclient.get_url(host)
|
21
|
+
@facebook_client = Newfbclient.get_client #creo un nuevo cliente
|
22
|
+
@facebook_client.authorization.authorize_url(:redirect_uri => url , :scope => @fb_data["credentials"][Rails.env]["permission"]) #pido autorizacion q me regresa una url a facebook
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get_client
|
26
|
+
@fb_data = Newfbclient.get_conf_data
|
27
|
+
FBGraph::Client.new(:client_id => @fb_data["credentials"][Rails.env]["api_key"], :secret_id => @fb_data["credentials"][Rails.env]["api_secret"])
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.auth_callback(code, url)
|
31
|
+
client = @facebook_client
|
32
|
+
client.authorization.process_callback(code, :redirect_uri => url)
|
33
|
+
client
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_url(host)
|
37
|
+
@aux_params = ""
|
38
|
+
@params.delete("controller")
|
39
|
+
@params.delete("action")
|
40
|
+
@params.each do |key, value|
|
41
|
+
@aux_params = @aux_params + key + "=" + value + "&"
|
42
|
+
end
|
43
|
+
"http://"+ host + "/oauth2_facebook/fb_callback?" + @aux_params #get url para el callback
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_conf_data
|
47
|
+
if Rails.env == 'test'
|
48
|
+
YAML.load_file("#{File.dirname(__FILE__)}/../config/fbconfig_test.yml")
|
49
|
+
else
|
50
|
+
YAML.load_file("#{Rails.root}/config/fbconfig.yml")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.crate_new_m(info, params, user)
|
55
|
+
cname = params[:config]
|
56
|
+
model_type = info[cname]["model"]["name"]
|
57
|
+
m_data = info[cname]["model"]["params"]
|
58
|
+
|
59
|
+
puts "-"*50
|
60
|
+
puts "Creating #{model_type}..."
|
61
|
+
|
62
|
+
m_data.each do |field, value|
|
63
|
+
aux = value.to_s.split("_")
|
64
|
+
if aux[0] == "fb"
|
65
|
+
value = user["#{aux[1]}"]
|
66
|
+
m_data[field] = value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if info[cname]["hsubmodel"] == "t" #si tiene algun tipo de subcategoria?
|
71
|
+
sm_data = info[cname]["submodel"]["params"]
|
72
|
+
sm_name = info[cname]["submodel"]["name"]
|
73
|
+
sm_data["#{sm_name}"][0].each do |field, value|
|
74
|
+
|
75
|
+
aux = value.to_s.split("_")
|
76
|
+
if aux[0] == "fb"
|
77
|
+
sm_data["#{sm_name}"][0][field] = user["#{aux[1]}"]
|
78
|
+
end
|
79
|
+
if aux[0] == "pm"
|
80
|
+
sm_data["#{sm_name}"][0][field] = params[aux[1].to_sym]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
m_data = m_data.merge(sm_data)
|
84
|
+
end
|
85
|
+
|
86
|
+
m_aux = model_type.constantize.create(m_data)
|
87
|
+
|
88
|
+
puts "-> ID: " + m_aux.id.to_s
|
89
|
+
puts "-> Ready!"
|
90
|
+
|
91
|
+
puts "-"*50
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def self.send_fb_msg(cname, user)
|
96
|
+
@fb_data = Newfbclient.get_conf_data
|
97
|
+
@facebook_client.selection.user(user[:id]).feed.publish!(:message => @fb_data[cname]["facebook"]["message"], :name => @fb_data[cname]["facebook"]["title"], :link => @fb_data[cname]["facebook"]["link"], :picture => @fb_data[cname]["facebook"]["picture"], :description => @fb_data[cname]["facebook"]["description"])
|
98
|
+
puts "-> Facebook Message, successfully published..."
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.get_redirect_path(params)
|
102
|
+
@fb_data = Newfbclient.get_conf_data
|
103
|
+
url = @fb_data[params[:config]]['redirect'].split(" ")
|
104
|
+
url_f = ""
|
105
|
+
url.each do |value|
|
106
|
+
aux = value.split("_")
|
107
|
+
if aux[0] == "pm"
|
108
|
+
url_f += params[aux[1].to_sym]
|
109
|
+
else
|
110
|
+
url_f += value
|
111
|
+
end
|
112
|
+
end
|
113
|
+
puts url_f
|
114
|
+
return url_f
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'rails'
|
4
|
+
require 'Fboauth2'
|
5
|
+
|
6
|
+
describe "Fboauth2 tests" do
|
7
|
+
it "get url to graph.facebook.com" do
|
8
|
+
params = {"config"=>"test", "param1"=>"test"}
|
9
|
+
url = Fboauth2::Newfbclient.get_auth("127.0.0.1:3000", params)
|
10
|
+
reg = /(https):\/\/(graph.facebook.com)\/(oauth)\/(authorize)[a-z]*/
|
11
|
+
match_r = (reg.match(url))? true : false
|
12
|
+
match_r.should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "get a client" do
|
16
|
+
client = Fboauth2::Newfbclient.get_client
|
17
|
+
client.facebook_uri.should == "https://graph.facebook.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "get callback url" do
|
21
|
+
callback_url = Fboauth2::Newfbclient.get_url("localtest")
|
22
|
+
callback_url.should == "http://localtest/oauth2_facebook/fb_callback?config=test¶m1=test&"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'test/unit'
|
13
|
+
require 'shoulda'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'Fboauth2'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestFboauth2 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "get url to auth on facebook" do
|
6
|
+
params = {"config"=>"test", "param1"=>"test"}
|
7
|
+
url = Fboauth2::Newfbclient.get_auth("127.0.0.1:3000", params)
|
8
|
+
reg = /(https):\/\/(graph.facebook.com)\/(oauth)\/(authorize)[a-z]*/
|
9
|
+
match_r = (reg.match(url))? true : false
|
10
|
+
assert_equal match_r, true
|
11
|
+
end
|
12
|
+
|
13
|
+
should "get a client object from fbgraph gem" do
|
14
|
+
client = Fboauth2::Newfbclient.get_client
|
15
|
+
assert_equal client.facebook_uri, "https://graph.facebook.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
should "get a callback url" do
|
19
|
+
params = {"config"=>"test", "param1"=>"test"}
|
20
|
+
Fboauth2::Newfbclient.get_auth("127.0.0.1:3000", params)
|
21
|
+
callback_url = Fboauth2::Newfbclient.get_url("localtest")
|
22
|
+
assert_equal callback_url, "http://localtest/oauth2_facebook/fb_callback?config=test¶m1=test&"
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fboauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Hugo Rincon
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-06 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 15
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 6
|
30
|
+
- 0
|
31
|
+
version: 1.6.0
|
32
|
+
name: fbgraph
|
33
|
+
prerelease: false
|
34
|
+
type: :runtime
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - "="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 27
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 5
|
46
|
+
- 0
|
47
|
+
version: 2.5.0
|
48
|
+
name: rspec
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
name: shoulda
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
requirement: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 23
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
version: 1.0.0
|
78
|
+
name: bundler
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
requirement: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 7
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 5
|
92
|
+
- 2
|
93
|
+
version: 1.5.2
|
94
|
+
name: jeweler
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
requirement: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
name: rcov
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
requirement: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
name: autotest
|
123
|
+
prerelease: false
|
124
|
+
type: :development
|
125
|
+
requirement: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - "="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 7
|
133
|
+
segments:
|
134
|
+
- 3
|
135
|
+
- 0
|
136
|
+
- 0
|
137
|
+
version: 3.0.0
|
138
|
+
name: rails
|
139
|
+
prerelease: false
|
140
|
+
type: :development
|
141
|
+
requirement: *id008
|
142
|
+
description: ""
|
143
|
+
email: hugo@bakedweb.net
|
144
|
+
executables: []
|
145
|
+
|
146
|
+
extensions: []
|
147
|
+
|
148
|
+
extra_rdoc_files:
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.rdoc
|
151
|
+
files:
|
152
|
+
- .rspec
|
153
|
+
- Fboauth2.gemspec
|
154
|
+
- Gemfile
|
155
|
+
- Gemfile.lock
|
156
|
+
- LICENSE.txt
|
157
|
+
- README.rdoc
|
158
|
+
- Rakefile
|
159
|
+
- VERSION
|
160
|
+
- app/controller/facebookoauth_controller.rb
|
161
|
+
- config/fbconfig_test.yml
|
162
|
+
- config/routes.rb
|
163
|
+
- lib/Fboauth2.rb
|
164
|
+
- pkg/Fboauth2-0.1.0.gem
|
165
|
+
- spec/fboauth2_spec.rb
|
166
|
+
- test/helper.rb
|
167
|
+
- test/test_Fboauth2.rb
|
168
|
+
homepage: http://github.com/hugoerg56/Fboauth2
|
169
|
+
licenses:
|
170
|
+
- MIT
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
hash: 3
|
182
|
+
segments:
|
183
|
+
- 0
|
184
|
+
version: "0"
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
hash: 3
|
191
|
+
segments:
|
192
|
+
- 0
|
193
|
+
version: "0"
|
194
|
+
requirements: []
|
195
|
+
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 1.7.2
|
198
|
+
signing_key:
|
199
|
+
specification_version: 3
|
200
|
+
summary: simple facebook auth
|
201
|
+
test_files:
|
202
|
+
- spec/fboauth2_spec.rb
|
203
|
+
- test/helper.rb
|
204
|
+
- test/test_Fboauth2.rb
|