authlogic-connect 0.0.3.8 → 0.0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,18 +1,40 @@
1
- # Authlogic Connect
1
+ # AuthlogicConnect
2
2
 
3
- Authlogic Connect is an extension of the Authlogic library to add extensive Oauth and OpenID support. With Authlogic Connect, it's very easy to allow users to login through any of the 30+ authentication providers out there. You shouldn't be reinventing the wheel anyways.
3
+ AuthlogicConnect is an extension of the Authlogic library to add extensive Oauth and OpenID support.
4
4
 
5
- There are 3 ways you can allow your users to login with Authlogic Connect:
5
+ It allows you to login through any of the 30+ Oauth and OpenID providers on the Internet.
6
6
 
7
- 1. Clicking an Oauth Provider
8
- 2. Clicking an OpenID Provider and entering in their username
9
- 3. Manually typing in a full OpenID address
7
+ That makes life easy and gives you a lot of power.
8
+
9
+ Here's a **[live example](http://authlogic-connect.heroku.com)** on Heroku ([with source](http://github.com/viatropos/authlogic-connect-example)).
10
+
11
+ ## Supported Providers
12
+
13
+ AuthlogicConnect currently allows you to login with 7 Oauth providers and all the OpenID providers. Feel free to add support for more as you need them.
14
+
15
+ ### Oauth
16
+
17
+ - Twitter
18
+ - Facebook
19
+ - Google
20
+ - LinkedIn
21
+ - MySpace
22
+ - Vimeo
23
+ - Yahoo
24
+
25
+ ### OpenID
26
+
27
+ - MyOpenID
10
28
 
11
- All of that is easier than creating a new account and password.
29
+ ### Lists of all known providers here:
30
+
31
+ - [Oauth Providers](http://wiki.oauth.net/ServiceProviders)
32
+ - [OpenID Providers](http://en.wikipedia.org/wiki/List_of_OpenID_providers)
33
+ - [More OpenID](http://openid.net/get-an-openid/)
12
34
 
13
35
  ## Install and use
14
36
 
15
- ### 1. Install Authlogic Connect
37
+ ### 1. Install AuthlogicConnect
16
38
 
17
39
  sudo gem install authlogic-connect
18
40
 
@@ -35,11 +57,11 @@ Rails 3: `Gemfile`
35
57
  gem "oauth2"
36
58
  gem "authlogic-connect"
37
59
 
38
- ### 2b. Add the `OpenIdAuthentication.store`
60
+ ### 3. Add the `OpenIdAuthentication.store`
39
61
 
40
62
  Do to [some strange problem](http://github.com/openid/ruby-openid/issues#issue/1) I have yet to really understand, Rails 2.3.5 doesn't like when `OpenIdAuthentication.store` is null, which means it uses the "in memory" store and for some reason fails.
41
63
 
42
- So as a fix, add these at the end of your `config/environment.rb` files:
64
+ So as a fix, if you are using Rails < 3, add these at the end of your `config/environment.rb` files:
43
65
 
44
66
  In development mode:
45
67
 
@@ -49,7 +71,7 @@ In production (on Heroku primarily)
49
71
 
50
72
  OpenIdAuthentication.store = :memcache
51
73
 
52
- ### 3. Add the Migrations
74
+ ### 4. Add the Migrations
53
75
 
54
76
  See the [Rails 2 Example](http://github.com/viatropos/authlogic-connect-example-rails2) and [Rails 3 Example](http://github.com/viatropos/authlogic-connect-example) projects to see what you need. Will add a generator sometime.
55
77
 
@@ -61,40 +83,42 @@ Files needed are:
61
83
  - initializers: config/authlogic.example.yml, config/initializers/authlogic_connect_config.rb
62
84
  - routes
63
85
 
64
- ### 4. Configure your keys
65
-
66
- 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).
67
-
68
- AuthlogicConnect.config = {
69
- :default => "facebook",
70
- :connect => {
71
- :twitter => {
72
- :key => "my_key",
73
- :secret => "my_secret",
74
- :label => "Twitter"
75
- },
76
- :facebook => {
77
- :key => "my_key",
78
- :secret => "my_secret",
79
- :label => "Facebook"
80
- },
81
- :google => {
82
- :key => "my_key",
83
- :secret => "my_secret",
84
- :label => "Google"
85
- },
86
- :yahoo => {
87
- :key => "my_key",
88
- :secret => "my_secret",
89
- :label => "Yahoo"
90
- },
91
- :vimeo => {
92
-
93
- }
94
- }
95
- }
96
-
97
- ### 5. Make sure you save your objects properly
86
+ ### 5. Configure your keys
87
+
88
+ In `config/authlogic.yml`, 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).
89
+
90
+ connect:
91
+ twitter:
92
+ key: "my_key"
93
+ secret: "my_secret"
94
+ label: "Twitter"
95
+ facebook:
96
+ key: "my_key"
97
+ secret: "my_secret"
98
+ label: "Facebook"
99
+ google:
100
+ key: "my_key"
101
+ secret: "my_secret"
102
+ label: "Google"
103
+ yahoo:
104
+ key: "my_key"
105
+ secret: "my_secret"
106
+ label: "Yahoo"
107
+ myspace:
108
+ key: "my_key"
109
+ secret: "my_secret"
110
+ vimeo:
111
+ key: "my_key"
112
+ secret: "my_secret"
113
+ linked_in:
114
+ key: "my_key"
115
+ secret: "my_secret"
116
+
117
+ These are then loaded via the initializer script in `config/initializers/authlogic_connect_config.rb`:
118
+
119
+ AuthlogicConnect.config = YAML.load_file("config/authlogic.yml")
120
+
121
+ ### 6. Make sure you save your objects properly
98
122
 
99
123
  Because of the redirects involved in Oauth and OpenID, you MUST pass a block to the `save` method in your UsersController and UserSessionsController:
100
124
 
@@ -107,32 +131,35 @@ Because of the redirects involved in Oauth and OpenID, you MUST pass a block to
107
131
  end
108
132
  end
109
133
 
110
- You should save your `@user` objects this way as well, because you also want the user to authenticate with OAuth.
111
-
112
- 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.
134
+ If you don't use the block, we will get a DoubleRender error. We need the block to jump out of the rendering while redirecting.
113
135
 
114
- ### 6. Add Parameters to Forms in your Views
136
+ ### 7. Add Parameters to Forms in your Views
115
137
 
116
- <%# oauth_register_button :value => "Register with Twitter" %>
117
- <%# oauth_login_button :value => "Login with Twitter" %>
138
+ There are 3 things to include in your views.
118
139
 
119
- Check out the example projects to see exactly what's required. These aren't totally useful yet. Their job is to just send the right parameters to authlogic-connect.
140
+ First, you must specify whether this is for _registration_ or _login_. This is stored in the `authentication_type` key with a value of `user` for registration and `session` for login:
120
141
 
121
- ### 7. Create Custom Tokens (if they don't already exist)
142
+ %input{:type => :hidden, :name => :authentication_type, :value => :user}
143
+
144
+ Second, if you are using Oauth, you must include an input with name `oauth_provider` and value `twitter` or whatever other provider you might want (see example apps for dynamic example).
122
145
 
123
- Here's an example of the FacebookToken for Oauth
146
+ %input{:type => :radio, :id => :twitter_oauth_provider, :name => :oauth_provider, :value => :twitter}
147
+
148
+ Finally, if you are using OpenID, you must include an input with name `openid_identifier`, which is a text field with the value the user types in for their address:
124
149
 
125
- class FacebookToken < OauthToken
150
+ %input.nice{:type => :text, :name => :openid_identifier}
126
151
 
127
- version 2.0
152
+ Those are passed as parameters to Authlogic, and the complicated details are abstracted away.
128
153
 
129
- settings "https://graph.facebook.com",
130
- :authorize_url => "https://graph.facebook.com/oauth/authorize",
131
- :scope => "email, offline_access"
154
+ ## Overview of the User Experience
132
155
 
133
- end
134
-
135
- If there is an Oauth/OpenID service you need, let me know, or fork/add/push and I will integrate it into the project and add you to the list.
156
+ There are 3 ways you a user can login with AuthlogicConnect:
157
+
158
+ 1. Clicking an Oauth Provider
159
+ 2. Clicking an OpenID Provider and entering in their username
160
+ 3. Manually typing in a full OpenID address
161
+
162
+ Oauth is very different from OpenID, but this aims to make them work the same.
136
163
 
137
164
  ## Examples
138
165
 
@@ -196,152 +223,18 @@ If they've associated their Facebook account with your site, you can access Face
196
223
  @profile = @user.profile
197
224
  end
198
225
 
199
- ## Supported Providers
200
-
201
- ### Oauth
202
-
203
- - Twitter
204
- - Facebook
205
- - Google
206
- - LinkedIn
207
- - MySpace
208
- - Vimeo
209
- - Yahoo
210
-
211
- ### OpenID
212
-
213
- - MyOpenID
214
-
215
- Lists of all known providers here:
216
-
217
- - [Oauth Providers](http://wiki.oauth.net/ServiceProviders)
218
- - [OpenID Providers](http://en.wikipedia.org/wiki/List_of_OpenID_providers)
219
- - [More OpenID](http://openid.net/get-an-openid/)
220
-
221
- ## Oauth vs. OpenID
222
-
223
- There is a big but subtle difference between Oauth and OpenID: Oauth is NOT a login protocol. OpenID IS.
224
-
225
- You should use Oauth when you want to be able to access and/or manipulate data on behalf of the user. If all you want is authentication, OpenID is best. However, if you want to login through Twitter or Facebook, you _have_ to use Oauth (forget Facebook Connect, too complicated).
226
-
227
- An example would be using Google and Oauth. With Google and Oauth, the user can grant you rights to "access the gmail contacts" for example, and you can get a list of their contacts. That requires that your app is authorized, which requires they grant access via Oauth. This is kinda strange though, because why does a login app need to access your google contacts? It doesn't. That's why we should use OpenID in this case. But we can still use Oauth... continuing...
228
-
229
- The problem with the Google Contacts Oauth example is that when you get the Oauth Access Token, Google doesn't give you any data, so you can't say "the 'guy who just logged in's email is abc@gmail.com, save that to the database". That's where OpenID would shine.
230
-
231
- If you want to use Oauth for logging in, you must get back some unique key to identify the user by. The best options are something like email, username, or some unique id. This is accomplished in the `GoogleToken` oauth class by passing a block to the `key` class method:
232
-
233
- key do |access_token|
234
- body = JSON.parse(access_token.get("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=0").body)
235
- email = body["feed"]["author"].first["email"]["$t"] # $t is some weird google json thing
236
- end
237
-
238
- That hack lets us use Oauth to get the email address of the user, which we need if we want to somehow find the account for a user who has logged out
239
-
240
- The confusing thing is that Twitter allows you to login with Oauth, it's one of the few it seems. This is because Twitter sends back the `user_id` and `screen_name`, allowing you to pretend the user logged in. Google doesn't send that. Which means you have to make an _additional_ call to the service, if you're using Oauth. If you're using OpenID, that's specifically for login so you're going to get back email/name/etc.
241
-
242
226
  ## Helpful links
243
227
 
244
- * <b>Authlogic:</b> [http://github.com/binarylogic/authlogic](http://github.com/binarylogic/authlogic)
245
- * <b>Authlogic Connect Example Project:</b> [http://github.com/viatropos/authlogic-connect-example](http://github.com/viatropos/authlogic-connect-example)
246
- * <b>Live example with Twitter and Facebook using Rails 3:</b> [http://authlogic-connect.heroku.com](http://authlogic-connect.heroku.com)
247
- * <b>Rails 2.3.5 Example:</b> [http://github.com/viatropos/authlogic-connect-example-rails2](http://github.com/viatropos/authlogic-connect-example-rails2)
228
+ * **Authlogic:** [http://github.com/binarylogic/authlogic](http://github.com/binarylogic/authlogic)
229
+ * **AuthlogicConnect Example Project:** [http://github.com/viatropos/authlogic-connect-example](http://github.com/viatropos/authlogic-connect-example)
230
+ * **Live example with Twitter and Facebook using Rails 3:** [http://authlogic-connect.heroku.com](http://authlogic-connect.heroku.com)
231
+ * **Rails 2.3.5 Example:** [http://github.com/viatropos/authlogic-connect-example-rails2](http://github.com/viatropos/authlogic-connect-example-rails2)
248
232
  * **Rubygems Repository:** [http://rubygems.org/gems/authlogic-connect](http://rubygems.org/gems/authlogic-connect)
249
233
 
250
- ## The Flow
251
-
252
- - Controller calls `save`
253
- - Save checks to see what type of authentication we're going to use
254
- - methods called `authenticating_with_x?` sees if its service is in use
255
- - called twice, once before, and once after, redirect
256
- - it does this by checking if the session and parameters have certain variables defined.
257
- - Save calls `save_with_x`, which either:
258
- - performs the initial redirect, or
259
- - on response from the service, retrieves attributes and saves the user
260
- - If first round (hasn't yet redirected):
261
- - Saves important data into the session
262
- - Specifies callback url based on controller name and action
263
- - Redirects to remote service
264
- - User clicks "accept!"
265
- - Redirects back to callback url
266
- - If second round (redirect callback url):
267
- - Still processing service (`authenticating_with_oauth?` for example)
268
- - Instantiates new User, Session, or Token, or all 3 if they are brand new
269
- - Validates User and Session
270
- - You don't want to validate any password/email if you're using these services,
271
- so they are all skipped
272
- - Need to validate keys
273
- - Save user
274
- - Finish block, render page
275
-
276
- ### Note about the redirect process
277
-
278
- When you make a request to one of these services, it responds with a GET request. But assuming we have made the request through a `create` method (`UsersController#create` for `/register`, `UserSessionsController#create` for `/login`), we want that GET to be a POST.
279
-
280
- This is accomplished by adding a property called `auth_callback_method` to the session when the original request is made. It says "POST", or whatever the translation is from the controller method that was called.
281
-
282
- Then a Rack Middleware filter converts the GET return request from the authentication service into POST. This forces it to run back through the `create` method. Check out [`AuthlogicConnect::CallbackFilter`](http://github.com/viatropos/authlogic-connect/blob/master/lib/authlogic_connect/callback_filter.rb) for details. Or search "Rack Middleware".
283
-
284
- ## Project Goals
285
-
286
- 1. It should require the end user ONE CLICK to create an account with your site.
287
- 2. It should not depend on Javascript
288
- 3. It should be enhanced by Javascript
289
- 4. You should never have to touch the User/Session model/controller/migration if you are a just looking to get up and running quickly.
290
- 5. You should be able to plugin ruby libraries that wrap an api, such as TwitterAuth via `@user.twitter`, and LinkedIn via `@user.linked_in`. Just because it's that easy.
291
-
292
- ### Tests
293
-
294
- This only has a few unit tests. Enough to make sure the methods are returning what we are expecting.
295
-
296
- It should have Functional and Integration tests, using the Authlogic Connect example projects. If any of you guys know of an easy way to set that up, I'd love to know. Send me a github message :).
297
-
298
- Goal:
299
-
300
- - Test Framework: [Shoulda](http://github.com/thoughtbot/shoulda)
301
- - Autotest with Shoulda
302
- - Testing style like [Paperclip Tests](http://github.com/thoughtbot/paperclip/tree/master/test/)
303
- - Rails 2.3+ and Rails 3 Compatability
304
-
305
- ### TODO
306
-
307
- - If the user bails out in the middle of a login session, there needs to be a mechanism that knows how to reset their session.
308
- - If the openid is filled out, and then the user clicks Twitter oauth, it should know that it should log them in via twitter. This can only really be done by javascript. But what should take precedence? The thing that requires no typing: oauth. So oauth should be checked first on save.
309
- - Add rememberme functionality correctly. Right now I think it remembers you by default.
310
- - Login should work without having to access the remote service again.
311
- - If I create new user with Twitter or Google, then logout, I can login through twitter no problem. However, I cannot login through Google. This is because google returns new tokens, so I can't find it in the database. How do I find it? Also, if you go and revoke access to twitter (go to your twitter profile on twitter.com, click "settings", and revoke access to app) after you've created an account, and you try to login, same problem. This is because tokens are regenerated. NEED CONFIRMATION SCREEN
312
- - If the user has only created an account with say Twitter, then logs out, if they try to login with google, it should ask if they have a different account. How should this work?
313
-
314
- OAuth is for accessing remote information. It doesn't always give you data about the user. OpenID on the other hand gives you all the info you need for login.
315
-
316
- ## Helpful References for Rails 3
317
-
318
- - [Rails 3 Initialization Process](http://ryanbigg.com/guides/initialization.html)
319
- - [Rails 3 Plugins - Part 1, Big Picture](http://www.themodestrubyist.com/2010/03/01/rails-3-plugins---part-1---the-big-picture/)
320
- - [Rails 3 Plugins - Part 2, Writing an Engine](http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/)
321
- - [Rails 3 Plugins - Part 3, Initializers](http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/)
322
- - [Using Gemspecs as Intended](http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/)
323
-
324
- ## Parameters
325
-
326
- should look like this:
327
-
328
- Params from form:
329
-
330
- {"authentication_type"=>"user", "submit"=>"Register", "openid_identifier"=>"", "oauth_provider"=>"twitter"}
331
-
332
- Session just before redirect:
333
-
334
- {"authentication_type"=>"user", "oauth_request_token"=>"token_key", "session_id"=>"session_hash", "auth_callback_method"=>"POST", "auth_attributes"=>{"login_count"=>0}, "oauth_request_token_secret"=>"token_secret", "auth_request_class"=>"User", "auth_method"=>"oauth", "oauth_provider"=>"twitter"}
335
-
336
- ## Details
337
-
338
- The regular OAuth process is a four-step sequence:
234
+ ## Rest...
339
235
 
340
- 1. ask for a "request" token.
341
- 2. ask for the token to be authorized, which triggers user approval.
342
- 3. exchange the authorized request token for an "access" token.
343
- 4. use the access token to interact with the user's Google service data.
236
+ Thanks for the people that are already extending the project, all the input making things move much faster.
344
237
 
345
- ## OpenID Process
238
+ Feel free to add to the wiki if you figure things out or make new distinctions.
346
239
 
347
- If they logout and log back into OpenID, we can find their token solely from the data they pass in (`openid_identifier`). This is unlike Oauth, where we have to run through the whole process again because we don't know anything about them.
240
+ https://rpxnow.com/features
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.3.8"
9
+ s.version = "0.0.3.9"
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"
@@ -119,7 +119,8 @@ class OauthToken < Token
119
119
  # if you pass a hash as the second parameter to consumer.get_request_token,
120
120
  # ruby oauth will think this is a form and all sorts of bad things happen
121
121
  def get_request_token(callback_url)
122
- consumer.get_request_token(:oauth_callback => callback_url)
122
+ options = {:scope => config[:scope]} if config[:scope]
123
+ consumer.get_request_token({:oauth_callback => callback_url}, options)
123
124
  end
124
125
 
125
126
  def get_access_token(oauth_verifier)
@@ -48,7 +48,7 @@ module AuthlogicConnect::Oauth::User
48
48
  # it is called by the validation chain.
49
49
  def complete_oauth_transaction
50
50
  unless create_oauth_token
51
- self.errors.add(:tokens, "you have already created an account using your #{oauth_token.service_name} account, so it")
51
+ self.errors.add(:tokens, "you have already created an account using your #{token_class.service_name} account, so it")
52
52
  end
53
53
  end
54
54
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.0.3.8
9
+ - 9
10
+ version: 0.0.3.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lance Pollard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-27 00:00:00 -07:00
18
+ date: 2010-05-28 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency