Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

made it work with rails 2.3.5 and rails 3, cleaned up some of the cod…

…e so you include less in the application
  • Loading branch information...
commit cd57ce16c8ffb03e919f512a9335485a4326e1fb 1 parent 32a0c6c
@lancejpollard authored
Showing with 397 additions and 75 deletions.
  1. +3 −3 Gemfile
  2. 0  MIT-LICENSE
  3. +63 −26 README.markdown
  4. +6 −4 Rakefile
  5. 0  init.rb
  6. +12 −21 lib/authlogic-connect.rb
  7. +6 −2 lib/authlogic_connect/callback_filter.rb
  8. +1 −0  lib/authlogic_connect/common.rb
  9. +55 −0 lib/authlogic_connect/common/ext.rb
  10. 0  lib/authlogic_connect/common/session.rb
  11. 0  lib/authlogic_connect/common/user.rb
  12. 0  lib/authlogic_connect/common/variables.rb
  13. +15 −0 lib/authlogic_connect/engine.rb
  14. 0  lib/authlogic_connect/oauth.rb
  15. 0  lib/authlogic_connect/oauth/helper.rb
  16. +2 −1  lib/authlogic_connect/oauth/process.rb
  17. 0  lib/authlogic_connect/oauth/session.rb
  18. 0  lib/authlogic_connect/oauth/tokens/facebook_token.rb
  19. 0  lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb
  20. 0  lib/authlogic_connect/oauth/tokens/google_token.rb
  21. 0  lib/authlogic_connect/oauth/tokens/linked_in_token.rb
  22. 0  lib/authlogic_connect/oauth/tokens/myspace_token.rb
  23. 0  lib/authlogic_connect/oauth/tokens/oauth_token.rb
  24. 0  lib/authlogic_connect/oauth/tokens/opensocial_token.rb
  25. 0  lib/authlogic_connect/oauth/tokens/twitter_token.rb
  26. 0  lib/authlogic_connect/oauth/tokens/vimeo_token.rb
  27. 0  lib/authlogic_connect/oauth/tokens/yahoo_token.rb
  28. +7 −3 lib/authlogic_connect/oauth/user.rb
  29. 0  lib/authlogic_connect/oauth/variables.rb
  30. 0  lib/authlogic_connect/openid.rb
  31. 0  lib/authlogic_connect/openid/session.rb
  32. 0  lib/authlogic_connect/openid/tokens/aol_token.rb
  33. 0  lib/authlogic_connect/openid/tokens/blogger_token.rb
  34. 0  lib/authlogic_connect/openid/tokens/flickr_token.rb
  35. 0  lib/authlogic_connect/openid/tokens/my_openid_token.rb
  36. 0  lib/authlogic_connect/openid/tokens/openid_token.rb
  37. +10 −11 lib/authlogic_connect/openid/user.rb
  38. 0  lib/authlogic_connect/openid/variables.rb
  39. 0  lib/authlogic_connect/token.rb
  40. +129 −0 lib/open_id_authentication.rb
  41. +3 −3 pkg/authlogic-connect.gemspec
  42. +19 −1 rails/init.rb
  43. +13 −0 test/test_authlogic_connect.rb
  44. +53 −0 test/test_helper.rb
View
6 Gemfile
@@ -1,9 +1,9 @@
source 'http://rubygems.org'
gem 'rails', '3.0.0.beta3'
-gem "json"
+
gem "ruby-openid"
+gem 'rack-openid', '>=0.2.1', :require => 'rack/openid'
gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3"
gem "oauth"
-gem "oauth2" # facebook only
-gem "authlogic-connect"
+gem "oauth2"
View
0  MIT-LICENSE 100644 → 100755
File mode changed
View
89 README.markdown 100644 → 100755
@@ -15,6 +15,8 @@ All of that is easier than creating a new account and password.
* <b>Authlogic:</b> [http://github.com/binarylogic/authlogic](http://github.com/binarylogic/authlogic)
* <b>Authlogic Connect Example Project:</b> [http://github.com/viatropos/authlogic-connect-example](http://github.com/viatropos/authlogic-connect-example)
* <b>Live example with Twitter and Facebook using Rails 3:</b> [http://authlogic-connect.heroku.com](http://authlogic-connect.heroku.com)
+* <b>Rails 2.3.5 Example:</b> [http://github.com/viatropos/authlogic-connect-example-rails2](http://github.com/viatropos/authlogic-connect-example-rails2)]
+* **Rubygems Repository:** [http://rubygems.org/search?query=authlogic-connect](http://rubygems.org/search?query=authlogic-connect)
## Supported Providers
@@ -35,40 +37,40 @@ Lists of all known providers here:
## Install and use
-### 1. Install Authlogic and setup your application
+### 1. Install Authlogic Connect (it will install the dependencies)
- sudo gem install authlogic
-
-### 2. Install OAuth and Authlogic Connect
-
- sudo gem install oauth
sudo gem install authlogic-connect
Now add the gem dependencies in your config:
+Rails 2.3.x: `config/environment.rb`
+
config.gem "json"
config.gem "authlogic"
config.gem "oauth"
config.gem "oauth2"
- config.gem "authlogic-connect", :lib => "authlogic_connect"
+ config.gem "authlogic-connect"
-### 3. Add the Migrations
+Rails 3: `Gemfile`
-If you are starting from scratch (and you don't even have a User model yet), create the migrations using this command.
+ gem "ruby-openid"
+ gem "rack-openid", ">=0.2.1", :require => "rack/openid"
+ gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3"
+ gem "oauth"
+ gem "oauth2"
+ gem "authlogic-connect"
- script/generate authlogic_connect_migration
+### 3. Add the Migrations
-Otherwise, add this migration
+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.
- class AddAuthlogicConnectMigration < ActiveRecord::Migration
- def self.up
- # TODO
- end
+Files needed are:
- def self.down
- # TODO
- end
- end
+- models: User, UserSession
+- controllers: UsersController, UserSessionsController, ApplicationController
+- migrations: create\_users, create\_sessions, create\_tokens
+- initializers: config/authlogic.example.yml, config/initializers/authlogic_connect_config.rb
+- routes
### 4. Configure your keys
@@ -124,15 +126,23 @@ If we don't use the block, we will get a DoubleRender error. This lets us skip t
Here's an example of the FacebookToken for Oauth
class FacebookToken < OauthToken
-
+
+ version 2.0 # oauth 2.0
+
+ settings "https://graph.facebook.com",
+ :authorize_url => "https://graph.facebook.com/oauth/authorize",
+ :scope => "email, offline_access"
+
end
+
+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.
-### 6. Add login and register buttons to your views
+### 7. Add login and register buttons to your views
<%# oauth_register_button :value => "Register with Twitter" %>
<%# oauth_login_button :value => "Login with Twitter" %>
-That's it! The rest is taken care of for you.
+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.
## The Flow
@@ -160,11 +170,15 @@ That's it! The rest is taken care of for you.
- Save user
- Finish block, render page
-## Tests
+### Note about the redirect process
+
+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.
+
+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.
-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.
+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".
-## Goals
+## Project Goals
1. It should require the end user ONE CLICK to create an account with your site.
2. It should not depend on Javascript
@@ -172,7 +186,30 @@ This has no tests! I had to build this in a weekend and am not fluent with Shou
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.
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.
+### Tests
+
+This has no tests! I had to build this in a day and am not fluent with Shoulda, which I'd like to use. It should have lots of tests to make sure all permutations of login and account association work perfectly.
+
+Goal:
+
+- Test Framework: [Shoulda](http://github.com/thoughtbot/shoulda)
+- Autotest with Shoulda
+- Testing style like [Paperclip Tests](http://github.com/thoughtbot/paperclip/tree/master/test/)
+- Rails 2.3+ and Rails 3 Compatability
+
+I have no idea how to get up and running with Autotest and Shoulda right now. If you know, I'd love to get the answer on Stack Overflow:
+
+[http://stackoverflow.com/questions/2823224/what-test-environment-setup-do-committers-use-in-the-ruby-community](http://stackoverflow.com/questions/2823224/what-test-environment-setup-do-committers-use-in-the-ruby-community)
+
## TODO
- Change `register_with_oauth` and related to `register_method` and `login_method`: oauth, openid, traditional
-- Build view helpers
+- Build view helpers
+
+## Helpful References for Rails 3
+
+- [Rails 3 Initialization Process](http://ryanbigg.com/guides/initialization.html)
+- [Rails 3 Plugins - Part 1, Big Picture](http://www.themodestrubyist.com/2010/03/01/rails-3-plugins---part-1---the-big-picture/)
+- [Rails 3 Plugins - Part 2, Writing an Engine](http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/)
+- [Rails 3 Plugins - Part 3, Initializers](http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/)
+- [Using Gemspecs as Intended](http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/)
View
10 Rakefile 100644 → 100755
@@ -6,7 +6,7 @@ require 'rake/gempackagetask'
spec = Gem::Specification.new do |s|
s.name = "authlogic-connect"
s.author = "Lance Pollard"
- s.version = "0.0.3.2"
+ s.version = "0.0.3.4"
s.summary = "Authlogic Connect: Let your app use all of Oauth and OpenID"
s.homepage = "http://github.com/viatropos/authlogic-connect"
s.email = "lancejpollard@gmail.com"
@@ -18,10 +18,12 @@ spec = Gem::Specification.new do |s|
s.require_path = "lib"
s.add_dependency("activesupport", ">= 2.1.2")
s.add_dependency("activerecord", ">= 2.1.2")
- s.add_dependency("authlogic")
- s.add_dependency("oauth")
s.add_dependency("json")
- s.add_dependency("oauth2") # facebook only
+ s.add_dependency("ruby-openid")
+ s.add_dependency("rack-openid", ">=0.2.1")
+ s.add_dependency("oauth")
+ s.add_dependency("oauth2")
+ s.add_dependency("authlogic")
end
desc "Create .gemspec file (useful for github)"
View
0  init.rb 100644 → 100755
File mode changed
View
33 lib/authlogic-connect.rb 100644 → 100755
@@ -1,20 +1,9 @@
require 'active_record'
+require "rubygems"
require 'authlogic'
require 'oauth'
require 'oauth2'
-
-# Throw callback rack app into the middleware stack
-# TODO: Somehow do this for Rails 3?
-# For now it is in the sample Rails 3 app
-=begin
-ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
- ActionController::Dispatcher.middleware.each do |klass|
- m.use klass
- end
- m.use AuthlogicConnect::CallbackFilter
-end
-=end
this = File.dirname(__FILE__)
library = "#{this}/authlogic_connect"
@@ -45,17 +34,17 @@ def recursively_symbolize_keys!
end
module AuthlogicConnect
- VERSION = "0.0.1"
+ KEY = "connect"
class << self
attr_accessor :config
-
+
def config=(value)
value.recursively_symbolize_keys!
@config = value
end
-
+
def key(path)
result = self.config
path.to_s.split(".").each { |node| result = result[node.to_sym] if result }
@@ -63,15 +52,15 @@ def key(path)
end
def credentials(service)
- key("services.#{service.to_s}")
+ key("#{KEY}.#{service.to_s}")
end
def services
- key("services")
+ key(KEY)
end
def service_names
- key("services").keys.collect(&:to_s)
+ services.keys.collect(&:to_s)
end
def include?(service)
@@ -89,15 +78,17 @@ def consumer(key)
end
end
+require "#{this}/open_id_authentication"
require "#{library}/callback_filter"
require "#{library}/token"
require "#{library}/openid"
require "#{library}/oauth"
require "#{library}/common"
+require "#{library}/engine" if defined?(Rails) && Rails::VERSION::MAJOR == 3
-custom_models = ["#{library}/token"]
-custom_models += Dir["#{library}/oauth/tokens"]
-custom_models +=Dir["#{library}/openid/tokens"]
+custom_models = ["#{library}/token"]
+custom_models += Dir["#{library}/oauth/tokens"]
+custom_models += Dir["#{library}/openid/tokens"]
custom_models.each do |path|
$LOAD_PATH << path
View
8 lib/authlogic_connect/callback_filter.rb 100644 → 100755
@@ -3,12 +3,16 @@ def initialize(app)
@app = app
end
+ # this intercepts how the browser interprets the url.
+ # so we override it and say,
+ # "if we've stored a variable in the session called :auth_callback_method,
+ # then convert that into a POST call so we re-call the original method"
def call(env)
if env["rack.session"].nil?
raise "Make sure you are setting the session in Rack too! Place this in config/application.rb"
end
- unless env["rack.session"][:oauth_callback_method].blank?
- env["REQUEST_METHOD"] = env["rack.session"].delete(:oauth_callback_method).to_s.upcase
+ unless env["rack.session"][:auth_callback_method].blank?
+ env["REQUEST_METHOD"] = env["rack.session"].delete(:auth_callback_method).to_s.upcase
end
@app.call(env)
end
View
1  lib/authlogic_connect/common.rb 100644 → 100755
@@ -1,6 +1,7 @@
module AuthlogicConnect::Common
end
+require File.dirname(__FILE__) + "/common/ext"
require File.dirname(__FILE__) + "/common/variables"
require File.dirname(__FILE__) + "/common/user"
require File.dirname(__FILE__) + "/common/session"
View
55 lib/authlogic_connect/common/ext.rb
@@ -0,0 +1,55 @@
+class String
+ # normalizes an OpenID according to http://openid.net/specs/openid-authentication-2_0.html#normalization
+ def normalize_identifier
+ # clean up whitespace
+ identifier = self.dup.strip
+
+ # if an XRI has a prefix, strip it.
+ identifier.gsub!(/xri:\/\//i, '')
+
+ # dodge XRIs -- TODO: validate, don't just skip.
+ unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
+ # does it begin with http? if not, add it.
+ identifier = "http://#{identifier}" unless identifier =~ /^http/i
+
+ # strip any fragments
+ identifier.gsub!(/\#(.*)$/, '')
+
+ begin
+ uri = URI.parse(identifier)
+ uri.scheme = uri.scheme.downcase # URI should do this
+ identifier = uri.normalize.to_s
+ rescue URI::InvalidURIError
+ raise InvalidOpenId.new("#{identifier} is not an OpenID identifier")
+ end
+ end
+
+ return identifier
+ end
+end
+
+class Hash
+ def recursively_symbolize_keys!
+ self.symbolize_keys!
+ self.values.each do |v|
+ if v.is_a? Hash
+ v.recursively_symbolize_keys!
+ elsif v.is_a? Array
+ v.recursively_symbolize_keys!
+ end
+ end
+ self
+ end
+end
+
+class Array
+ def recursively_symbolize_keys!
+ self.each do |item|
+ if item.is_a? Hash
+ item.recursively_symbolize_keys!
+ elsif item.is_a? Array
+ item.recursively_symbolize_keys!
+ end
+ end
+ end
+end
View
0  lib/authlogic_connect/common/session.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/common/user.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/common/variables.rb 100644 → 100755
File mode changed
View
15 lib/authlogic_connect/engine.rb
@@ -0,0 +1,15 @@
+module AuthlogicConnect
+ class Engine < Rails::Engine
+ engine_name :authlogic_connect
+
+ initializer "authlogic_connect.authentication_hook" do |app|
+ app.middleware.use AuthlogicConnect::CallbackFilter
+ app.middleware.use OpenIdAuthentication
+ end
+
+ initializer "authlogic_connect.finalize", :after => "authlogic_connect.authentication_hook" do |app|
+ OpenID::Util.logger = Rails.logger
+ ActionController::Base.send :include, OpenIdAuthentication
+ end
+ end
+end
View
0  lib/authlogic_connect/oauth.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/helper.rb 100644 → 100755
File mode changed
View
3  lib/authlogic_connect/oauth/process.rb 100644 → 100755
@@ -34,13 +34,14 @@ def redirect_to_oauth
end
def save_oauth_callback
+ puts "save_oauth_callback"
# Store the class which is redirecting, so we can ensure other classes
# don't get confused and attempt to use the response
auth_session[:oauth_request_class] = self.class.name
auth_session[:oauth_provider] = auth_params[:oauth_provider]
# Tell our rack callback filter what method the current request is using
- auth_session[:oauth_callback_method] = auth_controller.request.method
+ auth_session[:auth_callback_method] = auth_controller.request.method
end
def save_auth_session(request)
View
0  lib/authlogic_connect/oauth/session.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/facebook_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/google_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/linked_in_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/myspace_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/oauth_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/opensocial_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/twitter_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/vimeo_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/oauth/tokens/yahoo_token.rb 100644 → 100755
File mode changed
View
10 lib/authlogic_connect/oauth/user.rb 100644 → 100755
@@ -59,16 +59,20 @@ def validate_password_with_oauth?
def authenticating_with_oauth?
return false unless oauth_provider
# Initial request when user presses one of the button helpers
- (auth_params && !auth_params[:register_with_oauth].blank?) ||
+ initial_request = (auth_params && !auth_params[:register_with_oauth].blank?)
# When the oauth provider responds and we made the initial request
- (oauth_response && auth_session && auth_session[:oauth_request_class] == self.class.name)
+ initial_response = (oauth_response && auth_session && auth_session[:oauth_request_class] == self.class.name)
+
+ return initial_request || initial_response
end
def authenticate_with_oauth
# Restore any attributes which were saved before redirecting to the oauth server
self.attributes = auth_session.delete(:authlogic_oauth_attributes)
token = AuthlogicConnect.token(oauth_provider).new(oauth_key_and_secret)
- if Token.find_by_key(token.key)
+ puts "NEW TOKEN: #{token.inspect}"
+ if old_token = Token.find_by_key(token.key)
+ puts "OLD TOKEN? #{old_token.inspect}"
self.errors.add("you have already created an account using your #{oauth_token.service_name} account, so it")
else
self.tokens << token
View
0  lib/authlogic_connect/oauth/variables.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid/session.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid/tokens/aol_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid/tokens/blogger_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid/tokens/flickr_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid/tokens/my_openid_token.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/openid/tokens/openid_token.rb 100644 → 100755
File mode changed
View
21 lib/authlogic_connect/openid/user.rb 100644 → 100755
@@ -23,15 +23,14 @@ def self.included(base)
end
def openid_identifier=(value)
- write_attribute(:openid_identifier, value.blank? ? nil : OpenIdAuthentication.normalize_identifier(value))
+ write_attribute(:openid_identifier, value.blank? ? nil : value.to_s.normalize_identifier)
reset_persistence_token if openid_identifier_changed?
- rescue OpenIdAuthentication::InvalidOpenId => e
+ rescue Exception => e
@openid_error = e.message
end
def save_with_openid(perform_validation = true, &block)
return false if perform_validation && block_given? && authenticating_with_openid? && !authenticating_with_openid
- return false if new_record? && !openid_complete?
return true
end
@@ -42,15 +41,15 @@ def validate_openid
end
def using_openid?
- respond_to?(:openid_identifier) && !openid_identifier.blank?
+ respond_to?(:openid_identifier) && !auth_params[:openid_identifier].blank?
end
def openid_complete?
- auth_params[:open_id_complete] && auth_params[:for_model]
+ auth_session[:openid_attributes]
end
def authenticating_with_openid?
- session_class.activated? && ((using_openid? && openid_identifier_changed?) || openid_complete?)
+ session_class.activated? && ((using_openid?) || openid_complete?)
end
def validate_password_with_openid?
@@ -60,15 +59,15 @@ def validate_password_with_openid?
def authenticating_with_openid
@openid_error = nil
if !openid_complete?
- auth_session[:openid_attributes] = attributes_to_save
+ # Tell our rack callback filter what method the current request is using
+ auth_session[:auth_callback_method] = auth_controller.request.method
+ auth_session[:openid_attributes] = attributes_to_save
else
- self.attributes = auth_session[:openid_attributes]
- auth_session[:openid_attributes] = nil
+ self.attributes = auth_session.delete(:openid_attributes)
end
options = {}
- options[:return_to] = auth_controller.url_for(:for_model => "1",:controller => "users", :action => "create")
-
+ options[:return_to] = auth_controller.url_for(:for_model => "1", :controller => "users", :action => "create")
auth_controller.send(:authenticate_with_open_id, openid_identifier, options) do |result, openid_identifier, registration|
if result.unsuccessful?
@openid_error = result.message
View
0  lib/authlogic_connect/openid/variables.rb 100644 → 100755
File mode changed
View
0  lib/authlogic_connect/token.rb 100644 → 100755
File mode changed
View
129 lib/open_id_authentication.rb
@@ -0,0 +1,129 @@
+# copied from open_id_authentication plugin on github
+require 'uri'
+require 'openid'
+require 'rack/openid'
+
+module OpenIdAuthentication
+ def self.new(app)
+ store = OpenIdAuthentication.store
+ if store.nil?
+ Rails.logger.warn "OpenIdAuthentication.store is nil. Using in-memory store."
+ end
+
+ ::Rack::OpenID.new(app, OpenIdAuthentication.store)
+ end
+
+ def self.store
+ @@store
+ end
+
+ def self.store=(*store_option)
+ store, *parameters = *([ store_option ].flatten)
+
+ @@store = case store
+ when :memory
+ require 'openid/store/memory'
+ OpenID::Store::Memory.new
+ when :file
+ require 'openid/store/filesystem'
+ OpenID::Store::Filesystem.new(Rails.root.join('tmp/openids'))
+ when :memcache
+ require 'memcache'
+ require 'openid/store/memcache'
+ OpenID::Store::Memcache.new(MemCache.new(parameters))
+ else
+ store
+ end
+ end
+
+ self.store = nil
+
+ class Result
+ ERROR_MESSAGES = {
+ :missing => "Sorry, the OpenID server couldn't be found",
+ :invalid => "Sorry, but this does not appear to be a valid OpenID",
+ :canceled => "OpenID verification was canceled",
+ :failed => "OpenID verification failed",
+ :setup_needed => "OpenID verification needs setup"
+ }
+
+ def self.[](code)
+ new(code)
+ end
+
+ def initialize(code)
+ @code = code
+ end
+
+ def status
+ @code
+ end
+
+ ERROR_MESSAGES.keys.each { |state| define_method("#{state}?") { @code == state } }
+
+ def successful?
+ @code == :successful
+ end
+
+ def unsuccessful?
+ ERROR_MESSAGES.keys.include?(@code)
+ end
+
+ def message
+ ERROR_MESSAGES[@code]
+ end
+ end
+
+ protected
+ # The parameter name of "openid_identifier" is used rather than
+ # the Rails convention "open_id_identifier" because that's what
+ # the specification dictates in order to get browser auto-complete
+ # working across sites
+ def using_open_id?(identifier = nil) #:doc:
+ identifier ||= open_id_identifier
+ !identifier.blank? || request.env[Rack::OpenID::RESPONSE]
+ end
+
+ def authenticate_with_open_id(identifier = nil, options = {}, &block) #:doc:
+ identifier ||= open_id_identifier
+
+ if request.env[Rack::OpenID::RESPONSE]
+ complete_open_id_authentication(&block)
+ else
+ begin_open_id_authentication(identifier, options, &block)
+ end
+ end
+
+ private
+ def open_id_identifier
+ params[:openid_identifier] || params[:openid_url]
+ end
+
+ def begin_open_id_authentication(identifier, options = {})
+ options[:identifier] = identifier
+ value = Rack::OpenID.build_header(options)
+ response.headers[Rack::OpenID::AUTHENTICATE_HEADER] = value
+ head :unauthorized
+ end
+
+ def complete_open_id_authentication
+ response = request.env[Rack::OpenID::RESPONSE]
+ identifier = response.display_identifier
+
+ case response.status
+ when OpenID::Consumer::SUCCESS
+ yield Result[:successful], identifier,
+ OpenID::SReg::Response.from_success_response(response)
+ when :missing
+ yield Result[:missing], identifier, nil
+ when :invalid
+ yield Result[:invalid], identifier, nil
+ when OpenID::Consumer::CANCEL
+ yield Result[:canceled], identifier, nil
+ when OpenID::Consumer::FAILURE
+ yield Result[:failed], identifier, nil
+ when OpenID::Consumer::SETUP_NEEDED
+ yield Result[:setup_needed], response.setup_url, nil
+ end
+ end
+end
View
6 pkg/authlogic-connect.gemspec
@@ -2,14 +2,14 @@
Gem::Specification.new do |s|
s.name = %q{authlogic-connect}
- s.version = "0.0.3.2"
+ s.version = "0.0.3.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Lance Pollard"]
- s.date = %q{2010-05-11}
+ s.date = %q{2010-05-18}
s.description = %q{Let your app use all of Oauth and OpenID}
s.email = %q{lancejpollard@gmail.com}
- s.files = ["README.markdown", "Rakefile", "init.rb", "MIT-LICENSE", "lib/authlogic-connect.rb", "lib/authlogic_connect", "lib/authlogic_connect/callback_filter.rb", "lib/authlogic_connect/common", "lib/authlogic_connect/common/session.rb", "lib/authlogic_connect/common/user.rb", "lib/authlogic_connect/common/variables.rb", "lib/authlogic_connect/common.rb", "lib/authlogic_connect/oauth", "lib/authlogic_connect/oauth/helper.rb", "lib/authlogic_connect/oauth/process.rb", "lib/authlogic_connect/oauth/session.rb", "lib/authlogic_connect/oauth/tokens", "lib/authlogic_connect/oauth/tokens/facebook_token.rb", "lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb", "lib/authlogic_connect/oauth/tokens/google_token.rb", "lib/authlogic_connect/oauth/tokens/linked_in_token.rb", "lib/authlogic_connect/oauth/tokens/myspace_token.rb", "lib/authlogic_connect/oauth/tokens/oauth_token.rb", "lib/authlogic_connect/oauth/tokens/opensocial_token.rb", "lib/authlogic_connect/oauth/tokens/twitter_token.rb", "lib/authlogic_connect/oauth/tokens/vimeo_token.rb", "lib/authlogic_connect/oauth/tokens/yahoo_token.rb", "lib/authlogic_connect/oauth/user.rb", "lib/authlogic_connect/oauth/variables.rb", "lib/authlogic_connect/oauth.rb", "lib/authlogic_connect/openid", "lib/authlogic_connect/openid/session.rb", "lib/authlogic_connect/openid/tokens", "lib/authlogic_connect/openid/tokens/aol_token.rb", "lib/authlogic_connect/openid/tokens/blogger_token.rb", "lib/authlogic_connect/openid/tokens/flickr_token.rb", "lib/authlogic_connect/openid/tokens/my_openid_token.rb", "lib/authlogic_connect/openid/tokens/openid_token.rb", "lib/authlogic_connect/openid/user.rb", "lib/authlogic_connect/openid/variables.rb", "lib/authlogic_connect/openid.rb", "lib/authlogic_connect/token.rb", "rails/init.rb"]
+ s.files = ["README.markdown", "Rakefile", "init.rb", "MIT-LICENSE", "lib/authlogic-connect.rb", "lib/authlogic_connect", "lib/authlogic_connect/callback_filter.rb", "lib/authlogic_connect/common", "lib/authlogic_connect/common/ext.rb", "lib/authlogic_connect/common/session.rb", "lib/authlogic_connect/common/user.rb", "lib/authlogic_connect/common/variables.rb", "lib/authlogic_connect/common.rb", "lib/authlogic_connect/engine.rb", "lib/authlogic_connect/oauth", "lib/authlogic_connect/oauth/helper.rb", "lib/authlogic_connect/oauth/process.rb", "lib/authlogic_connect/oauth/session.rb", "lib/authlogic_connect/oauth/tokens", "lib/authlogic_connect/oauth/tokens/facebook_token.rb", "lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb", "lib/authlogic_connect/oauth/tokens/google_token.rb", "lib/authlogic_connect/oauth/tokens/linked_in_token.rb", "lib/authlogic_connect/oauth/tokens/myspace_token.rb", "lib/authlogic_connect/oauth/tokens/oauth_token.rb", "lib/authlogic_connect/oauth/tokens/opensocial_token.rb", "lib/authlogic_connect/oauth/tokens/twitter_token.rb", "lib/authlogic_connect/oauth/tokens/vimeo_token.rb", "lib/authlogic_connect/oauth/tokens/yahoo_token.rb", "lib/authlogic_connect/oauth/user.rb", "lib/authlogic_connect/oauth/variables.rb", "lib/authlogic_connect/oauth.rb", "lib/authlogic_connect/openid", "lib/authlogic_connect/openid/session.rb", "lib/authlogic_connect/openid/tokens", "lib/authlogic_connect/openid/tokens/aol_token.rb", "lib/authlogic_connect/openid/tokens/blogger_token.rb", "lib/authlogic_connect/openid/tokens/flickr_token.rb", "lib/authlogic_connect/openid/tokens/my_openid_token.rb", "lib/authlogic_connect/openid/tokens/openid_token.rb", "lib/authlogic_connect/openid/user.rb", "lib/authlogic_connect/openid/variables.rb", "lib/authlogic_connect/openid.rb", "lib/authlogic_connect/token.rb", "lib/open_id_authentication.rb", "rails/init.rb", "test/database.yml", "test/test_authlogic_connect.rb", "test/test_helper.rb"]
s.homepage = %q{http://github.com/viatropos/authlogic-connect}
s.require_paths = ["lib"]
s.rubyforge_project = %q{authlogic-connect}
View
20 rails/init.rb 100644 → 100755
@@ -1 +1,19 @@
-require "authlogic-connect"
+require "authlogic-connect"
+
+# copied from open_id_authentication plugin on github
+
+# this is the Rails 2.x equivalent.
+# Rails 3 equivalent is in authlogic_connect/engine.rb
+if Rails.version < '3'
+ config.gem 'rack-openid', :lib => 'rack/openid', :version => '>=0.2.1'
+end
+
+require 'open_id_authentication'
+
+config.middleware.use AuthlogicConnect::CallbackFilter
+config.middleware.use OpenIdAuthentication
+
+config.after_initialize do
+ OpenID::Util.logger = Rails.logger
+ ActionController::Base.send :include, OpenIdAuthentication
+end
View
13 test/test_authlogic_connect.rb
@@ -0,0 +1,13 @@
+require 'test/helper'
+
+class AuthlogicConnectTest < Test::Unit::TestCase
+ context "AuthlogicConnect.config" do
+ setup do
+ AuthlogicConnect.config = {}
+ end
+
+ should "have an empty configuration hash" do
+ assert_equal true, AuthlogicConnect.config.empty?
+ end
+ end
+end
View
53 test/test_helper.rb
@@ -0,0 +1,53 @@
+require 'rubygems'
+require 'tempfile'
+require 'test/unit'
+
+require 'shoulda'
+gem 'activerecord', '~>3.0.0'
+gem 'activesupport', '~>3.0.0'
+gem 'actionpack', '~>3.0.0'
+require 'active_record'
+require 'active_record/version'
+require 'active_support'
+require 'action_pack'
+gem "ruby-openid"
+gem 'rack-openid', '>=0.2.1'
+gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3"
+require 'authlogic'
+gem "oauth"
+gem "oauth2"
+
+puts "Testing against version #{ActiveRecord::VERSION::STRING}"
+
+begin
+ require 'ruby-debug'
+rescue LoadError => e
+ puts "debugger disabled"
+end
+
+ROOT = File.join(File.dirname(__FILE__), '..')
+
+def silence_warnings
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ yield
+ensure
+ $VERBOSE = old_verbose
+end
+
+class Test::Unit::TestCase
+ def setup
+ silence_warnings do
+ Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
+ end
+ end
+end
+
+$LOAD_PATH << File.join(ROOT, 'lib')
+$LOAD_PATH << File.join(ROOT, 'lib', 'authlogic-connect')
+
+require File.join(ROOT, 'lib', 'authlogic-connect.rb')
+
+FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
+config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
+ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
+ActiveRecord::Base.establish_connection(config['test'])
Please sign in to comment.
Something went wrong with that request. Please try again.