authlogic-connect 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +41 -4
- data/Rakefile +1 -1
- data/lib/{authlogic_connect.rb → authlogic-connect.rb} +37 -4
- data/lib/{oauth_callback_filter.rb → authlogic_connect/callback_filter.rb} +4 -1
- data/lib/authlogic_connect/oauth.rb +1 -0
- data/lib/authlogic_connect/oauth/process.rb +4 -4
- data/lib/authlogic_connect/oauth/session.rb +0 -3
- data/lib/authlogic_connect/oauth/tokens/oauth_token.rb +26 -7
- data/lib/authlogic_connect/oauth/variables.rb +2 -6
- data/lib/{token.rb → authlogic_connect/token.rb} +4 -0
- data/rails/init.rb +1 -17
- metadata +6 -6
data/README.markdown
CHANGED
@@ -81,8 +81,40 @@ Otherwise, add this migration
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
85
|
-
### 4.
|
84
|
+
|
85
|
+
### 4. Configure your keys
|
86
|
+
|
87
|
+
In `config/initializers/authlogic_connect_config.rb`, write your keys and secrets for each service you would like to support. You have to manually go to the websites and register with the service provider (list of those links coming soon, in token classes for now).
|
88
|
+
|
89
|
+
AuthlogicConnect.config = {
|
90
|
+
:services => {
|
91
|
+
:twitter => {
|
92
|
+
:key => "my_key",
|
93
|
+
:secret => "my_secret",
|
94
|
+
:label => "Twitter"
|
95
|
+
},
|
96
|
+
:facebook => {
|
97
|
+
:key => "my_key",
|
98
|
+
:secret => "my_secret",
|
99
|
+
:label => "Facebook"
|
100
|
+
},
|
101
|
+
:google => {
|
102
|
+
:key => "my_key",
|
103
|
+
:secret => "my_secret",
|
104
|
+
:label => "Google"
|
105
|
+
},
|
106
|
+
:yahoo => {
|
107
|
+
:key => "my_key",
|
108
|
+
:secret => "my_secret",
|
109
|
+
:label => "Yahoo"
|
110
|
+
},
|
111
|
+
:vimeo => {
|
112
|
+
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
### 5. Make sure you save your objects properly
|
86
118
|
|
87
119
|
Because of the redirects involved in Oauth and OpenID, you MUST pass a block to the `save` method in your UsersController and UserSessionsController:
|
88
120
|
|
@@ -99,7 +131,7 @@ You should save your `@user` objects this way as well, because you also want the
|
|
99
131
|
|
100
132
|
If we don't use the block, we will get a DoubleRender error. This lets us skip that entire block and send the user along their way without any problems.
|
101
133
|
|
102
|
-
###
|
134
|
+
### 6. Create Custom Tokens (if they don't already exist)
|
103
135
|
|
104
136
|
Here's an example of the FacebookToken for Oauth
|
105
137
|
|
@@ -142,4 +174,9 @@ That's it! The rest is taken care of for you.
|
|
142
174
|
|
143
175
|
## Tests
|
144
176
|
|
145
|
-
This has no tests! I had to build this in a weekend and am not fluent with Shoulda, which I'd like to use. One of these days when I can breathe.
|
177
|
+
This has no tests! I had to build this in a weekend and am not fluent with Shoulda, which I'd like to use. One of these days when I can breathe.
|
178
|
+
|
179
|
+
## TODO
|
180
|
+
|
181
|
+
- Change `register_with_oauth` and related to `register_method` and `login_method`: oauth, openid, traditional
|
182
|
+
- Build view helpers
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'rake/gempackagetask'
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = "authlogic-connect"
|
8
8
|
s.author = "Lance Pollard"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.2"
|
10
10
|
s.summary = "Authlogic Connect: Let your app use all of Oauth and OpenID"
|
11
11
|
s.homepage = "http://github.com/viatropos/authlogic-connect"
|
12
12
|
s.email = "lancejpollard@gmail.com"
|
@@ -3,6 +3,20 @@ require 'authlogic'
|
|
3
3
|
require 'oauth'
|
4
4
|
require 'oauth2'
|
5
5
|
|
6
|
+
# Throw callback rack app into the middleware stack
|
7
|
+
# TODO: Somehow do this for Rails 3?
|
8
|
+
# For now it is in the sample Rails 3 app
|
9
|
+
=begin
|
10
|
+
ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
|
11
|
+
ActionController::Dispatcher.middleware.each do |klass|
|
12
|
+
m.use klass
|
13
|
+
end
|
14
|
+
m.use AuthlogicConnect::CallbackFilter
|
15
|
+
end
|
16
|
+
=end
|
17
|
+
this = File.dirname(__FILE__)
|
18
|
+
library = "#{this}/authlogic_connect"
|
19
|
+
|
6
20
|
class Hash
|
7
21
|
def recursively_symbolize_keys!
|
8
22
|
self.symbolize_keys!
|
@@ -50,7 +64,15 @@ module AuthlogicConnect
|
|
50
64
|
def credentials(service)
|
51
65
|
key("services.#{service.to_s}")
|
52
66
|
end
|
53
|
-
|
67
|
+
|
68
|
+
def services
|
69
|
+
key("services")
|
70
|
+
end
|
71
|
+
|
72
|
+
def service_names
|
73
|
+
key("services").keys.collect(&:to_s)
|
74
|
+
end
|
75
|
+
|
54
76
|
def include?(service)
|
55
77
|
!credentials(service).nil?
|
56
78
|
end
|
@@ -66,6 +88,17 @@ module AuthlogicConnect
|
|
66
88
|
end
|
67
89
|
end
|
68
90
|
|
69
|
-
require
|
70
|
-
require
|
71
|
-
require
|
91
|
+
require "#{library}/callback_filter"
|
92
|
+
require "#{library}/token"
|
93
|
+
require "#{library}/openid"
|
94
|
+
require "#{library}/oauth"
|
95
|
+
require "#{library}/common"
|
96
|
+
|
97
|
+
custom_models = ["#{library}/token"]
|
98
|
+
custom_models += Dir["#{library}/oauth/tokens"]
|
99
|
+
custom_models +=Dir["#{library}/openid/tokens"]
|
100
|
+
|
101
|
+
custom_models.each do |path|
|
102
|
+
$LOAD_PATH << path
|
103
|
+
ActiveSupport::Dependencies.load_paths << path
|
104
|
+
end
|
@@ -1,9 +1,12 @@
|
|
1
|
-
class
|
1
|
+
class AuthlogicConnect::CallbackFilter
|
2
2
|
def initialize(app)
|
3
3
|
@app = app
|
4
4
|
end
|
5
5
|
|
6
6
|
def call(env)
|
7
|
+
if env["rack.session"].nil?
|
8
|
+
raise "Make sure you are setting the session in Rack too! Place this in config/application.rb"
|
9
|
+
end
|
7
10
|
unless env["rack.session"][:oauth_callback_method].blank?
|
8
11
|
env["REQUEST_METHOD"] = env["rack.session"].delete(:oauth_callback_method).to_s.upcase
|
9
12
|
end
|
@@ -2,7 +2,7 @@ module AuthlogicConnect::Oauth
|
|
2
2
|
module Process
|
3
3
|
|
4
4
|
private
|
5
|
-
include Variables
|
5
|
+
include AuthlogicConnect::Oauth::Variables
|
6
6
|
|
7
7
|
def validate_by_oauth
|
8
8
|
validate_email_field = false
|
@@ -26,7 +26,7 @@ module AuthlogicConnect::Oauth
|
|
26
26
|
save_auth_session(request)
|
27
27
|
auth_controller.redirect_to request.authorize_url
|
28
28
|
else
|
29
|
-
auth_controller.redirect_to
|
29
|
+
auth_controller.redirect_to oauth_consumer.web_server.authorize_url(
|
30
30
|
:redirect_uri => oauth_callback_url,
|
31
31
|
:scope => oauth_token.settings[:scope]
|
32
32
|
)
|
@@ -64,7 +64,7 @@ module AuthlogicConnect::Oauth
|
|
64
64
|
result = request_token.get_access_token(:oauth_verifier => auth_params[:oauth_verifier])
|
65
65
|
result = {:key => result.token, :secret => result.secret}
|
66
66
|
else
|
67
|
-
result =
|
67
|
+
result = oauth_consumer.web_server.get_access_token(oauth_key, :redirect_uri => oauth_callback_url)
|
68
68
|
result = {:key => result.token, :secret => oauth_key}
|
69
69
|
end
|
70
70
|
result
|
@@ -74,7 +74,7 @@ module AuthlogicConnect::Oauth
|
|
74
74
|
if oauth_version == 1.0
|
75
75
|
request_token.get_access_token(:oauth_verifier => auth_params[:oauth_verifier])
|
76
76
|
else
|
77
|
-
|
77
|
+
oauth_consumer.web_server.get_access_token(oauth_key, :redirect_uri => oauth_callback_url)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -3,7 +3,6 @@ module AuthlogicConnect::Oauth
|
|
3
3
|
# to the Authlogic::Session::Base class.
|
4
4
|
module Session
|
5
5
|
def self.included(base)
|
6
|
-
puts "included Oauth in Session"
|
7
6
|
base.class_eval do
|
8
7
|
include InstanceMethods
|
9
8
|
end
|
@@ -34,8 +33,6 @@ module AuthlogicConnect::Oauth
|
|
34
33
|
# Clears out the block if we are authenticating with oauth,
|
35
34
|
# so that we can redirect without a DoubleRender error.
|
36
35
|
def save_with_oauth(&block)
|
37
|
-
puts "SAVE SESSION WITH OAUTH"
|
38
|
-
puts "redirecting_to_oauth_server? #{redirecting_to_oauth_server?.to_s}"
|
39
36
|
block = nil if redirecting_to_oauth_server?
|
40
37
|
return block.nil?
|
41
38
|
end
|
@@ -1,9 +1,20 @@
|
|
1
1
|
class OauthToken < Token
|
2
|
-
|
3
2
|
# Main client for interfacing with remote service. Override this to use
|
4
3
|
# preexisting library eg. Twitter gem.
|
5
4
|
def client
|
6
|
-
@client
|
5
|
+
unless @client
|
6
|
+
if oauth_version == 1.0
|
7
|
+
@client = OAuth::AccessToken.new(self.consumer, self.key, self.secret)
|
8
|
+
else
|
9
|
+
@client = OAuth2::AccessToken.new(self.consumer, self.key)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
@client
|
14
|
+
end
|
15
|
+
|
16
|
+
def consumer
|
17
|
+
self.class.consumer
|
7
18
|
end
|
8
19
|
|
9
20
|
def simple_client
|
@@ -14,6 +25,10 @@ class OauthToken < Token
|
|
14
25
|
self.class.oauth_version
|
15
26
|
end
|
16
27
|
|
28
|
+
def get(path, options = {})
|
29
|
+
client.get(path)
|
30
|
+
end
|
31
|
+
|
17
32
|
class << self
|
18
33
|
|
19
34
|
def oauth_version
|
@@ -25,11 +40,15 @@ class OauthToken < Token
|
|
25
40
|
end
|
26
41
|
|
27
42
|
def consumer
|
28
|
-
@consumer
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
43
|
+
unless @consumer
|
44
|
+
if oauth_version == 1.0
|
45
|
+
@consumer = OAuth::Consumer.new(credentials[:key], credentials[:secret], settings.merge(credentials[:options] || {}))
|
46
|
+
else
|
47
|
+
@consumer = OAuth2::Client.new(credentials[:key], credentials[:secret], settings)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@consumer
|
33
52
|
end
|
34
53
|
|
35
54
|
def request_token(token, secret)
|
@@ -20,15 +20,11 @@ module AuthlogicConnect::Oauth
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def oauth_consumer
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def oauth_client
|
27
|
-
oauth_token.client
|
23
|
+
oauth_token.consumer
|
28
24
|
end
|
29
25
|
|
30
26
|
def oauth_token
|
31
27
|
AuthlogicConnect.token(oauth_provider)
|
32
28
|
end
|
33
29
|
end
|
34
|
-
end
|
30
|
+
end
|
data/rails/init.rb
CHANGED
@@ -1,17 +1 @@
|
|
1
|
-
require "
|
2
|
-
require "oauth_callback_filter"
|
3
|
-
|
4
|
-
# Throw callback rack app into the middleware stack
|
5
|
-
ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
|
6
|
-
ActionController::Dispatcher.middleware.each do |klass|
|
7
|
-
m.use klass
|
8
|
-
end
|
9
|
-
m.use OauthCallbackFilter
|
10
|
-
end
|
11
|
-
|
12
|
-
custom_models = Dir["#{File.dirname(__FILE__)}/../lib/authlogic_connect/oauth/tokens"]
|
13
|
-
custom_models +=Dir["#{File.dirname(__FILE__)}/../lib/authlogic_connect/openid/tokens"]
|
14
|
-
custom_models.each do |path|
|
15
|
-
$LOAD_PATH << path
|
16
|
-
ActiveSupport::Dependencies.load_paths << path
|
17
|
-
end
|
1
|
+
require "authlogic-connect"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lance Pollard
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-11 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,8 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- init.rb
|
108
108
|
- MIT-LICENSE
|
109
|
+
- lib/authlogic-connect.rb
|
110
|
+
- lib/authlogic_connect/callback_filter.rb
|
109
111
|
- lib/authlogic_connect/common/session.rb
|
110
112
|
- lib/authlogic_connect/common/user.rb
|
111
113
|
- lib/authlogic_connect/common/variables.rb
|
@@ -137,9 +139,7 @@ files:
|
|
137
139
|
- lib/authlogic_connect/openid/user.rb
|
138
140
|
- lib/authlogic_connect/openid/variables.rb
|
139
141
|
- lib/authlogic_connect/openid.rb
|
140
|
-
- lib/authlogic_connect.rb
|
141
|
-
- lib/oauth_callback_filter.rb
|
142
|
-
- lib/token.rb
|
142
|
+
- lib/authlogic_connect/token.rb
|
143
143
|
- rails/init.rb
|
144
144
|
has_rdoc: true
|
145
145
|
homepage: http://github.com/viatropos/authlogic-connect
|