social_auth 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +39 -0
- data/app/models/social_auth/facebook_service.rb +60 -0
- data/app/models/social_auth/google_plus_service.rb +106 -0
- data/app/models/social_auth/service.rb +152 -0
- data/app/models/social_auth/twitter_service.rb +67 -0
- data/config/routes.rb +2 -0
- data/lib/generators/social_auth/install/install_generator.rb +37 -0
- data/lib/generators/social_auth/install/templates/create_social_auth_services.rb +12 -0
- data/lib/generators/social_auth/install/templates/initializer.rb +15 -0
- data/lib/social_auth.rb +73 -0
- data/lib/social_auth/acts_as_social_user.rb +23 -0
- data/lib/social_auth/engine.rb +12 -0
- data/lib/social_auth/railtie.rb +7 -0
- data/lib/social_auth/version.rb +3 -0
- data/lib/tasks/social_auth_tasks.rake +4 -0
- data/spec/dummy/rails-4.2.0/Gemfile +42 -0
- data/spec/dummy/rails-4.2.0/README.rdoc +28 -0
- data/spec/dummy/rails-4.2.0/Rakefile +6 -0
- data/spec/dummy/rails-4.2.0/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/rails-4.2.0/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/rails-4.2.0/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/rails-4.2.0/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/rails-4.2.0/app/models/user.rb +2 -0
- data/spec/dummy/rails-4.2.0/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/rails-4.2.0/bin/bundle +3 -0
- data/spec/dummy/rails-4.2.0/bin/rails +4 -0
- data/spec/dummy/rails-4.2.0/bin/rake +4 -0
- data/spec/dummy/rails-4.2.0/bin/setup +29 -0
- data/spec/dummy/rails-4.2.0/config.ru +4 -0
- data/spec/dummy/rails-4.2.0/config/application.rb +26 -0
- data/spec/dummy/rails-4.2.0/config/boot.rb +3 -0
- data/spec/dummy/rails-4.2.0/config/database.yml +15 -0
- data/spec/dummy/rails-4.2.0/config/environment.rb +5 -0
- data/spec/dummy/rails-4.2.0/config/environments/development.rb +41 -0
- data/spec/dummy/rails-4.2.0/config/environments/production.rb +79 -0
- data/spec/dummy/rails-4.2.0/config/environments/test.rb +42 -0
- data/spec/dummy/rails-4.2.0/config/initializers/assets.rb +11 -0
- data/spec/dummy/rails-4.2.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/rails-4.2.0/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/rails-4.2.0/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/rails-4.2.0/config/initializers/inflections.rb +16 -0
- data/spec/dummy/rails-4.2.0/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/rails-4.2.0/config/initializers/session_store.rb +3 -0
- data/spec/dummy/rails-4.2.0/config/initializers/social_auth.rb +15 -0
- data/spec/dummy/rails-4.2.0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/rails-4.2.0/config/locales/en.yml +23 -0
- data/spec/dummy/rails-4.2.0/config/routes.rb +56 -0
- data/spec/dummy/rails-4.2.0/config/secrets.yml +22 -0
- data/spec/dummy/rails-4.2.0/db/migrate/20150504044515878_create_social_auth_services.rb +12 -0
- data/spec/dummy/rails-4.2.0/db/migrate/20150504044519_create_users.rb +9 -0
- data/spec/dummy/rails-4.2.0/db/schema.rb +35 -0
- data/spec/dummy/rails-4.2.0/db/seeds.rb +7 -0
- data/spec/dummy/rails-4.2.0/log/test.log +2570 -0
- data/spec/dummy/rails-4.2.0/public/404.html +67 -0
- data/spec/dummy/rails-4.2.0/public/422.html +67 -0
- data/spec/dummy/rails-4.2.0/public/500.html +66 -0
- data/spec/dummy/rails-4.2.0/public/favicon.ico +0 -0
- data/spec/dummy/rails-4.2.0/public/robots.txt +5 -0
- data/spec/dummy/rails-4.2.0/test/fixtures/users.yml +7 -0
- data/spec/dummy/rails-4.2.0/test/models/user_test.rb +7 -0
- data/spec/dummy/rails-4.2.0/test/test_helper.rb +10 -0
- data/spec/fixtures/vcr_cassettes/facebook_service/invalid_friends_request.yml +54 -0
- data/spec/fixtures/vcr_cassettes/facebook_service/invalid_request.yml +50 -0
- data/spec/fixtures/vcr_cassettes/facebook_service/invalid_token.yml +50 -0
- data/spec/fixtures/vcr_cassettes/facebook_service/valid_friends_request.yml +110 -0
- data/spec/fixtures/vcr_cassettes/facebook_service/valid_request.yml +55 -0
- data/spec/fixtures/vcr_cassettes/google_plus_service/invalid_authorization.yml +51 -0
- data/spec/fixtures/vcr_cassettes/google_plus_service/invalid_friends_request.yml +53 -0
- data/spec/fixtures/vcr_cassettes/google_plus_service/invalid_token.yml +51 -0
- data/spec/fixtures/vcr_cassettes/google_plus_service/valid_authorization.yml +56 -0
- data/spec/fixtures/vcr_cassettes/google_plus_service/valid_friends_request.yml +132 -0
- data/spec/fixtures/vcr_cassettes/google_plus_service/valid_request.yml +110 -0
- data/spec/fixtures/vcr_cassettes/twitter_service/invalid_friends_request.yml +47 -0
- data/spec/fixtures/vcr_cassettes/twitter_service/valid_friends_request.yml +159 -0
- data/spec/fixtures/vcr_cassettes/twitter_service/valid_request.yml +337 -0
- data/spec/models/facebook_service_spec.rb +127 -0
- data/spec/models/google_plus_service_spec.rb +133 -0
- data/spec/models/service_spec.rb +236 -0
- data/spec/models/twitter_service_spec.rb +100 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/database.yml +15 -0
- data/spec/support/rails_template.rb +15 -0
- metadata +376 -0
data/config/routes.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class SocialAuth::InstallGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_migrations
|
9
|
+
copy_migration "create_social_auth_services"
|
10
|
+
|
11
|
+
puts "Installation successful. You can now run:"
|
12
|
+
puts " rake db:migrate"
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_initializer
|
16
|
+
template "initializer.rb", "config/initializers/social_auth.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.next_migration_number(dirname)
|
20
|
+
if ActiveRecord::Base.timestamped_migrations
|
21
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S%L")
|
22
|
+
else
|
23
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def copy_migration(filename)
|
30
|
+
if self.class.migration_exists?("db/migrate", "#{filename}")
|
31
|
+
say_status("skipped", "Migration #{filename}.rb already exists")
|
32
|
+
else
|
33
|
+
migration_template "#{filename}.rb", "db/migrate/#{filename}.rb"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateSocialAuthServices < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :social_auth_services do |t|
|
4
|
+
t.string :type, default: "SocialAuth::Service"
|
5
|
+
t.json :access_token
|
6
|
+
t.string :remote_id
|
7
|
+
t.integer :user_id
|
8
|
+
t.string :method
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
SocialAuth.setup do |config|
|
2
|
+
config.redis_instance_method = :redis_instance_var #eg $redis
|
3
|
+
|
4
|
+
config.twitter_consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
5
|
+
|
6
|
+
config.twitter_consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
7
|
+
|
8
|
+
config.google_client_id = ENV['GOOGLE_CLIENT_ID']
|
9
|
+
|
10
|
+
config.google_client_secret = ENV['GOOGLE_CLIENT_SECRET']
|
11
|
+
|
12
|
+
config.google_redirect_uri = ENV['GOOGLE_REDIRECT_URI']
|
13
|
+
|
14
|
+
config.google_api_key = ENV['GOOGLE_API_KEY']
|
15
|
+
end
|
data/lib/social_auth.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "social_auth/engine"
|
2
|
+
require 'sidekiq'
|
3
|
+
|
4
|
+
module SocialAuth
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :ActsAsSocialUser, 'social_auth/acts_as_social_user'
|
8
|
+
|
9
|
+
mattr_accessor :redis_instance_method
|
10
|
+
@@redis_instance_method = nil
|
11
|
+
|
12
|
+
mattr_accessor :twitter_consumer_key
|
13
|
+
@@twitter_consumer_key = nil
|
14
|
+
|
15
|
+
mattr_accessor :twitter_consumer_secret
|
16
|
+
@@twitter_consumer_secret = nil
|
17
|
+
|
18
|
+
mattr_accessor :google_client_id
|
19
|
+
@@google_client_id = nil
|
20
|
+
|
21
|
+
mattr_accessor :google_client_secret
|
22
|
+
@@google_client_secret = nil
|
23
|
+
|
24
|
+
mattr_accessor :google_redirect_uri
|
25
|
+
@@google_redirect_uri = nil
|
26
|
+
|
27
|
+
mattr_accessor :google_api_key
|
28
|
+
@@google_api_key = nil
|
29
|
+
|
30
|
+
# Used to set up Social Login from the initializer.
|
31
|
+
def self.setup
|
32
|
+
yield self
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.authenticate(type, auth_token)
|
36
|
+
case type.camelize
|
37
|
+
when "Facebook"
|
38
|
+
FacebookService.init_with(auth_token)
|
39
|
+
when "Twitter"
|
40
|
+
TwitterService.init_with(auth_token)
|
41
|
+
when "GooglePlus"
|
42
|
+
GooglePlusService.init_with(auth_token)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.connect(user, type, auth_token, method="Connected")
|
47
|
+
case type.camelize
|
48
|
+
when "Facebook"
|
49
|
+
FacebookService.connect_with(user, auth_token, method)
|
50
|
+
when "Twitter"
|
51
|
+
TwitterService.connect_with(user, auth_token, method)
|
52
|
+
when "GooglePlus"
|
53
|
+
GooglePlusService.connect_with(user, auth_token, method)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.disconnect(user, type)
|
58
|
+
case type.camelize
|
59
|
+
when "Facebook"
|
60
|
+
FacebookService.disconnect_user(user)
|
61
|
+
when "Twitter"
|
62
|
+
TwitterService.disconnect_user(user)
|
63
|
+
when "GooglePlus"
|
64
|
+
GooglePlusService.disconnect_user(user)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module ActiveRecord
|
70
|
+
class Base
|
71
|
+
include SocialAuth::ActsAsSocialUser
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SocialAuth
|
2
|
+
module ActsAsSocialUser
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
def friends_that_use_the_app
|
8
|
+
self.class.joins(:services).where('social_auth_services.remote_id IN (?)', remote_ids)
|
9
|
+
end
|
10
|
+
|
11
|
+
def remote_ids
|
12
|
+
remote_ids = services.map(&:friend_ids).flatten.map(&:to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def acts_as_social_user(options = {})
|
19
|
+
has_many :services, foreign_key: options[:foreign_key] || :user_id, class_name: SocialAuth::Service
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SocialAuth
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace SocialAuth
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec, :fixture => false
|
7
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
8
|
+
g.assets false
|
9
|
+
g.helper false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
|
4
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
|
+
gem 'rails', '4.2.0'
|
6
|
+
# Use postgresql as the database for Active Record
|
7
|
+
gem 'pg'
|
8
|
+
# Use SCSS for stylesheets
|
9
|
+
gem 'sass-rails', '~> 5.0'
|
10
|
+
# Use Uglifier as compressor for JavaScript assets
|
11
|
+
gem 'uglifier', '>= 1.3.0'
|
12
|
+
# Use CoffeeScript for .coffee assets and views
|
13
|
+
gem 'coffee-rails', '~> 4.1.0'
|
14
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
15
|
+
# gem 'therubyracer', platforms: :ruby
|
16
|
+
|
17
|
+
# Use jquery as the JavaScript library
|
18
|
+
gem 'jquery-rails'
|
19
|
+
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
20
|
+
gem 'turbolinks'
|
21
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
22
|
+
gem 'jbuilder', '~> 2.0'
|
23
|
+
# bundle exec rake doc:rails generates the API under doc/api.
|
24
|
+
gem 'sdoc', '~> 0.4.0', group: :doc
|
25
|
+
|
26
|
+
# Use ActiveModel has_secure_password
|
27
|
+
# gem 'bcrypt', '~> 3.1.7'
|
28
|
+
|
29
|
+
# Use Unicorn as the app server
|
30
|
+
# gem 'unicorn'
|
31
|
+
|
32
|
+
# Use Capistrano for deployment
|
33
|
+
# gem 'capistrano-rails', group: :development
|
34
|
+
|
35
|
+
group :development, :test do
|
36
|
+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
37
|
+
gem 'byebug'
|
38
|
+
|
39
|
+
# Access an IRB console on exception pages or by using <%= console %> in views
|
40
|
+
gem 'web-console', '~> 2.0'
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Rails420</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
module Rails420
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
16
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
17
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
18
|
+
|
19
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
20
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
21
|
+
# config.i18n.default_locale = :de
|
22
|
+
|
23
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
24
|
+
config.active_record.raise_in_transactional_callbacks = true
|
25
|
+
end
|
26
|
+
end
|