socialite 0.0.1.beta → 0.0.1.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/app/controllers/socialite/session_controller.rb +0 -16
- data/app/models/socialite/facebook_identity.rb +1 -3
- data/app/models/socialite/identity.rb +1 -2
- data/app/models/socialite/user.rb +1 -33
- data/config/routes.rb +1 -1
- data/lib/generators/socialite/install_generator.rb +21 -0
- data/lib/generators/socialite/templates/socialite.rb +15 -0
- data/lib/socialite.rb +18 -2
- data/lib/socialite/controllers/helpers.rb +138 -0
- data/lib/socialite/engine.rb +2 -2
- data/lib/socialite/helpers/authentication.rb +17 -0
- data/lib/socialite/models/facebook_identity.rb +14 -0
- data/lib/socialite/models/identity.rb +99 -0
- data/lib/socialite/models/user.rb +50 -0
- data/lib/socialite/version.rb +1 -1
- metadata +45 -41
- data/app/helpers/socialite/authentication_helper.rb +0 -15
- data/lib/socialite/base_identity.rb +0 -96
- data/lib/socialite/controller_support.rb +0 -136
data/Gemfile.lock
CHANGED
@@ -7,22 +7,6 @@ module Socialite
|
|
7
7
|
|
8
8
|
respond_to :html, :json
|
9
9
|
|
10
|
-
# Render the login page.
|
11
|
-
def new
|
12
|
-
respond_with(@user = User.new)
|
13
|
-
end
|
14
10
|
|
15
|
-
# Destroy the session, logging out the current user.
|
16
|
-
def destroy
|
17
|
-
@user = current_user
|
18
|
-
if logout!
|
19
|
-
flash_message :notice, 'You have been logged out.'
|
20
|
-
else
|
21
|
-
flash_message :error, 'We had trouble signing you out.'
|
22
|
-
end
|
23
|
-
respond_with(@user) do |format|
|
24
|
-
format.html { redirect_to default_route }
|
25
|
-
end
|
26
|
-
end
|
27
11
|
end
|
28
12
|
end
|
@@ -1,42 +1,10 @@
|
|
1
1
|
module Socialite
|
2
2
|
class User < ActiveRecord::Base
|
3
|
-
|
3
|
+
include Models::User
|
4
4
|
|
5
5
|
has_one :facebook_identity,
|
6
6
|
:class_name => 'Identity', :foreign_key => 'user_id', :conditions => { :provider => 'facebook' }
|
7
7
|
has_one :twitter_identity,
|
8
8
|
:class_name => 'Identity', :foreign_key => 'user_id', :conditions => { :provider => 'twitter' }
|
9
|
-
|
10
|
-
# Returns the first linked facebook identity
|
11
|
-
#
|
12
|
-
# @return [FacebookIdentity] the first facebook identity
|
13
|
-
def facebook
|
14
|
-
self.facebook_identity.api
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns the first linked twitter account
|
18
|
-
#
|
19
|
-
# @return [TwitterIdentity] the first twitter identity
|
20
|
-
def twitter
|
21
|
-
self.twitter_identity.api
|
22
|
-
end
|
23
|
-
|
24
|
-
# Set the user's remember token
|
25
|
-
#
|
26
|
-
# @return [User] the current user
|
27
|
-
def remember_me!
|
28
|
-
self.remember_token = Socialite.generate_token
|
29
|
-
save(:validate => false)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Clear the user's remember token
|
33
|
-
#
|
34
|
-
# @return [User] the current user
|
35
|
-
def forget_me!
|
36
|
-
if persisted?
|
37
|
-
self.remember_token = nil
|
38
|
-
save(:validate => false)
|
39
|
-
end
|
40
|
-
end
|
41
9
|
end
|
42
10
|
end
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Socialite
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
desc 'Generates the socialite initializer'
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
File.join(File.dirname(__FILE__), 'templates')
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_initializer
|
16
|
+
template 'socialite.rb', 'config/initializers/socialite.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'socialite'
|
2
|
+
|
3
|
+
Socialite.setup do |config|
|
4
|
+
# ==> Twitter
|
5
|
+
# config.twitter 'APP_KEY', 'APP_SECRET'
|
6
|
+
|
7
|
+
# ==> Facebook
|
8
|
+
# config.facebook 'APP_KEY', 'APP_SECRET', :scope => 'publish_stream'
|
9
|
+
|
10
|
+
if Rails.env.production?
|
11
|
+
# Configs for production mode go here
|
12
|
+
elsif Rails.env.development?
|
13
|
+
# Configs for development mode go here
|
14
|
+
end
|
15
|
+
end
|
data/lib/socialite.rb
CHANGED
@@ -3,7 +3,7 @@ require 'omniauth/core'
|
|
3
3
|
require 'omniauth/oauth'
|
4
4
|
|
5
5
|
module Socialite
|
6
|
-
autoload :
|
6
|
+
autoload :ControllerSupport, 'socialite/controller_support'
|
7
7
|
autoload :ServiceConfig, 'socialite/service_config'
|
8
8
|
|
9
9
|
module ApiWrappers
|
@@ -11,6 +11,23 @@ module Socialite
|
|
11
11
|
autoload :Twitter, 'socialite/api_wrappers/twitter'
|
12
12
|
end
|
13
13
|
|
14
|
+
module Controllers
|
15
|
+
autoload :Helpers, 'socialite/controllers/helpers'
|
16
|
+
autoload :Identities, 'socialite/controllers/identities'
|
17
|
+
autoload :Session, 'socialite/controllers/session'
|
18
|
+
autoload :User, 'socialite/controllers/user'
|
19
|
+
end
|
20
|
+
|
21
|
+
module Helpers
|
22
|
+
autoload :Authentication, 'socialite/helpers/authentication.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
module Models
|
26
|
+
autoload :Identity, 'socialite/models/identity'
|
27
|
+
autoload :User, 'socialite/models/user'
|
28
|
+
autoload :FacebookIdentity, 'socialite/models/facebook_identity.rb'
|
29
|
+
end
|
30
|
+
|
14
31
|
mattr_accessor :service_configs, :root_path, :mount_prefix
|
15
32
|
@@service_configs = {}
|
16
33
|
|
@@ -33,5 +50,4 @@ module Socialite
|
|
33
50
|
end
|
34
51
|
end
|
35
52
|
|
36
|
-
require 'socialite/controller_support'
|
37
53
|
require 'socialite/engine'
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module Socialite
|
2
|
+
module Controllers
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
helper_method :current_user, :user_signed_in?, :current_user?, :default_route
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
|
12
|
+
# Set default route for redirect
|
13
|
+
#
|
14
|
+
# @param [String] the path for default redirects
|
15
|
+
# @return [String] the default path for redirect
|
16
|
+
# (see #default_route)
|
17
|
+
def default_route=(route)
|
18
|
+
@default_route = route
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get default route for redirect
|
22
|
+
#
|
23
|
+
# @return [String] the default path for redirect
|
24
|
+
# (see #default_route=)
|
25
|
+
def default_route
|
26
|
+
@default_route ||= '/'
|
27
|
+
end
|
28
|
+
|
29
|
+
# Helper for supporting multiple flash messages per type
|
30
|
+
#
|
31
|
+
# @param [Symbol] the type of flash message. Common types are
|
32
|
+
# :success, :notice, :error
|
33
|
+
# @param [String] the message to attach to the flash type
|
34
|
+
# @return [Hash] all associated flash messages for this request
|
35
|
+
def flash_message(type, text)
|
36
|
+
flash[type.to_sym] ||= []
|
37
|
+
flash[type.to_sym] << text
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
# Filters
|
43
|
+
|
44
|
+
# Conditional check to see ensure a current user exists
|
45
|
+
#
|
46
|
+
# @return [Boolean]
|
47
|
+
# (see #current_user?)
|
48
|
+
def ensure_user
|
49
|
+
current_user? || deny_access('You must be logged in to perform this action.')
|
50
|
+
end
|
51
|
+
|
52
|
+
# Conditional check to see ensure there is no current user
|
53
|
+
#
|
54
|
+
# @return [Boolean]
|
55
|
+
# (see #current_user?)
|
56
|
+
def ensure_no_user
|
57
|
+
!current_user? || redirect_back_or_default
|
58
|
+
end
|
59
|
+
|
60
|
+
# Utils
|
61
|
+
|
62
|
+
# Store the location URL in the session for later use.
|
63
|
+
#
|
64
|
+
# @return [Hash] the modified session object
|
65
|
+
def store_location
|
66
|
+
session[:return_to] = request.fullpath
|
67
|
+
end
|
68
|
+
|
69
|
+
# Stores the URL for the current requested action, then redirects to
|
70
|
+
# the login page.
|
71
|
+
#
|
72
|
+
# @param [String] optional flash message to pass to the user
|
73
|
+
# @note This method sets the redirect path, but does not return false.
|
74
|
+
# Meaning you can perform actions after this method is invoked.
|
75
|
+
def deny_access(message=nil)
|
76
|
+
store_location
|
77
|
+
flash_message :notice, message if message.present?
|
78
|
+
redirect_to login_path
|
79
|
+
end
|
80
|
+
|
81
|
+
# Conditional redirect to handle an empty return_to path. If return_to
|
82
|
+
# is empty, the request is redirected to the default path
|
83
|
+
#
|
84
|
+
# @param [String] path to use as the default redirect location
|
85
|
+
# @return [Hash] the modified session hash
|
86
|
+
def redirect_back_or_default(default=nil)
|
87
|
+
default = self.default_route
|
88
|
+
redirect_to(session[:return_to] || default)
|
89
|
+
session[:return_to] = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
# Fetch the User model associated with the current session.
|
93
|
+
#
|
94
|
+
# @return [User]
|
95
|
+
# (see #current_user=)
|
96
|
+
def current_user
|
97
|
+
@current_user ||= if session[:user_id]
|
98
|
+
User.find(session[:user_id])
|
99
|
+
elsif cookies[:remember_token]
|
100
|
+
User.find_by_remember_token(cookies[:remember_token])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Assign the User model associated with the current session.
|
105
|
+
#
|
106
|
+
# @return [User]
|
107
|
+
# (see #current_user)
|
108
|
+
def current_user=(user)
|
109
|
+
user.tap do |user|
|
110
|
+
user.remember_me!
|
111
|
+
session[:user_id] = user.id
|
112
|
+
cookies[:remember_token] = user.remember_token
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Accessor method for checking if a user is currently signed in
|
117
|
+
#
|
118
|
+
# @return [Boolean]
|
119
|
+
# (see #current_user)
|
120
|
+
def user_signed_in?
|
121
|
+
!!current_user
|
122
|
+
end
|
123
|
+
alias_method :current_user?, :user_signed_in?
|
124
|
+
|
125
|
+
# Destroy the current user session, effectively logging them out upon
|
126
|
+
# the next request.
|
127
|
+
#
|
128
|
+
# @return [Hash] the modified session object
|
129
|
+
def logout!
|
130
|
+
session[:user_id] = nil
|
131
|
+
session[:return_to] = nil
|
132
|
+
@current_user = nil
|
133
|
+
cookies.delete(:remember_token)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/socialite/engine.rb
CHANGED
@@ -22,11 +22,11 @@ module Socialite
|
|
22
22
|
end
|
23
23
|
|
24
24
|
ActiveSupport.on_load(:action_controller) do
|
25
|
-
include Socialite::
|
25
|
+
include Socialite::Controllers::Helpers
|
26
26
|
end
|
27
27
|
|
28
28
|
ActiveSupport.on_load(:action_view) do
|
29
|
-
include Socialite::
|
29
|
+
include Socialite::Helpers::Authentication
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Socialite
|
2
|
+
module Helpers
|
3
|
+
module Authentication
|
4
|
+
def identity_request_path(options={})
|
5
|
+
[Socialite.mount_prefix, 'auth', options[:service]].join('/')
|
6
|
+
end
|
7
|
+
|
8
|
+
def twitter_login_button
|
9
|
+
content_tag(:a, content_tag(:span, 'Sign in with Twitter'), :class => 'socialite_button twitter', :href => identity_request_path(:service => 'twitter'), :rel => 'external')
|
10
|
+
end
|
11
|
+
|
12
|
+
def facebook_login_button
|
13
|
+
content_tag(:a, content_tag(:span, 'Sign in with Facebook'), :class => 'socialite_button facebook', :href => identity_request_path(:service => 'facebook'), :rel => 'external')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Socialite
|
2
|
+
module Models
|
3
|
+
module FacebookIdentity
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Socialite::ApiWrappers::Facebook
|
8
|
+
|
9
|
+
has_one :identity, :as => :api
|
10
|
+
delegate :access_token, :access_token_secret, :to => :identity, :allow_nil => true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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
|
data/lib/socialite/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-28 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70251593638160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70251593638160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sass-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70251593636940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70251593636940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: simple_form
|
38
|
-
requirement: &
|
38
|
+
requirement: &70251593635780 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.5.2
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70251593635780
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: haml
|
49
|
-
requirement: &
|
49
|
+
requirement: &70251593634700 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.1.2
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70251593634700
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: oa-core
|
60
|
-
requirement: &
|
60
|
+
requirement: &70251593633480 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.3.0.rc3
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70251593633480
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: oa-oauth
|
71
|
-
requirement: &
|
71
|
+
requirement: &70251593632660 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.3.0.rc3
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70251593632660
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: koala
|
82
|
-
requirement: &
|
82
|
+
requirement: &70251593631600 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.2.0beta4
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70251593631600
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: grackle
|
93
|
-
requirement: &
|
93
|
+
requirement: &70251593630500 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.1.10
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70251593630500
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: sqlite3
|
104
|
-
requirement: &
|
104
|
+
requirement: &70251593629640 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70251593629640
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: yard
|
115
|
-
requirement: &
|
115
|
+
requirement: &70251593628640 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70251593628640
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rdiscount
|
126
|
-
requirement: &
|
126
|
+
requirement: &70251593627640 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70251593627640
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: rspec-rails
|
137
|
-
requirement: &
|
137
|
+
requirement: &70251593626460 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ~>
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 2.6.1
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70251593626460
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: factory_girl
|
148
|
-
requirement: &
|
148
|
+
requirement: &70251593625280 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ~>
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: 2.1.0
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70251593625280
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: shoulda-matchers
|
159
|
-
requirement: &
|
159
|
+
requirement: &70251593624400 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,10 +164,10 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70251593624400
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: cucumber-rails
|
170
|
-
requirement: &
|
170
|
+
requirement: &70251593623300 !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
173
|
- - ~>
|
@@ -175,10 +175,10 @@ dependencies:
|
|
175
175
|
version: 1.0.6
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
|
-
version_requirements: *
|
178
|
+
version_requirements: *70251593623300
|
179
179
|
- !ruby/object:Gem::Dependency
|
180
180
|
name: database_cleaner
|
181
|
-
requirement: &
|
181
|
+
requirement: &70251593622420 !ruby/object:Gem::Requirement
|
182
182
|
none: false
|
183
183
|
requirements:
|
184
184
|
- - ! '>='
|
@@ -186,10 +186,10 @@ dependencies:
|
|
186
186
|
version: 0.6.7
|
187
187
|
type: :development
|
188
188
|
prerelease: false
|
189
|
-
version_requirements: *
|
189
|
+
version_requirements: *70251593622420
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
191
|
name: selenium-webdriver
|
192
|
-
requirement: &
|
192
|
+
requirement: &70251593621060 !ruby/object:Gem::Requirement
|
193
193
|
none: false
|
194
194
|
requirements:
|
195
195
|
- - ! '>='
|
@@ -197,10 +197,10 @@ dependencies:
|
|
197
197
|
version: 2.4.0
|
198
198
|
type: :development
|
199
199
|
prerelease: false
|
200
|
-
version_requirements: *
|
200
|
+
version_requirements: *70251593621060
|
201
201
|
- !ruby/object:Gem::Dependency
|
202
202
|
name: launchy
|
203
|
-
requirement: &
|
203
|
+
requirement: &70251593619900 !ruby/object:Gem::Requirement
|
204
204
|
none: false
|
205
205
|
requirements:
|
206
206
|
- - ~>
|
@@ -208,7 +208,7 @@ dependencies:
|
|
208
208
|
version: 2.0.5
|
209
209
|
type: :development
|
210
210
|
prerelease: false
|
211
|
-
version_requirements: *
|
211
|
+
version_requirements: *70251593619900
|
212
212
|
description: Rails engine supporting multiple auth providers per user.
|
213
213
|
email: justin.smestad@gmail.com
|
214
214
|
executables: []
|
@@ -232,7 +232,6 @@ files:
|
|
232
232
|
- app/controllers/socialite/identities_controller.rb
|
233
233
|
- app/controllers/socialite/session_controller.rb
|
234
234
|
- app/controllers/socialite/user_controller.rb
|
235
|
-
- app/helpers/socialite/authentication_helper.rb
|
236
235
|
- app/models/socialite/facebook_identity.rb
|
237
236
|
- app/models/socialite/identity.rb
|
238
237
|
- app/models/socialite/user.rb
|
@@ -262,12 +261,17 @@ files:
|
|
262
261
|
- features/support/omniauth.rb
|
263
262
|
- features/support/paths.rb
|
264
263
|
- features/support/selectors.rb
|
264
|
+
- lib/generators/socialite/install_generator.rb
|
265
|
+
- lib/generators/socialite/templates/socialite.rb
|
265
266
|
- lib/socialite.rb
|
266
267
|
- lib/socialite/api_wrappers/facebook.rb
|
267
268
|
- lib/socialite/api_wrappers/twitter.rb
|
268
|
-
- lib/socialite/
|
269
|
-
- lib/socialite/controller_support.rb
|
269
|
+
- lib/socialite/controllers/helpers.rb
|
270
270
|
- lib/socialite/engine.rb
|
271
|
+
- lib/socialite/helpers/authentication.rb
|
272
|
+
- lib/socialite/models/facebook_identity.rb
|
273
|
+
- lib/socialite/models/identity.rb
|
274
|
+
- lib/socialite/models/user.rb
|
271
275
|
- lib/socialite/service_config.rb
|
272
276
|
- lib/socialite/version.rb
|
273
277
|
- lib/tasks/.gitkeep
|
@@ -334,7 +338,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
334
338
|
version: '0'
|
335
339
|
segments:
|
336
340
|
- 0
|
337
|
-
hash:
|
341
|
+
hash: 3505192399675819770
|
338
342
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
339
343
|
none: false
|
340
344
|
requirements:
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Socialite
|
2
|
-
module AuthenticationHelper
|
3
|
-
def identity_request_path(options={})
|
4
|
-
[Socialite.mount_prefix, 'auth', options[:service]].join('/')
|
5
|
-
end
|
6
|
-
|
7
|
-
def twitter_login_button
|
8
|
-
content_tag(:a, content_tag(:span, 'Sign in with Twitter'), :class => 'socialite_button twitter', :href => identity_request_path(:service => 'twitter'), :rel => 'external')
|
9
|
-
end
|
10
|
-
|
11
|
-
def facebook_login_button
|
12
|
-
content_tag(:a, content_tag(:span, 'Sign in with Facebook'), :class => 'socialite_button facebook', :href => identity_request_path(:service => 'facebook'), :rel => 'external')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
module Socialite
|
2
|
-
module BaseIdentity
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
belongs_to :user
|
7
|
-
serialize :auth_hash
|
8
|
-
|
9
|
-
# Ensure that before validation happens that the provider
|
10
|
-
# database column matches what is inside of the auth_hash
|
11
|
-
# dataset.
|
12
|
-
before_validation do |identity|
|
13
|
-
if identity.auth_hash.present?
|
14
|
-
identity.provider = identity.auth_hash.delete('provider') if identity.provider.blank?
|
15
|
-
identity.unique_id = identity.auth_hash.delete('uid') if identity.unique_id.blank?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Ensure each user has only a single identity per provider type
|
20
|
-
validates :provider,
|
21
|
-
:uniqueness => {:scope => :user_id, :case_sensitive => false},
|
22
|
-
:presence => true
|
23
|
-
|
24
|
-
# Ensure an identity is never reused by another account
|
25
|
-
validates :unique_id,
|
26
|
-
:uniqueness => {:scope => :provider},
|
27
|
-
:presence => true
|
28
|
-
|
29
|
-
# Ensure an associated user exists before creating the identity
|
30
|
-
# validates_associated :user
|
31
|
-
end
|
32
|
-
|
33
|
-
module ClassMethods
|
34
|
-
# Finder method that finds the matching Provider and Unique ID or
|
35
|
-
# initializes a new, unsaved, object.
|
36
|
-
#
|
37
|
-
# @params [Hash] the OAuth authentication hash
|
38
|
-
# @returns [Identity]
|
39
|
-
def find_or_initialize_by_oauth(auth_hash)
|
40
|
-
identity = where(:provider => auth_hash['provider'], :unique_id => auth_hash['uid']).first || new
|
41
|
-
identity.auth_hash = auth_hash
|
42
|
-
identity
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module InstanceMethods
|
47
|
-
# Method that maps uid to unique_id which is what we store it as.
|
48
|
-
#
|
49
|
-
# @returns [String]
|
50
|
-
# def uid=(new_uid)
|
51
|
-
# self.unique_id = new_uid
|
52
|
-
# end
|
53
|
-
|
54
|
-
# Convenience method for accessing the OAuth access token
|
55
|
-
#
|
56
|
-
# @returns [String] OAuth access token
|
57
|
-
# (see #credentials)
|
58
|
-
def access_token
|
59
|
-
credentials['token']
|
60
|
-
end
|
61
|
-
|
62
|
-
# Convenience method for accessing the OAuth access token secret
|
63
|
-
#
|
64
|
-
# @returns [String] OAuth access token secret
|
65
|
-
# (see #credentials)
|
66
|
-
def access_token_secret
|
67
|
-
credentials['secret']
|
68
|
-
end
|
69
|
-
|
70
|
-
# Convenience method for accessing the OAuth credentials sub-hash
|
71
|
-
#
|
72
|
-
# @returns [Hash] OAuth credentials sub-hash
|
73
|
-
# (see #access_token)
|
74
|
-
# (see #access_token_secret)
|
75
|
-
def credentials
|
76
|
-
auth_hash['credentials']
|
77
|
-
end
|
78
|
-
|
79
|
-
# Convenience method for accessing the nickname, which is typically
|
80
|
-
# set to the login name used for that provider.
|
81
|
-
#
|
82
|
-
# @returns [String] user nickname for the provider identity
|
83
|
-
def nickname
|
84
|
-
user_info['nickname']
|
85
|
-
end
|
86
|
-
|
87
|
-
# Convenience method for accessing the user information from the
|
88
|
-
# OAuth provider.
|
89
|
-
#
|
90
|
-
# @returns [Hash] the user information sub-hash
|
91
|
-
def user_info
|
92
|
-
auth_hash['user_info']
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
module Socialite
|
2
|
-
module ControllerSupport
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
helper_method :current_user, :user_signed_in?, :current_user?, :default_route
|
7
|
-
end
|
8
|
-
|
9
|
-
module InstanceMethods
|
10
|
-
|
11
|
-
# Set default route for redirect
|
12
|
-
#
|
13
|
-
# @param [String] the path for default redirects
|
14
|
-
# @return [String] the default path for redirect
|
15
|
-
# (see #default_route)
|
16
|
-
def default_route=(route)
|
17
|
-
@default_route = route
|
18
|
-
end
|
19
|
-
|
20
|
-
# Get default route for redirect
|
21
|
-
#
|
22
|
-
# @return [String] the default path for redirect
|
23
|
-
# (see #default_route=)
|
24
|
-
def default_route
|
25
|
-
@default_route ||= '/'
|
26
|
-
end
|
27
|
-
|
28
|
-
# Helper for supporting multiple flash messages per type
|
29
|
-
#
|
30
|
-
# @param [Symbol] the type of flash message. Common types are
|
31
|
-
# :success, :notice, :error
|
32
|
-
# @param [String] the message to attach to the flash type
|
33
|
-
# @return [Hash] all associated flash messages for this request
|
34
|
-
def flash_message(type, text)
|
35
|
-
flash[type.to_sym] ||= []
|
36
|
-
flash[type.to_sym] << text
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
# Filters
|
42
|
-
|
43
|
-
# Conditional check to see ensure a current user exists
|
44
|
-
#
|
45
|
-
# @return [Boolean]
|
46
|
-
# (see #current_user?)
|
47
|
-
def ensure_user
|
48
|
-
current_user? || deny_access('You must be logged in to perform this action.')
|
49
|
-
end
|
50
|
-
|
51
|
-
# Conditional check to see ensure there is no current user
|
52
|
-
#
|
53
|
-
# @return [Boolean]
|
54
|
-
# (see #current_user?)
|
55
|
-
def ensure_no_user
|
56
|
-
!current_user? || redirect_back_or_default
|
57
|
-
end
|
58
|
-
|
59
|
-
# Utils
|
60
|
-
|
61
|
-
# Store the location URL in the session for later use.
|
62
|
-
#
|
63
|
-
# @return [Hash] the modified session object
|
64
|
-
def store_location
|
65
|
-
session[:return_to] = request.fullpath
|
66
|
-
end
|
67
|
-
|
68
|
-
# Stores the URL for the current requested action, then redirects to
|
69
|
-
# the login page.
|
70
|
-
#
|
71
|
-
# @param [String] optional flash message to pass to the user
|
72
|
-
# @note This method sets the redirect path, but does not return false.
|
73
|
-
# Meaning you can perform actions after this method is invoked.
|
74
|
-
def deny_access(message=nil)
|
75
|
-
store_location
|
76
|
-
flash_message :notice, message if message.present?
|
77
|
-
redirect_to login_path
|
78
|
-
end
|
79
|
-
|
80
|
-
# Conditional redirect to handle an empty return_to path. If return_to
|
81
|
-
# is empty, the request is redirected to the default path
|
82
|
-
#
|
83
|
-
# @param [String] path to use as the default redirect location
|
84
|
-
# @return [Hash] the modified session hash
|
85
|
-
def redirect_back_or_default(default=nil)
|
86
|
-
default = self.default_route
|
87
|
-
redirect_to(session[:return_to] || default)
|
88
|
-
session[:return_to] = nil
|
89
|
-
end
|
90
|
-
|
91
|
-
# Fetch the User model associated with the current session.
|
92
|
-
#
|
93
|
-
# @return [User]
|
94
|
-
# (see #current_user=)
|
95
|
-
def current_user
|
96
|
-
@current_user ||= if session[:user_id]
|
97
|
-
User.find(session[:user_id])
|
98
|
-
elsif cookies[:remember_token]
|
99
|
-
User.find_by_remember_token(cookies[:remember_token])
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Assign the User model associated with the current session.
|
104
|
-
#
|
105
|
-
# @return [User]
|
106
|
-
# (see #current_user)
|
107
|
-
def current_user=(user)
|
108
|
-
user.tap do |user|
|
109
|
-
user.remember_me!
|
110
|
-
session[:user_id] = user.id
|
111
|
-
cookies[:remember_token] = user.remember_token
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Accessor method for checking if a user is currently signed in
|
116
|
-
#
|
117
|
-
# @return [Boolean]
|
118
|
-
# (see #current_user)
|
119
|
-
def user_signed_in?
|
120
|
-
!!current_user
|
121
|
-
end
|
122
|
-
alias_method :current_user?, :user_signed_in?
|
123
|
-
|
124
|
-
# Destroy the current user session, effectively logging them out upon
|
125
|
-
# the next request.
|
126
|
-
#
|
127
|
-
# @return [Hash] the modified session object
|
128
|
-
def logout!
|
129
|
-
session[:user_id] = nil
|
130
|
-
session[:return_to] = nil
|
131
|
-
@current_user = nil
|
132
|
-
cookies.delete(:remember_token)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|