robdimarco_authlogic_oauth2 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +12 -0
- data/README.rdoc +120 -0
- data/Rakefile +14 -0
- data/init.rb +1 -0
- data/lib/authlogic_oauth2/acts_as_authentic.rb +129 -0
- data/lib/authlogic_oauth2/helper.rb +21 -0
- data/lib/authlogic_oauth2/oauth2_process.rb +75 -0
- data/lib/authlogic_oauth2/session.rb +121 -0
- data/lib/authlogic_oauth2/version.rb +51 -0
- data/lib/authlogic_oauth2.rb +23 -0
- data/lib/oauth2_callback_filter.rb +12 -0
- data/rails/init.rb +1 -0
- data/robdimarco_authlogic_oauth2.gemspec +36 -0
- metadata +119 -0
data/Manifest
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Manifest
|
2
|
+
README.rdoc
|
3
|
+
Rakefile
|
4
|
+
init.rb
|
5
|
+
lib/authlogic_oauth2.rb
|
6
|
+
lib/authlogic_oauth2/acts_as_authentic.rb
|
7
|
+
lib/authlogic_oauth2/helper.rb
|
8
|
+
lib/authlogic_oauth2/oauth2_process.rb
|
9
|
+
lib/authlogic_oauth2/session.rb
|
10
|
+
lib/authlogic_oauth2/version.rb
|
11
|
+
lib/oauth2_callback_filter.rb
|
12
|
+
rails/init.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
= Authlogic OAuth2
|
2
|
+
|
3
|
+
Disclaimer: This plugin CANNOT be used alongside other Authlogic extensions like authlogic_oauth and authlogic_openid due to an unfortunate bug caused by all these plugins overriding the ActiveRecord save method to avoid a DoubleRenderError.
|
4
|
+
|
5
|
+
== Install and use
|
6
|
+
|
7
|
+
=== 1. Install the authlogic and oauth2 gems
|
8
|
+
|
9
|
+
config.gem "authlogic"
|
10
|
+
config.gem "oauth2"
|
11
|
+
config.gem "authlogic_oauth2"
|
12
|
+
|
13
|
+
$ sudo rake gems:install
|
14
|
+
|
15
|
+
For older version of Rails, you can install authlogic_oauth2 as a plugin:
|
16
|
+
|
17
|
+
$ script/plugin install git://github.com/andyhite/authlogic_oauth2.git
|
18
|
+
|
19
|
+
=== 2. Set up and configure authlogic
|
20
|
+
|
21
|
+
For information about how to set up and configure authlogic, please consult the authlogic README (http://github.com/binarylogic/authlogic)
|
22
|
+
|
23
|
+
=== 3. Add the necessary fields to your authlogic users table
|
24
|
+
|
25
|
+
class AddOauth2FieldsToUser < ActiveRecord::Migration
|
26
|
+
def self.up
|
27
|
+
add_column :users, :oauth2_token, :string
|
28
|
+
add_index :users, :oauth2_token
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.down
|
32
|
+
remove_column :users, :oauth2_token
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
IMPORTANT: make sure that you allow null values for crypted_password and password_salt if they aren't required for OAuth2 users.
|
37
|
+
|
38
|
+
=== 4. Configure your OAuth2 client in the UserSession model
|
39
|
+
|
40
|
+
The oauth2_client_id, oauth2_client_secret and oauth2_site configuration values must be specified so we can initialize the connection with your OAuth2 provider. The oauth2_scope value is optional, and is used to request extended permissions from your provider.
|
41
|
+
|
42
|
+
Here's an example for Facebook:
|
43
|
+
|
44
|
+
class UserSession < Authlogic::Session::Base
|
45
|
+
oauth2_client_id "APPLICATION_ID"
|
46
|
+
oauth2_client_secret "APPLICATION_SECRET"
|
47
|
+
oauth2_site "https://graph.facebook.com"
|
48
|
+
oauth2_scope "offline_access,email,user_birthday"
|
49
|
+
end
|
50
|
+
|
51
|
+
It's important to note here that if you don't request offline_access permissions from your OAuth2 provider the access token will expire either at a specific time or upon logout from the provider itself. Some providers allow refresh tokens to be issued, but some (Facebook, for example) does not. Refresh token handling hasn't been implemented in authlogic_oauth2 yet, so make sure you request offline_access.
|
52
|
+
|
53
|
+
=== 5. Make sure you save your objects properly
|
54
|
+
|
55
|
+
We need to redirect the user to their oauth2 provider so they can authenticate and then pick things back up when they're returned, so any calls to User#save or UserSession#save need to be updated to the following format:
|
56
|
+
|
57
|
+
@user.save do |result|
|
58
|
+
if result
|
59
|
+
# Do something
|
60
|
+
else
|
61
|
+
# Do something else
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
and
|
66
|
+
|
67
|
+
@user_session.save do |result|
|
68
|
+
if result
|
69
|
+
# Do something
|
70
|
+
else
|
71
|
+
# Do something else
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
=== 6. Add the login and register buttons to their respective forms
|
76
|
+
|
77
|
+
In file app/views/user_sessions/new.html.erb:
|
78
|
+
|
79
|
+
<% form_for @user_session, :url => user_session_path do |f| %>
|
80
|
+
# All your other form stuff goes here, if you need it.
|
81
|
+
<%= oauth2_login_button :value => "Login using Facebook" %>
|
82
|
+
<% end %>
|
83
|
+
|
84
|
+
In file app/views/users/new.html.erb:
|
85
|
+
|
86
|
+
<% form_for @user, :url => account_path do |f| %>
|
87
|
+
# All your other form stuff goes here, if you need it.
|
88
|
+
<%= oauth2_register_button :value => "Register using Facebook" %>
|
89
|
+
<% end %>
|
90
|
+
|
91
|
+
=== 7. There is no step 7
|
92
|
+
|
93
|
+
If you followed these steps correctly, then you should be able to register and login using OAuth2.
|
94
|
+
|
95
|
+
== Accessing API endpoints
|
96
|
+
|
97
|
+
You can easily access any API endpoints that are exposed to an OAuth2 user by utilizing the oauth2 gem's "get" method on current_user#oauth2_access. For instance, you can access information about the currently logged in user's Facebook profile by doing the following:
|
98
|
+
|
99
|
+
current_user.oauth2_access.get('/me')
|
100
|
+
|
101
|
+
This will return a JSON string representing the user's profile information.
|
102
|
+
|
103
|
+
You can pre-populate user information by using the after_oauth2_authentication hook in your user model:
|
104
|
+
|
105
|
+
require 'json'
|
106
|
+
|
107
|
+
class User < ActiveRecord::Base
|
108
|
+
...
|
109
|
+
|
110
|
+
def after_oauth2_authentication
|
111
|
+
json = oauth2_access.get('/me')
|
112
|
+
|
113
|
+
if user_data = JSON.parse(json)
|
114
|
+
self.name = user_data['name']
|
115
|
+
self.facebook_uid = user_data['id']
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
You can get more information about the Facebook Graph API on the following website: http://developers.facebook.com/docs/api
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
require File.dirname(__FILE__) + "/lib/authlogic_oauth2/version"
|
5
|
+
|
6
|
+
Echoe.new('robdimarco_authlogic_oauth2', AuthlogicOauth2::Version::STRING) do |p|
|
7
|
+
p.description = "Authlogic OAuth2 is an extension of the Authlogic library to add OAuth2 support. OAuth2 can be used to allow users to login with their Facebook credentials."
|
8
|
+
p.url = "http://github.com/robdimarco/authlogic_oauth2"
|
9
|
+
p.author = "Andrew Hite"
|
10
|
+
p.email = "andrew@andrew-hite.com"
|
11
|
+
p.runtime_dependencies = ['authlogic', 'oauth2']
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init.rb"
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'authlogic'
|
2
|
+
|
3
|
+
module AuthlogicOauth2
|
4
|
+
module ActsAsAuthentic
|
5
|
+
def self.included(klass)
|
6
|
+
klass.class_eval do
|
7
|
+
extend Config
|
8
|
+
add_acts_as_authentic_module(Methods, :prepend)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Config
|
13
|
+
# The name of the oauth2 token field in the database.
|
14
|
+
#
|
15
|
+
# * <tt>Default:</tt> :oauth2_token
|
16
|
+
# * <tt>Accepts:</tt> Symbol
|
17
|
+
def oauth2_token_field(value = nil)
|
18
|
+
rw_config(:oauth2_token_field, value, :oauth2_token)
|
19
|
+
end
|
20
|
+
alias_method :oauth2_token_field=, :oauth2_token_field
|
21
|
+
end
|
22
|
+
|
23
|
+
module Methods
|
24
|
+
include Oauth2Process
|
25
|
+
|
26
|
+
# Set up some simple validations
|
27
|
+
def self.included(klass)
|
28
|
+
klass.class_eval do
|
29
|
+
alias_method "#{oauth2_token_field.to_s}=".to_sym, :oauth2_token=
|
30
|
+
end
|
31
|
+
|
32
|
+
return if !klass.column_names.include?(klass.oauth2_token_field.to_s)
|
33
|
+
|
34
|
+
klass.class_eval do
|
35
|
+
validate :validate_by_oauth2, :if => :authenticating_with_oauth2?
|
36
|
+
|
37
|
+
validates_uniqueness_of klass.oauth2_token_field, :scope => validations_scope, :if => :using_oauth2?
|
38
|
+
|
39
|
+
validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_oauth2?)
|
40
|
+
validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_oauth2?)
|
41
|
+
validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_oauth2?)
|
42
|
+
validates_length_of_login_field_options validates_length_of_login_field_options.merge(:if => :validate_password_with_oauth2?)
|
43
|
+
validates_format_of_login_field_options validates_format_of_login_field_options.merge(:if => :validate_password_with_oauth2?)
|
44
|
+
|
45
|
+
validates_format_of_email_field_options(validates_format_of_email_field_options.merge(:unless=>:using_oauth2?))
|
46
|
+
validates_length_of_email_field_options(validates_length_of_email_field_options.merge(:unless=>:using_oauth2?))
|
47
|
+
validates_uniqueness_of_email_field_options(validates_uniqueness_of_email_field_options.merge(:unless=>:using_oauth2?))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def save(perform_validation = true, &block)
|
52
|
+
if perform_validation && block_given? && redirecting_to_oauth2_server?
|
53
|
+
# Save attributes so they aren't lost during the authentication with the oauth2 server
|
54
|
+
session_class.controller.session[:authlogic_oauth2_attributes] = attributes.reject!{|k, v| v.blank?}
|
55
|
+
redirect_to_oauth2
|
56
|
+
return false
|
57
|
+
end
|
58
|
+
|
59
|
+
result = super
|
60
|
+
|
61
|
+
# yield(result) if block_given?
|
62
|
+
if block_given?
|
63
|
+
unless result
|
64
|
+
if oauth2_token && (record = self.class.where(oauth2_token_field => oauth2_token).first)
|
65
|
+
session_class.create(record)
|
66
|
+
result = true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
yield(result)
|
71
|
+
end
|
72
|
+
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
# Accessors for oauth2 fields
|
77
|
+
def oauth2_token
|
78
|
+
read_attribute(oauth2_token_field)
|
79
|
+
end
|
80
|
+
|
81
|
+
def oauth2_token=(value)
|
82
|
+
write_attribute(oauth2_token_field, value.blank? ? nil : value)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Provides access to an API exposed on the access_token object
|
86
|
+
def oauth2_access
|
87
|
+
access_token
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def authenticating_with_oauth2?
|
93
|
+
# Controller isn't available in all contexts (e.g. irb)
|
94
|
+
return false unless session_class.controller
|
95
|
+
|
96
|
+
# Initial request when user presses one of the button helpers
|
97
|
+
(session_class.controller.params && !session_class.controller.params[:register_with_oauth2].blank?) ||
|
98
|
+
# When the oauth2 provider responds and we made the initial request
|
99
|
+
(oauth2_response && session_class.controller.session && session_class.controller.session[:oauth2_request_class] == self.class.name)
|
100
|
+
end
|
101
|
+
|
102
|
+
def authenticate_with_oauth2
|
103
|
+
# Restore any attributes which were saved before redirecting to the oauth2 server
|
104
|
+
self.attributes = session_class.controller.session.delete(:authlogic_oauth2_attributes)
|
105
|
+
self.oauth2_token = generate_oauth2_access_token.token
|
106
|
+
|
107
|
+
# Execute callback if it's defined in the user model
|
108
|
+
self.after_oauth2_authentication if self.respond_to?(:after_oauth2_authentication)
|
109
|
+
end
|
110
|
+
|
111
|
+
def access_token
|
112
|
+
OAuth2::AccessToken.new(oauth2_client, read_attribute(oauth2_token_field))
|
113
|
+
end
|
114
|
+
|
115
|
+
def using_oauth2?
|
116
|
+
respond_to?(oauth2_token_field) && !oauth2_token.blank?
|
117
|
+
end
|
118
|
+
|
119
|
+
def validate_password_with_oauth2?
|
120
|
+
!using_oauth2? && require_password?
|
121
|
+
end
|
122
|
+
|
123
|
+
# Convenience methods for accessing configuration values
|
124
|
+
def oauth2_token_field
|
125
|
+
self.class.oauth2_token_field
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AuthlogicOauth2
|
2
|
+
module Helper
|
3
|
+
def oauth2_register_button(options = {})
|
4
|
+
oauth2_button('register_with_oauth2', options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def oauth2_login_button(options = {})
|
8
|
+
oauth2_button('login_with_oauth2', options)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def oauth2_button(name, options = {})
|
13
|
+
id = options[:id] || 'user_submit'
|
14
|
+
if options[:type] == 'image'
|
15
|
+
image_submit_tag(options[:src], :value => options[:value], :name => name, :id => id, :class => options[:class])
|
16
|
+
else
|
17
|
+
submit_tag(options[:value], :name => name, :id => id, :class => options[:class])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module AuthlogicOauth2
|
2
|
+
module Oauth2Process
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def validate_by_oauth2
|
7
|
+
validate_email_field = false
|
8
|
+
|
9
|
+
if oauth2_response.blank?
|
10
|
+
redirect_to_oauth2
|
11
|
+
else
|
12
|
+
authenticate_with_oauth2
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def redirecting_to_oauth2_server?
|
17
|
+
authenticating_with_oauth2? && oauth2_response.blank?
|
18
|
+
end
|
19
|
+
|
20
|
+
def redirect_to_oauth2
|
21
|
+
authorize_url = oauth2_client.web_server.authorize_url(:redirect_uri => build_oauth2_callback_url, :scope => oauth2_scope)
|
22
|
+
|
23
|
+
# Store the class which is redirecting, so we can ensure other classes
|
24
|
+
# don't get confused and attempt to use the response
|
25
|
+
oauth2_controller.session[:oauth2_request_class] = self.class.name
|
26
|
+
|
27
|
+
# Tell our rack callback filter what method the current request is using
|
28
|
+
oauth2_controller.session[:oauth2_callback_method] = oauth2_controller.request.method
|
29
|
+
|
30
|
+
oauth2_controller.redirect_to authorize_url
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_oauth2_callback_url
|
34
|
+
oauth2_controller.url_for :controller => oauth2_controller.controller_name, :action => oauth2_controller.action_name
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_oauth2_access_token
|
38
|
+
oauth2_client.web_server.get_access_token(oauth2_controller.params[:code], :redirect_uri => build_oauth2_callback_url)
|
39
|
+
end
|
40
|
+
|
41
|
+
def oauth2_response
|
42
|
+
oauth2_controller.params && oauth2_controller.params[:code]
|
43
|
+
end
|
44
|
+
|
45
|
+
def oauth2_client
|
46
|
+
OAuth2::Client.new(oauth2_client_id, oauth2_client_secret, :site => oauth2_site)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Convenience method for accessing the session controller
|
50
|
+
def oauth2_controller
|
51
|
+
is_auth_session? ? controller : session_class.controller
|
52
|
+
end
|
53
|
+
|
54
|
+
# Convenience methods for accessing session configuration values
|
55
|
+
def oauth2_client_id
|
56
|
+
is_auth_session? ? self.class.oauth2_client_id : session_class.oauth2_client_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def oauth2_client_secret
|
60
|
+
is_auth_session? ? self.class.oauth2_client_secret : session_class.oauth2_client_secret
|
61
|
+
end
|
62
|
+
|
63
|
+
def oauth2_site
|
64
|
+
is_auth_session? ? self.class.oauth2_site : session_class.oauth2_site
|
65
|
+
end
|
66
|
+
|
67
|
+
def oauth2_scope
|
68
|
+
is_auth_session? ? self.class.oauth2_scope : session_class.oauth2_scope
|
69
|
+
end
|
70
|
+
|
71
|
+
def is_auth_session?
|
72
|
+
self.is_a?(Authlogic::Session::Base)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module AuthlogicOauth2
|
2
|
+
# This module is responsible for adding oauth2
|
3
|
+
# to the Authlogic::Session::Base class.
|
4
|
+
module Session
|
5
|
+
def self.included(klass)
|
6
|
+
klass.class_eval do
|
7
|
+
extend Config
|
8
|
+
include Methods
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Config
|
13
|
+
# * <tt>Default:</tt> :find_by_oauth2_token
|
14
|
+
# * <tt>Accepts:</tt> Symbol
|
15
|
+
def find_by_oauth2_method(value = nil)
|
16
|
+
rw_config(:find_by_oauth2_method, value, :find_by_oauth2_token)
|
17
|
+
end
|
18
|
+
alias_method :find_by_oauth2_method=, :find_by_oauth2_method
|
19
|
+
|
20
|
+
# * <tt>Default:</tt> ''
|
21
|
+
# * <tt>Accepts:</tt> String
|
22
|
+
def oauth2_client_id(value = nil)
|
23
|
+
rw_config(:oauth2_client_id, value, '')
|
24
|
+
end
|
25
|
+
alias_method :oauth2_client_id=, :oauth2_client_id
|
26
|
+
|
27
|
+
# * <tt>Default:</tt> ''
|
28
|
+
# * <tt>Accepts:</tt> String
|
29
|
+
def oauth2_client_secret(value = nil)
|
30
|
+
rw_config(:oauth2_client_secret, value, '')
|
31
|
+
end
|
32
|
+
alias_method :oauth2_client_secret=, :oauth2_client_secret
|
33
|
+
|
34
|
+
# * <tt>Default:</tt> ''
|
35
|
+
# * <tt>Accepts:</tt> String
|
36
|
+
def oauth2_site(value = nil)
|
37
|
+
rw_config(:oauth2_site, value, '')
|
38
|
+
end
|
39
|
+
alias_method :oauth2_site=, :oauth2_site
|
40
|
+
|
41
|
+
# * <tt>Default:</tt> ''
|
42
|
+
# * <tt>Accepts:</tt> String
|
43
|
+
def oauth2_scope(value = nil)
|
44
|
+
rw_config(:oauth2_scope, value, '')
|
45
|
+
end
|
46
|
+
alias_method :oauth2_scope=, :oauth2_scope
|
47
|
+
end
|
48
|
+
|
49
|
+
module Methods
|
50
|
+
include Oauth2Process
|
51
|
+
|
52
|
+
def self.included(klass)
|
53
|
+
klass.class_eval do
|
54
|
+
validate :validate_by_oauth2, :if => :authenticating_with_oauth2?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Hooks into credentials so that you can pass a user who has already has an oauth2 access token.
|
59
|
+
def credentials=(value)
|
60
|
+
super
|
61
|
+
values = value.is_a?(Array) ? value : [value]
|
62
|
+
hash = values.first.is_a?(Hash) ? values.first.with_indifferent_access : nil
|
63
|
+
self.record = hash[:priority_record] if !hash.nil? && hash.key?(:priority_record)
|
64
|
+
end
|
65
|
+
|
66
|
+
def record=(record)
|
67
|
+
@record = record
|
68
|
+
end
|
69
|
+
|
70
|
+
# Clears out the block if we are authenticating with oauth2,
|
71
|
+
# so that we can redirect without a DoubleRender error.
|
72
|
+
def save(&block)
|
73
|
+
block = nil if redirecting_to_oauth2_server?
|
74
|
+
super(&block)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def authenticating_with_oauth2?
|
80
|
+
return false if authenticating_with_unauthorized_record?
|
81
|
+
# Initial request when user presses one of the button helpers
|
82
|
+
(controller.params && !controller.params[:login_with_oauth2].blank?) ||
|
83
|
+
# When the oauth2 provider responds and we made the initial request
|
84
|
+
(oauth2_response && controller.session && controller.session[:oauth2_request_class] == self.class.name)
|
85
|
+
end
|
86
|
+
|
87
|
+
def authenticate_with_oauth2
|
88
|
+
if @record
|
89
|
+
self.attempted_record = record
|
90
|
+
else
|
91
|
+
self.attempted_record = search_for_record(find_by_oauth2_method, generate_oauth2_access_token.token)
|
92
|
+
end
|
93
|
+
|
94
|
+
if !attempted_record
|
95
|
+
errors.add(:base, "Could not find user in our database, have you registered with your Oauth2 account?")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Convenience methods for accessing configuration values
|
100
|
+
def find_by_oauth2_method
|
101
|
+
self.class.find_by_oauth2_method
|
102
|
+
end
|
103
|
+
|
104
|
+
def oauth2_client_id
|
105
|
+
self.class.oauth2_client_id
|
106
|
+
end
|
107
|
+
|
108
|
+
def oauth2_client_secret
|
109
|
+
self.class.oauth2_client_secret
|
110
|
+
end
|
111
|
+
|
112
|
+
def oauth2_site
|
113
|
+
self.class.oauth2_site
|
114
|
+
end
|
115
|
+
|
116
|
+
def oauth2_scope
|
117
|
+
self.class.oauth2_scope
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module AuthlogicOauth2
|
2
|
+
# A class for describing the current version of a library. The version
|
3
|
+
# consists of three parts: the +major+ number, the +minor+ number, and the
|
4
|
+
# +tiny+ (or +patch+) number.
|
5
|
+
class Version
|
6
|
+
include Comparable
|
7
|
+
|
8
|
+
# A convenience method for instantiating a new Version instance with the
|
9
|
+
# given +major+, +minor+, and +tiny+ components.
|
10
|
+
def self.[](major, minor, tiny)
|
11
|
+
new(major, minor, tiny)
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :major, :minor, :tiny
|
15
|
+
|
16
|
+
# Create a new Version object with the given components.
|
17
|
+
def initialize(major, minor, tiny)
|
18
|
+
@major, @minor, @tiny = major, minor, tiny
|
19
|
+
end
|
20
|
+
|
21
|
+
# Compare this version to the given +version+ object.
|
22
|
+
def <=>(version)
|
23
|
+
to_i <=> version.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
# Converts this version object to a string, where each of the three
|
27
|
+
# version components are joined by the '.' character. E.g., 2.0.0.
|
28
|
+
def to_s
|
29
|
+
@to_s ||= [@major, @minor, @tiny].join(".")
|
30
|
+
end
|
31
|
+
|
32
|
+
# Converts this version to a canonical integer that may be compared
|
33
|
+
# against other version objects.
|
34
|
+
def to_i
|
35
|
+
@to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_a
|
39
|
+
[@major, @minor, @tiny]
|
40
|
+
end
|
41
|
+
|
42
|
+
MAJOR = 1
|
43
|
+
MINOR = 1
|
44
|
+
TINY = 2
|
45
|
+
|
46
|
+
# The current version as a Version instance
|
47
|
+
CURRENT = new(MAJOR, MINOR, TINY)
|
48
|
+
# The current version as a String
|
49
|
+
STRING = CURRENT.to_s
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/authlogic_oauth2/version"
|
2
|
+
require File.dirname(__FILE__) + "/authlogic_oauth2/oauth2_process"
|
3
|
+
require File.dirname(__FILE__) + "/authlogic_oauth2/acts_as_authentic"
|
4
|
+
require File.dirname(__FILE__) + "/authlogic_oauth2/session"
|
5
|
+
require File.dirname(__FILE__) + "/authlogic_oauth2/helper"
|
6
|
+
require File.dirname(__FILE__) + "/oauth2_callback_filter"
|
7
|
+
|
8
|
+
ActiveRecord::Base.send(:include, AuthlogicOauth2::ActsAsAuthentic)
|
9
|
+
Authlogic::Session::Base.send(:include, AuthlogicOauth2::Session)
|
10
|
+
ActionController::Base.helper AuthlogicOauth2::Helper
|
11
|
+
|
12
|
+
# Throw callback rack app into the middleware stack
|
13
|
+
if defined?(ActionController::Metal)
|
14
|
+
module AuthlogicOAuth2
|
15
|
+
class Railtie < Rails::Railtie
|
16
|
+
initializer :load_oauth2_callback_filter do |app|
|
17
|
+
app.config.middleware.use(Oauth2CallbackFilter) # Rails >= 3.0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
else
|
22
|
+
ActionController::Dispatcher.middleware.use(Oauth2CallbackFilter) # Rails < 3.0
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Oauth2CallbackFilter
|
2
|
+
def initialize(app)
|
3
|
+
@app = app
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(env)
|
7
|
+
unless env["rack.session"][:oauth2_callback_method].blank?
|
8
|
+
env["REQUEST_METHOD"] = env["rack.session"].delete(:oauth2_callback_method).to_s.upcase
|
9
|
+
end
|
10
|
+
@app.call(env)
|
11
|
+
end
|
12
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "authlogic_oauth2"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{robdimarco_authlogic_oauth2}
|
5
|
+
s.version = "1.1.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Andrew Hite"]
|
9
|
+
s.date = %q{2010-12-09}
|
10
|
+
s.description = %q{Authlogic OAuth2 is an extension of the Authlogic library to add OAuth2 support. OAuth2 can be used to allow users to login with their Facebook credentials.}
|
11
|
+
s.email = %q{andrew@andrew-hite.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/authlogic_oauth2.rb", "lib/authlogic_oauth2/acts_as_authentic.rb", "lib/authlogic_oauth2/helper.rb", "lib/authlogic_oauth2/oauth2_process.rb", "lib/authlogic_oauth2/session.rb", "lib/authlogic_oauth2/version.rb", "lib/oauth2_callback_filter.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/authlogic_oauth2.rb", "lib/authlogic_oauth2/acts_as_authentic.rb", "lib/authlogic_oauth2/helper.rb", "lib/authlogic_oauth2/oauth2_process.rb", "lib/authlogic_oauth2/session.rb", "lib/authlogic_oauth2/version.rb", "lib/oauth2_callback_filter.rb", "rails/init.rb", "robdimarco_authlogic_oauth2.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/robdimarco/authlogic_oauth2}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Robdimarco_authlogic_oauth2", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{robdimarco_authlogic_oauth2}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Authlogic OAuth2 is an extension of the Authlogic library to add OAuth2 support. OAuth2 can be used to allow users to login with their Facebook credentials.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<authlogic>, [">= 0"])
|
27
|
+
s.add_runtime_dependency(%q<oauth2>, [">= 0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<authlogic>, [">= 0"])
|
30
|
+
s.add_dependency(%q<oauth2>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<authlogic>, [">= 0"])
|
34
|
+
s.add_dependency(%q<oauth2>, [">= 0"])
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robdimarco_authlogic_oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew Hite
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-09 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: authlogic
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: oauth2
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Authlogic OAuth2 is an extension of the Authlogic library to add OAuth2 support. OAuth2 can be used to allow users to login with their Facebook credentials.
|
50
|
+
email: andrew@andrew-hite.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
- lib/authlogic_oauth2.rb
|
58
|
+
- lib/authlogic_oauth2/acts_as_authentic.rb
|
59
|
+
- lib/authlogic_oauth2/helper.rb
|
60
|
+
- lib/authlogic_oauth2/oauth2_process.rb
|
61
|
+
- lib/authlogic_oauth2/session.rb
|
62
|
+
- lib/authlogic_oauth2/version.rb
|
63
|
+
- lib/oauth2_callback_filter.rb
|
64
|
+
files:
|
65
|
+
- Manifest
|
66
|
+
- README.rdoc
|
67
|
+
- Rakefile
|
68
|
+
- init.rb
|
69
|
+
- lib/authlogic_oauth2.rb
|
70
|
+
- lib/authlogic_oauth2/acts_as_authentic.rb
|
71
|
+
- lib/authlogic_oauth2/helper.rb
|
72
|
+
- lib/authlogic_oauth2/oauth2_process.rb
|
73
|
+
- lib/authlogic_oauth2/session.rb
|
74
|
+
- lib/authlogic_oauth2/version.rb
|
75
|
+
- lib/oauth2_callback_filter.rb
|
76
|
+
- rails/init.rb
|
77
|
+
- robdimarco_authlogic_oauth2.gemspec
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/robdimarco/authlogic_oauth2
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options:
|
84
|
+
- --line-numbers
|
85
|
+
- --inline-source
|
86
|
+
- --title
|
87
|
+
- Robdimarco_authlogic_oauth2
|
88
|
+
- --main
|
89
|
+
- README.rdoc
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 11
|
107
|
+
segments:
|
108
|
+
- 1
|
109
|
+
- 2
|
110
|
+
version: "1.2"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project: robdimarco_authlogic_oauth2
|
114
|
+
rubygems_version: 1.3.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Authlogic OAuth2 is an extension of the Authlogic library to add OAuth2 support. OAuth2 can be used to allow users to login with their Facebook credentials.
|
118
|
+
test_files: []
|
119
|
+
|