socialite 0.0.1.beta4 → 0.1.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/README.md +33 -34
  2. data/Rakefile +8 -21
  3. data/app/controllers/socialite/application_controller.rb +4 -0
  4. data/app/controllers/socialite/identities_controller.rb +2 -14
  5. data/app/controllers/socialite/session_controller.rb +20 -0
  6. data/app/controllers/socialite/users_controller.rb +0 -1
  7. data/app/views/layouts/socialite/application.html.haml +11 -0
  8. data/app/views/socialite/identities/new.html.haml +27 -0
  9. data/app/views/socialite/session/new.html.haml +31 -14
  10. data/app/views/socialite/user/edit.html.haml +1 -1
  11. data/config/routes.rb +7 -7
  12. data/lib/generators/socialite/install_generator.rb +7 -9
  13. data/lib/generators/socialite/migrations_generator.rb +34 -0
  14. data/lib/generators/socialite/templates/identity.rb.erb +25 -0
  15. data/lib/generators/socialite/templates/socialite.rb +20 -7
  16. data/lib/generators/socialite/templates/users.rb.erb +12 -0
  17. data/lib/socialite.rb +25 -27
  18. data/lib/socialite/controllers/helpers.rb +107 -111
  19. data/lib/socialite/engine.rb +19 -32
  20. data/lib/socialite/helpers/authentication.rb +1 -1
  21. data/lib/socialite/models/identity_concern.rb +91 -0
  22. data/lib/socialite/models/user_concern.rb +54 -0
  23. data/lib/socialite/version.rb +1 -1
  24. data/spec/dummy/README.rdoc +261 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +9 -3
  26. data/spec/dummy/app/assets/stylesheets/application.css +11 -5
  27. data/{app/assets/images/socialite → spec/dummy/app/mailers}/.gitkeep +0 -0
  28. data/{app/assets/javascripts/socialite → spec/dummy/app/models}/.gitkeep +0 -0
  29. data/spec/dummy/app/models/identity.rb +4 -0
  30. data/spec/dummy/app/models/user.rb +4 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +1 -5
  32. data/spec/dummy/config/application.rb +19 -2
  33. data/spec/dummy/config/boot.rb +1 -11
  34. data/spec/dummy/config/database.yml +18 -2
  35. data/spec/dummy/config/environments/development.rb +8 -1
  36. data/spec/dummy/config/environments/production.rb +9 -2
  37. data/spec/dummy/config/environments/test.rb +4 -9
  38. data/spec/dummy/config/initializers/inflections.rb +5 -0
  39. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  40. data/spec/dummy/config/initializers/session_store.rb +1 -1
  41. data/spec/dummy/config/initializers/socialite.rb +26 -4
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  43. data/spec/dummy/config/routes.rb +2 -10
  44. data/{db/migrate/20110914215410_create_users.rb → spec/dummy/db/migrate/20130206224516_create_socialite_users.rb} +2 -4
  45. data/spec/dummy/db/migrate/20130206224517_create_socialite_identities.rb +25 -0
  46. data/spec/dummy/db/schema.rb +12 -20
  47. data/{lib/tasks → spec/dummy/lib/assets}/.gitkeep +0 -0
  48. data/spec/dummy/log/.gitkeep +0 -0
  49. data/spec/dummy/public/500.html +0 -1
  50. data/spec/factories/facebook.rb +5 -5
  51. data/spec/factories/identity.rb +3 -3
  52. data/spec/factories/user.rb +10 -12
  53. data/spec/generators/socialite/install_generator_spec.rb +43 -0
  54. data/spec/generators/socialite/migrations_generator_spec.rb +27 -0
  55. data/spec/models/facebook_spec.rb +24 -21
  56. data/spec/models/identity_spec.rb +2 -2
  57. data/spec/models/user_spec.rb +7 -7
  58. data/spec/socialite_spec.rb +53 -0
  59. data/spec/spec_helper.rb +23 -10
  60. data/spec/support/identity_shared_example.rb +24 -20
  61. metadata +202 -144
  62. data/.autotest +0 -7
  63. data/.gitignore +0 -9
  64. data/.rspec +0 -2
  65. data/.travis.yml +0 -10
  66. data/.yardopts +0 -8
  67. data/Gemfile +0 -8
  68. data/Gemfile.lock +0 -208
  69. data/app/models/socialite/facebook_identity.rb +0 -5
  70. data/app/models/socialite/identity.rb +0 -5
  71. data/app/models/socialite/user.rb +0 -10
  72. data/config/initializers/simple_form.rb +0 -90
  73. data/config/locales/simple_form.en.yml +0 -23
  74. data/db/migrate/20110925224222_create_identities.rb +0 -26
  75. data/db/migrate/20110926005551_create_facebook_identities.rb +0 -12
  76. data/lib/socialite/api_wrappers/facebook.rb +0 -67
  77. data/lib/socialite/api_wrappers/twitter.rb +0 -19
  78. data/lib/socialite/models/identity.rb +0 -99
  79. data/lib/socialite/models/user.rb +0 -50
  80. data/lib/socialite/service_config.rb +0 -14
  81. data/lib/tasks/cucumber.rake +0 -65
  82. data/script/cucumber +0 -10
  83. data/script/rails +0 -6
  84. data/socialite.gemspec +0 -39
  85. data/spec/dummy/app/controllers/home_controller.rb +0 -11
  86. data/spec/dummy/app/views/home/index.html.haml +0 -12
  87. data/spec/dummy/app/views/home/show.html.haml +0 -6
@@ -1,19 +0,0 @@
1
- module Socialite
2
- module ApiWrappers
3
- module Twitter
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- require 'twitter'
8
- end
9
-
10
- module ClassMethods
11
-
12
- end
13
-
14
- module InstanceMethods
15
-
16
- end
17
- end
18
- end
19
- end
@@ -1,99 +0,0 @@
1
- module Socialite
2
- module Models
3
- module Identity
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- belongs_to :api, :polymorphic => true, :dependent => :destroy
8
- belongs_to :user
9
- serialize :auth_hash
10
-
11
- # Ensure that before validation happens that the provider
12
- # database column matches what is inside of the auth_hash
13
- # dataset.
14
- before_validation do |identity|
15
- if identity.auth_hash.present?
16
- identity.provider = identity.auth_hash.delete('provider') if identity.provider.blank?
17
- identity.unique_id = identity.auth_hash.delete('uid') if identity.unique_id.blank?
18
- end
19
- end
20
-
21
- # Ensure each user has only a single identity per provider type
22
- validates :provider,
23
- :uniqueness => {:scope => :user_id, :case_sensitive => false},
24
- :presence => true
25
-
26
- # Ensure an identity is never reused by another account
27
- validates :unique_id,
28
- :uniqueness => {:scope => :provider},
29
- :presence => true
30
-
31
- # Ensure an associated user exists before creating the identity
32
- # validates_associated :user
33
- end
34
-
35
- module ClassMethods
36
- # Finder method that finds the matching Provider and Unique ID or
37
- # initializes a new, unsaved, object.
38
- #
39
- # @params [Hash] the OAuth authentication hash
40
- # @returns [Identity]
41
- def find_or_initialize_by_oauth(auth_hash)
42
- identity = where(:provider => auth_hash['provider'], :unique_id => auth_hash['uid']).first || new
43
- identity.auth_hash = auth_hash
44
- identity
45
- end
46
- end
47
-
48
- module InstanceMethods
49
- # Method that maps uid to unique_id which is what we store it as.
50
- #
51
- # @returns [String]
52
- # def uid=(new_uid)
53
- # self.unique_id = new_uid
54
- # end
55
-
56
- # Convenience method for accessing the OAuth access token
57
- #
58
- # @returns [String] OAuth access token
59
- # (see #credentials)
60
- def access_token
61
- credentials['token']
62
- end
63
-
64
- # Convenience method for accessing the OAuth access token secret
65
- #
66
- # @returns [String] OAuth access token secret
67
- # (see #credentials)
68
- def access_token_secret
69
- credentials['secret']
70
- end
71
-
72
- # Convenience method for accessing the OAuth credentials sub-hash
73
- #
74
- # @returns [Hash] OAuth credentials sub-hash
75
- # (see #access_token)
76
- # (see #access_token_secret)
77
- def credentials
78
- auth_hash['credentials']
79
- end
80
-
81
- # Convenience method for accessing the nickname, which is typically
82
- # set to the login name used for that provider.
83
- #
84
- # @returns [String] user nickname for the provider identity
85
- def nickname
86
- user_info['nickname']
87
- end
88
-
89
- # Convenience method for accessing the user information from the
90
- # OAuth provider.
91
- #
92
- # @returns [Hash] the user information sub-hash
93
- def user_info
94
- auth_hash['user_info']
95
- end
96
- end
97
- end
98
- end
99
- end
@@ -1,50 +0,0 @@
1
- module Socialite
2
- module Models
3
- module User
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- has_many :identities, :dependent => :destroy
8
-
9
- # has_one :facebook_identity,
10
- # :class_name => 'Identity', :foreign_key => 'user_id', :conditions => { :provider => 'facebook' }
11
- # has_one :twitter_identity,
12
- # :class_name => 'Identity', :foreign_key => 'user_id', :conditions => { :provider => 'twitter' }
13
- end
14
-
15
- module InstanceMethods
16
- # Returns the first linked facebook identity
17
- #
18
- # @return [FacebookIdentity] the first facebook identity
19
- def facebook
20
- self.facebook_identity.api
21
- end
22
-
23
- # Returns the first linked twitter account
24
- #
25
- # @return [TwitterIdentity] the first twitter identity
26
- def twitter
27
- self.twitter_identity.api
28
- end
29
-
30
- # Set the user's remember token
31
- #
32
- # @return [User] the current user
33
- def remember_me!
34
- self.remember_token = Socialite.generate_token
35
- save(:validate => false)
36
- end
37
-
38
- # Clear the user's remember token
39
- #
40
- # @return [User] the current user
41
- def forget_me!
42
- if persisted?
43
- self.remember_token = nil
44
- save(:validate => false)
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,14 +0,0 @@
1
- require 'ostruct'
2
-
3
- module Socialite
4
- class ServiceConfig < OpenStruct
5
- # Set credentials and options for a given service, i.e. twitter
6
- def initialize(app_key, app_secret, options)
7
- super({
8
- :app_key => app_key,
9
- :app_secret => app_secret,
10
- :options => options
11
- })
12
- end
13
- end
14
- end
@@ -1,65 +0,0 @@
1
- # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
- # It is recommended to regenerate this file in the future when you upgrade to a
3
- # newer version of cucumber-rails. Consider adding your own code to a new file
4
- # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
- # files.
6
-
7
-
8
- unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
-
10
- vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
- $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
-
13
- begin
14
- require 'cucumber/rake/task'
15
-
16
- namespace :cucumber do
17
- Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18
- t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
- t.fork = true # You may get faster startup if you set this to false
20
- t.profile = 'default'
21
- end
22
-
23
- Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24
- t.binary = vendored_cucumber_bin
25
- t.fork = true # You may get faster startup if you set this to false
26
- t.profile = 'wip'
27
- end
28
-
29
- Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
- t.binary = vendored_cucumber_bin
31
- t.fork = true # You may get faster startup if you set this to false
32
- t.profile = 'rerun'
33
- end
34
-
35
- desc 'Run all features'
36
- task :all => [:ok, :wip]
37
-
38
- task :statsetup do
39
- require 'rails/code_statistics'
40
- ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41
- ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42
- end
43
- end
44
- desc 'Alias for cucumber:ok'
45
- task :cucumber => 'cucumber:ok'
46
-
47
- task :default => :cucumber
48
-
49
- task :features => :cucumber do
50
- STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51
- end
52
-
53
- # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
54
- task 'db:test:prepare' do
55
- end
56
-
57
- task :stats => 'cucumber:statsetup'
58
- rescue LoadError
59
- desc 'cucumber rake task not available (cucumber not installed)'
60
- task :cucumber do
61
- abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62
- end
63
- end
64
-
65
- end
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
- if vendored_cucumber_bin
5
- load File.expand_path(vendored_cucumber_bin)
6
- else
7
- require 'rubygems' unless ENV['NO_RUBYGEMS']
8
- require 'cucumber'
9
- load Cucumber::BINARY
10
- end
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #!/usr/bin/env ruby
3
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
4
-
5
- ENGINE_PATH = File.expand_path('../..', __FILE__)
6
- load File.expand_path('../../spec/dummy/script/rails', __FILE__)
@@ -1,39 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
-
3
- # Maintain your gem's version:
4
- require 'socialite/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = 'socialite'
8
- gem.version = Socialite::VERSION
9
- gem.platform = Gem::Platform::RUBY
10
- gem.authors = ['Justin Smestad']
11
- gem.email = 'justin.smestad@gmail.com'
12
- gem.homepage = 'http://github.com/jsmestad/socialite'
13
- gem.summary = 'Rails engine supporting multiple auth providers per user.'
14
- gem.description = 'Rails engine supporting multiple auth providers per user.'
15
-
16
- gem.files = `git ls-files`.split("\n")
17
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- gem.require_paths = ["lib"]
19
-
20
- gem.add_dependency 'rails', '~> 3.1.0'
21
- gem.add_dependency 'sass-rails', '~> 3.1.0'
22
- gem.add_dependency 'simple_form', '~> 1.5.2'
23
- gem.add_dependency 'haml', '~> 3.1.2'
24
- gem.add_dependency 'oa-core', '~> 0.3.0.rc3'
25
- gem.add_dependency 'oa-oauth', '~> 0.3.0.rc3'
26
- gem.add_dependency 'koala', '~> 1.2.0beta4'
27
- gem.add_dependency 'grackle', '~> 0.1.10'
28
-
29
- gem.add_development_dependency 'sqlite3'
30
- gem.add_development_dependency 'yard'
31
- gem.add_development_dependency 'rdiscount'
32
- gem.add_development_dependency 'rspec-rails', '~> 2.6.1'
33
- gem.add_development_dependency 'factory_girl', '~> 2.1.0'
34
- gem.add_development_dependency 'shoulda-matchers'
35
- gem.add_development_dependency 'cucumber-rails', '~> 1.0.6'
36
- gem.add_development_dependency 'database_cleaner', '>= 0.6.7'
37
- gem.add_development_dependency 'selenium-webdriver', '>= 2.4.0'
38
- gem.add_development_dependency 'launchy', '~> 2.0.5'
39
- end
@@ -1,11 +0,0 @@
1
- class HomeController < ApplicationController
2
- before_filter :ensure_user, :only => [:show]
3
-
4
- def index
5
- render
6
- end
7
-
8
- def show
9
- render
10
- end
11
- end
@@ -1,12 +0,0 @@
1
- %h2 Unrestricted Dummy Homepage
2
-
3
- %a{:href => '/restricted'} Go to Restricted Page
4
-
5
- #authentication
6
- - if user_signed_in?
7
- = link_to 'Sign out', socialite.logout_path
8
- - else
9
- = link_to 'Sign in', socialite.login_path
10
-
11
- #user
12
- = link_to 'User Profile', socialite.user_path
@@ -1,6 +0,0 @@
1
- %h1 Dummy App Sandbox
2
-
3
- %p You are viewing a page that should be restricted to logged in users only.
4
-
5
- %section
6
- %h3 Login Status: #{user_signed_in? ? 'Logged In' : 'Logged Out'}