authlogic_facebook_koala 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.md +4 -0
  2. data/authlogic_facebook_koala.gemspec +25 -22
  3. metadata +31 -165
  4. data/LICENSE +0 -20
  5. data/README.rdoc +0 -76
  6. data/Rakefile +0 -39
  7. data/VERSION +0 -1
  8. data/init.rb +0 -1
  9. data/lib/authlogic_facebook_koala.rb +0 -17
  10. data/lib/authlogic_facebook_koala/acts_as_authentic.rb +0 -20
  11. data/lib/authlogic_facebook_koala/adapter.rb +0 -35
  12. data/lib/authlogic_facebook_koala/config.rb +0 -80
  13. data/lib/authlogic_facebook_koala/helper.rb +0 -4
  14. data/lib/authlogic_facebook_koala/session.rb +0 -68
  15. data/rails/init.rb +0 -1
  16. data/test/rails_root/app/controllers/application_controller.rb +0 -10
  17. data/test/rails_root/app/helpers/application_helper.rb +0 -3
  18. data/test/rails_root/app/models/user.rb +0 -7
  19. data/test/rails_root/app/models/user_session.rb +0 -7
  20. data/test/rails_root/config/boot.rb +0 -110
  21. data/test/rails_root/config/database.yml +0 -10
  22. data/test/rails_root/config/environment.rb +0 -31
  23. data/test/rails_root/config/environments/development.rb +0 -0
  24. data/test/rails_root/config/environments/test.rb +0 -0
  25. data/test/rails_root/config/facebook.yml +0 -7
  26. data/test/rails_root/config/initializers/authlogic_facebook_koala.rb +0 -5
  27. data/test/rails_root/config/initializers/new_rails_defaults.rb +0 -21
  28. data/test/rails_root/config/initializers/session_store.rb +0 -15
  29. data/test/rails_root/config/locales/en.yml +0 -5
  30. data/test/rails_root/config/routes.rb +0 -43
  31. data/test/rails_root/db/migrate/20101217000008_create_users.rb +0 -37
  32. data/test/rails_root/db/seeds.rb +0 -7
  33. data/test/rails_root/script/console +0 -3
  34. data/test/rails_root/script/dbconsole +0 -3
  35. data/test/rails_root/script/generate +0 -3
  36. data/test/test_helper.rb +0 -43
  37. data/test/units/adapter_test.rb +0 -182
  38. data/test/units/config_test.rb +0 -145
  39. data/test/units/session_test.rb +0 -221
@@ -1,21 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # These settings change the behavior of Rails 2 apps and will be defaults
4
- # for Rails 3. You can remove this initializer when Rails 3 is released.
5
-
6
- if defined?(ActiveRecord)
7
- # Include Active Record class name as root for JSON serialized output.
8
- ActiveRecord::Base.include_root_in_json = true
9
-
10
- # Store the full class name (including module namespace) in STI type column.
11
- ActiveRecord::Base.store_full_sti_class = true
12
- end
13
-
14
- ActionController::Routing.generate_best_match = false
15
-
16
- # Use ISO 8601 format for JSON serialized times and dates.
17
- ActiveSupport.use_standard_json_time_format = true
18
-
19
- # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
- # if you're including raw json in an HTML page.
21
- ActiveSupport.escape_html_entities_in_json = false
@@ -1,15 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying cookie session data integrity.
4
- # If you change this key, all old sessions will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- ActionController::Base.session = {
8
- :key => '_rails_root_session',
9
- :secret => '4deb5b6e05377d982fa6ef37582c0be6de39e1473cc99a4a0f32fd61ec735cd9e86276b2c25fc781e7df8cd6afdc819208f7f497a755e217bff75728d05f543b'
10
- }
11
-
12
- # Use the database for sessions instead of the cookie-based default,
13
- # which shouldn't be used to store highly confidential information
14
- # (create the session table with "rake db:sessions:create")
15
- # ActionController::Base.session_store = :active_record_store
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
@@ -1,43 +0,0 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- # The priority is based upon order of creation: first created -> highest priority.
3
-
4
- # Sample of regular route:
5
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
- # Keep in mind you can assign values other than :controller and :action
7
-
8
- # Sample of named route:
9
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
- # This route can be invoked with purchase_url(:id => product.id)
11
-
12
- # Sample resource route (maps HTTP verbs to controller actions automatically):
13
- # map.resources :products
14
-
15
- # Sample resource route with options:
16
- # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
-
18
- # Sample resource route with sub-resources:
19
- # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
-
21
- # Sample resource route with more complex sub-resources
22
- # map.resources :products do |products|
23
- # products.resources :comments
24
- # products.resources :sales, :collection => { :recent => :get }
25
- # end
26
-
27
- # Sample resource route within a namespace:
28
- # map.namespace :admin do |admin|
29
- # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
- # admin.resources :products
31
- # end
32
-
33
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
- # map.root :controller => "welcome"
35
-
36
- # See how all your routes lay out with "rake routes"
37
-
38
- # Install the default routes as the lowest priority.
39
- # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
- # consider removing or commenting them out if you're using named routes and resources.
41
- map.connect ':controller/:action/:id'
42
- map.connect ':controller/:action/:id.:format'
43
- end
@@ -1,37 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration
2
-
3
- def self.up
4
- create_table :users do |t|
5
- t.datetime :created_at
6
- t.datetime :updated_at
7
- t.integer :lock_version, :default => 0
8
- t.integer :company_id
9
- t.string :login
10
- t.string :crypted_password
11
- t.string :password_salt
12
- t.string :persistence_token
13
- t.string :single_access_token
14
- t.string :perishable_token
15
- t.string :email
16
- t.string :first_name
17
- t.string :last_name
18
- t.integer :login_count, :default => 0, :null => false
19
- t.integer :failed_login_count, :default => 0, :null => false
20
- t.datetime :last_request_at
21
- t.datetime :current_login_at
22
- t.datetime :last_login_at
23
- t.string :current_login_ip
24
- t.string :last_login_ip
25
- t.boolean :active, :default => true
26
- t.boolean :approved, :default => true
27
- t.boolean :confirmed, :default => true
28
- t.string :facebook_uid
29
- end
30
-
31
- end
32
-
33
- def self.down
34
- drop_table :users
35
- end
36
-
37
- end
@@ -1,7 +0,0 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
- # Major.create(:name => 'Daley', :city => cities.first)
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/console'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/dbconsole'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/generate'
@@ -1,43 +0,0 @@
1
- # Load the environment
2
- ENV['RAILS_ENV'] = 'test'
3
- rails_root = File.dirname(__FILE__) + '/rails_root'
4
- require "#{rails_root}/config/environment.rb"
5
-
6
- # Load the testing framework
7
- require 'test_help'
8
- require 'flexmock/test_unit'
9
- require "authlogic/test_case"
10
-
11
- silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
12
-
13
- # Run the migrations
14
- ActiveRecord::Migration.verbose = false
15
- ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
16
-
17
- # Setup the fixtures path
18
-
19
- class ActiveSupport::TestCase #:nodoc:
20
- self.fixture_path = File.join(File.dirname(__FILE__), "fixtures")
21
- self.use_transactional_fixtures = false
22
- self.use_instantiated_fixtures = false
23
- self.pre_loaded_fixtures = false
24
-
25
- fixtures :all
26
- setup :activate_authlogic
27
-
28
- end
29
-
30
- # --- Sample valid cookie hash generated with the code below
31
- # cookie_hash = {'fbs_233423200151' => 'access_token=233423200151|6892d62675cd952ade8b3f9b-6184456410|xrNaOlTCUF0QFZrJCHmVWzTb5Mk.&expires=0&secret=339a00cdafe6959c3caa1b8004e5f8db&session_key=6892d62675cd952ade8b3f9b-6184456410&sig=19d3c9ccb5b5a55d680ed1cf18698f57&uid=6184456410'}
32
-
33
- # --- Generates user params from cookie for this app_id & secret
34
- # oauth = Koala::Facebook::OAuth.new('233423200151', '8371c9fc95a7d0a3d9cdb6bbacfea306')
35
- # params = oauth.get_user_from_cookie(cookie_hash)
36
-
37
- # --- Generates a signature for a cookie hash
38
- # fb_cookie = cookie_hash["fbs_233423200151"]
39
- # components = {}
40
- # fb_cookie.split("&").map {|param| param = param.split("="); components[param[0]] = param[1]}
41
- # auth_string = components.keys.sort.collect {|a| a == "sig" ? nil : "#{a}=#{components[a]}"}.reject {|a| a.nil?}.join("")
42
- # sig = Digest::MD5.hexdigest(auth_string + '8371c9fc95a7d0a3d9cdb6bbacfea306')
43
-
@@ -1,182 +0,0 @@
1
- require File.expand_path( '../test_helper.rb', File.dirname(__FILE__) )
2
-
3
- class AdapterTest < ActiveSupport::TestCase
4
-
5
- setup :activate_authlogic
6
-
7
- context "Adapter" do
8
- setup do
9
- @user_info = {
10
- 'session_key' => 'mocksessionkey',
11
- 'expires' => '0',
12
- 'uid' => 'mockuid',
13
- 'sig' => 'cbd80b97f124bf392f76e2ee61168990',
14
- 'secret' => 'mocksecret',
15
- 'access_token' => 'mockaccesstoken'
16
- }
17
- @mock_cookies = MockCookieJar.new
18
- @mock_cookies['fbs_mockappid'] = {:value => 'access_token=mockaccesstoken&expires=0&secret=mocksecret&session_key=mocksessionkey&sig=cbd80b97f124bf392f76e2ee61168990&uid=mockuid'}
19
- @session = flexmock(UserSession.new)
20
- @controller = flexmock('Controller')
21
-
22
- @session.should_receive(:facebook_app_id).and_return('mockappid').by_default
23
- @session.should_receive(:facebook_api_key).and_return('mockapikey').by_default
24
- @session.should_receive(:facebook_secret_key).and_return('mocksecret').by_default
25
- @session.should_receive(:controller).and_return(@controller).by_default
26
- @controller.should_receive(:cookies).and_return(@mock_cookies).by_default
27
- end
28
-
29
- context "setup - for my own sanity" do
30
-
31
- should "set the controller" do
32
- assert_equal @controller, @session.controller
33
- end
34
-
35
- should "set the cookies" do
36
- assert_equal @mock_cookies, @session.controller.cookies
37
- end
38
-
39
- should "set the facebook_app_id" do
40
- assert_equal 'mockappid', @session.facebook_app_id
41
- end
42
-
43
- should "set the facebook_secret_key" do
44
- assert_equal 'mocksecret', @session.facebook_secret_key
45
- end
46
-
47
- should "set the facebook_api_key" do
48
- assert_equal 'mockapikey', @session.facebook_api_key
49
- end
50
-
51
- end
52
-
53
- context "facebook_session" do
54
-
55
- context "with a valid facebook cookie" do
56
-
57
- context "and koala support for get_user_info_from_cookie" do
58
-
59
- should "return a session_key" do
60
- assert_equal 'mocksessionkey', @session.facebook_session.session_key
61
- end
62
-
63
- should "return a uid" do
64
- assert_equal 'mockuid', @session.facebook_session.uid
65
- end
66
-
67
- should "return a secret" do
68
- assert_equal 'mocksecret', @session.facebook_session.secret
69
- end
70
-
71
- should "return a sig" do
72
- assert_equal 'cbd80b97f124bf392f76e2ee61168990', @session.facebook_session.sig
73
- end
74
-
75
- should "return an access_token" do
76
- assert_equal 'mockaccesstoken', @session.facebook_session.access_token
77
- end
78
-
79
- end
80
-
81
- context "with previous koala api" do
82
-
83
- should "get user info with the get_user_from_cookie method" do
84
- @oauth = flexmock('oauth')
85
- flexmock(Koala::Facebook::OAuth).should_receive(:new).and_return(@oauth).once
86
- @oauth.should_receive(:respond_to?).with(:get_user_info_from_cookie).and_return(false).once
87
- @oauth.should_receive(:get_user_from_cookie).with(@mock_cookies).and_return(@user_info).once
88
-
89
- assert_equal 'mocksessionkey', @session.facebook_session.session_key
90
- end
91
-
92
- end
93
-
94
- end
95
-
96
- context "with no valid facebook cookie" do
97
-
98
- should "return nil" do
99
- @session.should_receive('facebook_app_id').and_return(nil).once
100
- assert_nil @session.facebook_session
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- context "facebook_session?" do
108
-
109
- context "with a valid facebook session" do
110
-
111
- should "be true" do
112
- assert @session.facebook_session?
113
- end
114
-
115
- end
116
-
117
- context "without a valid facebook session" do
118
-
119
- should "return nil" do
120
- @session.should_receive('facebook_app_id').and_return(nil).once
121
- assert_equal false, @session.facebook_session?
122
- end
123
-
124
- end
125
-
126
- end
127
-
128
- context "facebook_user" do
129
-
130
- context "with a valid facebook session" do
131
-
132
- setup do
133
- @user = {
134
- "id" => "mockid",
135
- "name" => "Full name",
136
- "first_name" => "First name",
137
- "last_name" => "Last name"
138
- }
139
-
140
- @access_token = flexmock('access token')
141
- @session.should_receive('facebook_session.access_token').and_return(@access_token).by_default
142
- @session.should_receive('facebook_session?').and_return(true).by_default
143
-
144
- @graph_api = flexmock('graph api', :get_object => @user)
145
- flexmock(Koala::Facebook::GraphAPI).should_receive(:new).and_return(@graph_api).by_default
146
- end
147
-
148
- should "initialize the graph api" do
149
- flexmock(Koala::Facebook::GraphAPI).should_receive(:new).with(@access_token).and_return(@graph_api).once
150
- @session.facebook_user
151
- end
152
-
153
- should "return an OpenStruct" do
154
- assert @session.facebook_user.is_a?(OpenStruct)
155
- end
156
-
157
- should "return the user details" do
158
- assert_equal 'Full name', @session.facebook_user.name
159
- assert_equal 'First name', @session.facebook_user.first_name
160
- assert_equal 'Last name', @session.facebook_user.last_name
161
- end
162
-
163
- should "return the facebook id as uid" do
164
- assert_equal 'mockid', @session.facebook_user.uid
165
- end
166
-
167
- end
168
-
169
- context "with no valid facebook session" do
170
-
171
- should "return nil" do
172
- @session.should_receive('facebook_session?').and_return(false).once
173
- assert_nil @session.facebook_user
174
- end
175
-
176
- end
177
-
178
- end
179
-
180
- end
181
-
182
- end
@@ -1,145 +0,0 @@
1
- require File.expand_path( '../test_helper.rb', File.dirname(__FILE__) )
2
-
3
- class ConfigTest < ActiveSupport::TestCase
4
-
5
- context "Config" do
6
-
7
- setup do
8
- @session_class = Class.new(Authlogic::Session::Base)
9
- end
10
-
11
- context "facebook_config_file" do
12
-
13
- should "have a default 'facebook.yml'" do
14
- assert_equal 'facebook.yml', @session_class.facebook_config_file
15
- end
16
-
17
- should "have a setter method" do
18
- fb_config = 'fbconf.yml'
19
- @session_class.facebook_config_file = fb_config
20
- assert_equal fb_config, @session_class.facebook_config_file
21
- end
22
-
23
- end
24
-
25
- context "facebook_app_id" do
26
-
27
- should "default to default_config.app_id" do
28
- default_from_config = 'defaultappid'
29
- flexmock(@session_class).should_receive('default_config.app_id').and_return(default_from_config).once
30
- assert_equal default_from_config, @session_class.facebook_app_id
31
- end
32
-
33
- should "have a setter method" do
34
- fb_app_id = '234234234'
35
- @session_class.facebook_app_id = fb_app_id
36
- assert_equal fb_app_id, @session_class.facebook_app_id
37
- end
38
-
39
- end
40
-
41
- context "facebook_secret_key" do
42
-
43
- should "default to default_config.secret_key" do
44
- default_from_config = 'defaultsecretkey'
45
- flexmock(@session_class).should_receive('default_config.secret_key').and_return(default_from_config).once
46
- assert_equal default_from_config, @session_class.facebook_secret_key
47
- end
48
-
49
- should "have a setter method" do
50
- fb_secret = '553246736447566b583138525a716e693950736'
51
- @session_class.facebook_secret_key = fb_secret
52
- assert_equal fb_secret, @session_class.facebook_secret_key
53
- end
54
-
55
- end
56
-
57
- context "facebook_api_key" do
58
-
59
- should "default to default_config.api_key" do
60
- default_from_config = 'defaultapikey'
61
- flexmock(@session_class).should_receive('default_config.api_key').and_return(default_from_config).once
62
- assert_equal default_from_config, @session_class.facebook_api_key
63
- end
64
-
65
- should "have a setter method" do
66
- fb_api_key = '25a366a46366451636933676978776a45585734'
67
- @session_class.facebook_api_key = fb_api_key
68
- assert_equal fb_api_key, @session_class.facebook_api_key
69
- end
70
-
71
- end
72
-
73
- context "facebook_uid_field" do
74
-
75
- should "have a default of :facebook_uid" do
76
- assert_equal :facebook_uid, @session_class.facebook_uid_field
77
- end
78
-
79
- should "have a setter method" do
80
- fb_uid_field = 'fb_uid'
81
- @session_class.facebook_uid_field = fb_uid_field
82
- assert_equal fb_uid_field, @session_class.facebook_uid_field
83
- end
84
-
85
- end
86
-
87
- context "facebook_finder" do
88
-
89
- should 'have a default nil' do
90
- assert_nil @session_class.facebook_finder
91
- end
92
-
93
- should "have a setter method" do
94
- fb_finder = 'find_by_fb_uid'
95
- @session_class.facebook_finder = fb_finder
96
- assert_equal fb_finder, @session_class.facebook_finder
97
- end
98
-
99
- end
100
-
101
- context "facebook_auto_register" do
102
-
103
- should 'have a default false' do
104
- assert_false @session_class.facebook_auto_register
105
- end
106
-
107
- should "have a setter method" do
108
- fb_auto_reg = true
109
- @session_class.facebook_auto_register = fb_auto_reg
110
- assert_equal fb_auto_reg, @session_class.facebook_auto_register
111
- end
112
-
113
- end
114
-
115
- context "default_config" do
116
-
117
- should "be a class method" do
118
- assert @session_class.respond_to?(:default_config)
119
- end
120
-
121
- should "return an OpenStruct" do
122
- assert @session_class.default_config.is_a?(OpenStruct)
123
- end
124
-
125
- should "return the app_id from the default config file" do
126
- assert_equal 'appidfromfile', @session_class.default_config.app_id
127
- end
128
-
129
- should "return the api_key from the default config file" do
130
- assert_equal 'apikeyfromfile', @session_class.default_config.api_key
131
- end
132
-
133
- should "return the secret_key from the default config file" do
134
- assert_equal 'secretkeyfromfile', @session_class.default_config.secret_key
135
- end
136
-
137
- should "return an empty OpenStruct if the file isn't found" do
138
- flexmock(@session_class).should_receive(:facebook_config_file).and_return('notthere.yml').once
139
- assert_equal OpenStruct.new({}), @session_class.default_config
140
- end
141
- end
142
-
143
- end
144
-
145
- end