socialite 0.0.1.beta4 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -34
- data/Rakefile +8 -21
- data/app/controllers/socialite/application_controller.rb +4 -0
- data/app/controllers/socialite/identities_controller.rb +2 -14
- data/app/controllers/socialite/session_controller.rb +20 -0
- data/app/controllers/socialite/users_controller.rb +0 -1
- data/app/views/layouts/socialite/application.html.haml +11 -0
- data/app/views/socialite/identities/new.html.haml +27 -0
- data/app/views/socialite/session/new.html.haml +31 -14
- data/app/views/socialite/user/edit.html.haml +1 -1
- data/config/routes.rb +7 -7
- data/lib/generators/socialite/install_generator.rb +7 -9
- data/lib/generators/socialite/migrations_generator.rb +34 -0
- data/lib/generators/socialite/templates/identity.rb.erb +25 -0
- data/lib/generators/socialite/templates/socialite.rb +20 -7
- data/lib/generators/socialite/templates/users.rb.erb +12 -0
- data/lib/socialite.rb +25 -27
- data/lib/socialite/controllers/helpers.rb +107 -111
- data/lib/socialite/engine.rb +19 -32
- data/lib/socialite/helpers/authentication.rb +1 -1
- data/lib/socialite/models/identity_concern.rb +91 -0
- data/lib/socialite/models/user_concern.rb +54 -0
- data/lib/socialite/version.rb +1 -1
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -3
- data/spec/dummy/app/assets/stylesheets/application.css +11 -5
- data/{app/assets/images/socialite → spec/dummy/app/mailers}/.gitkeep +0 -0
- data/{app/assets/javascripts/socialite → spec/dummy/app/models}/.gitkeep +0 -0
- data/spec/dummy/app/models/identity.rb +4 -0
- data/spec/dummy/app/models/user.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +1 -5
- data/spec/dummy/config/application.rb +19 -2
- data/spec/dummy/config/boot.rb +1 -11
- data/spec/dummy/config/database.yml +18 -2
- data/spec/dummy/config/environments/development.rb +8 -1
- data/spec/dummy/config/environments/production.rb +9 -2
- data/spec/dummy/config/environments/test.rb +4 -9
- data/spec/dummy/config/initializers/inflections.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/socialite.rb +26 -4
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +2 -10
- data/{db/migrate/20110914215410_create_users.rb → spec/dummy/db/migrate/20130206224516_create_socialite_users.rb} +2 -4
- data/spec/dummy/db/migrate/20130206224517_create_socialite_identities.rb +25 -0
- data/spec/dummy/db/schema.rb +12 -20
- data/{lib/tasks → spec/dummy/lib/assets}/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/500.html +0 -1
- data/spec/factories/facebook.rb +5 -5
- data/spec/factories/identity.rb +3 -3
- data/spec/factories/user.rb +10 -12
- data/spec/generators/socialite/install_generator_spec.rb +43 -0
- data/spec/generators/socialite/migrations_generator_spec.rb +27 -0
- data/spec/models/facebook_spec.rb +24 -21
- data/spec/models/identity_spec.rb +2 -2
- data/spec/models/user_spec.rb +7 -7
- data/spec/socialite_spec.rb +53 -0
- data/spec/spec_helper.rb +23 -10
- data/spec/support/identity_shared_example.rb +24 -20
- metadata +202 -144
- data/.autotest +0 -7
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.travis.yml +0 -10
- data/.yardopts +0 -8
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -208
- data/app/models/socialite/facebook_identity.rb +0 -5
- data/app/models/socialite/identity.rb +0 -5
- data/app/models/socialite/user.rb +0 -10
- data/config/initializers/simple_form.rb +0 -90
- data/config/locales/simple_form.en.yml +0 -23
- data/db/migrate/20110925224222_create_identities.rb +0 -26
- data/db/migrate/20110926005551_create_facebook_identities.rb +0 -12
- data/lib/socialite/api_wrappers/facebook.rb +0 -67
- data/lib/socialite/api_wrappers/twitter.rb +0 -19
- data/lib/socialite/models/identity.rb +0 -99
- data/lib/socialite/models/user.rb +0 -50
- data/lib/socialite/service_config.rb +0 -14
- data/lib/tasks/cucumber.rake +0 -65
- data/script/cucumber +0 -10
- data/script/rails +0 -6
- data/socialite.gemspec +0 -39
- data/spec/dummy/app/controllers/home_controller.rb +0 -11
- data/spec/dummy/app/views/home/index.html.haml +0 -12
- data/spec/dummy/app/views/home/show.html.haml +0 -6
@@ -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
|
data/lib/tasks/cucumber.rake
DELETED
@@ -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
|
data/script/cucumber
DELETED
@@ -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
|
data/script/rails
DELETED
@@ -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__)
|
data/socialite.gemspec
DELETED
@@ -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,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
|